6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 5:03 am

All times are UTC




Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Thu Nov 01, 2018 3:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Glad you could check out a psion or two!


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 01, 2018 3:54 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
I just checked with a short C program on a PowerPC, which has native single- and double-precision IEEE arithmetic, and that gets zeroes for all four cases in both precisions. This is perfectly consistent with the results for half-precision that I worked out mostly by hand.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 01, 2018 4:03 pm 
Offline
User avatar

Joined: Thu May 14, 2015 9:20 pm
Posts: 155
Location: UK
It is interesting how different the results actually are, where some produce a result of zero for some results, but not for others, while a different device does the opposite.

Oh, and one thing that many forget, is that any number system is an approximation of the real world where everything has an infinite resolution. Only humans like nice ‘round’ numbers...!

So, when using a 4¾ digit digital multimeter, how often does anyone take any notice of the two least significant digits? Same for the last digit on a 3½ digit multimeter...

When the utility company wants an electricity meter reading or a gas meter reading, they are not the least bit interested in the digits after the decimal point.

And no one says we will have a meeting at 10:35.45...

But when it comes to computers and calculators, because the device shows the displayed result, people will argue that it “must be right” because machines don’t suffer from human error. Oh much fun :lol:

Mark


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 01, 2018 4:06 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Chromatix wrote:
I just checked with a short C program ...


With a real CPU and with half-precision floats, you could probably run through an exhaustive
x/y*y-x
test in reasonable time, and count up how many times you get each number of ULP of error. Anything more than 1 ULP would be interesting, but it would also be interesting to know how often you get 0 ULPs of error and how often 1.

With BBC Basic, with my very non-exhaustive testing, I think I was getting at most 2 ULPs of error.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 01, 2018 5:13 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Quote:
It is interesting how different the results actually are, where some produce a result of zero for some results, but not for others, while a different device does the opposite.

Yes, because there are not only two different radixes in common use (decimal versus binary), but different rounding rules. Sometimes there are no guard digits or bits at all, sometimes just one digit, sometimes two, and for IEEE arithmetic only, the sticky bit. Sometimes ties are rounded away from zero, sometimes to even as IEEE does; some very basic implementations just truncate instead of rounding.

You can see the effect of the sticky bit in the 7/3 and 10/3 rounding in half-precision. The IEEE rules mean that those are rounded up; with only one or two guard bits the rounding would be a tie, and the round-to-even rule would round them both down.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 08, 2018 8:35 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
GARTHWILSON wrote:
I have not studied the innards of HP's handhelds, but I think many of the models used three more digits in intermediate results than they did in memory storage and display.

I've been reading some of WIlliam Kahan's writings: he worked on the 8087 FPU, on the IEEE standard (at the same time, but aiming to be scrupulous about conflict of interest) and on several of HP's calculators. He mentions and to some extent explains these three extra digits in this 49 page PDF:


Also good, an interview with him (a 15 min read):

And, still on HP, when they improved their algorithms as used in the HP-35 they wrote some articles:

Within Kahan's various writings are some example simple calculations which can show up anomalies in arithmetic. For example:
    pi * e - e * pi
    729^33.5 / 3^201 -1

Over on the hpmuseum forum, some other suggested calculations.

I tried this one: Nine ones squared, or 111.111111 ^ 2 - 12345
Code:
hp15c 0.67899
hp30b 0.67898770 best result
hp35s 0.67898770 best result same
casio 0.6789876  bad rounding
sharp 0.6789876  bad rounding same
psion 0.678987699999 stepwise, or 0.678987654319 as a formula


I had a go multiplying some square roots (even my two most basic calculators do square root)
sqrt 2 * sqrt 3, squared, minus 6
Code:
hp15c        1E-9
hp35s      -2E-11
hp30b      -2E-11
EL-556D  -1.2E-10
fx-115s  -1.2E-10
SL-300      -7E-7
Zebra 4     -7E-7

Psion 3 is a bit wysiwyg - displayed numbers can be re-used as is but internally there's more going on. It's clearly binary rather than decimal.
    I get just over -2E-11 if I re-enter each number as printed - just under 36 bits.
    If I put everything in a single line I get 8.88E-16 which is 2^-50, about 15 digits

edit: fix typo


Last edited by BigEd on Thu Nov 08, 2018 8:50 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 08, 2018 8:44 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Quote:
pi * e - e * pi

Just with that one, it's easy to see something revealing about HiPER Calc Pro. If I enter it as a single formula, I get zero, which is correct. If I press = before -, I get a 45-digit answer with exponent 10^-45.

The explanation is that HiPER Calc Pro is doing its internal clculations to twice the precision of display - but pressing equals rounds the value in processing to display precision.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 08, 2018 9:12 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
That's interesting, and quite remarkable: it's working at twice the precision it displays? That's much much more work than the extra 16 bits in the 8087's 80 bit format, or the 3 extra digits in a 12-digit HP calculator.

Just a couple more points...

We're told, I think, that the original 6502 BBC Basic used approaches found in Cody and Waite. But I see in Kahan's Sand article linked above that the 8087 did better:
Quote:
Like Hewlett-Packard’s elementary transcendental functions in its recent calculators, Intel’s are accurate to within an ulp or two, but that ulp is in the 64th sig. bit, beyond 18 sig. dec. Both the calculators and the i8087 achieve their accuracies via digit-by-digit methods [26] that generate ln(1+x), exp(x)-1, tan(x) and arctan(x) quickly and correct to 64 sig. bits in the i8087, 13 sig. dec. in h-p calculators. Then simple but unobvious programs produce the other elementary functions accurately from those four. Intel’s programs were written by Steve Baumel with my help, and appear in the CEL (Common Elementary function Library) in RMX-86 on the 86/330A. Their accuracies surpass crafty programs by Cody and Waite [27] run on less refined arithmetics.


(Indeed, I note that Kahan says that in binary, taking a square root and then squaring should always be lossless, but 6502 BBC Basic isn't, at least for 15 and 17.)

One of Kahan's notes is a lament that IEEE's three different rounding modes are not more readily accessible: running the same calculation in all three modes can give a hint as to whether a calculation is sound or not.

A couple of nice pull-quotes from the Sand piece:
Quote:
A computer is deemed Reliable when its users are never surprised by something its designers must later apologize for. How can designers and users who never meet learn what to expect from each other? Through education. That is the key to reliable computation.

Quote:
Design arithmetic functions in such a way that almost no user need know more about them than the designer is proud to explain in the Owner’s Handbook.


Finally, maybe, Kahan has more of a slide-deck presentation here, from 2005, which also links back into some specific other writings of his:

Pointers within include:

How Futile are Mindless Assessments of Roundoff in Floating-Point Computation? pp56, 2006
    "Some parentheses in Microsoft's Excel 2000 spreadsheet possess uncanny powers" which is about binary arithmetic masquerading as decimal.
and
Marketing versus Mathematics and other Ruminations on the Design of Floating-Point Arithmetic pp48, 2000


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 08, 2018 9:42 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Well, HiPER Calc Pro gets to take advantage of the modern gigahertz-class RISC CPU in my smartphone. It can *afford* to do more work than the sub-megahertz logic in many pocket calculators.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 08, 2018 9:58 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
A fair point!

I found it satisfying to find some sums which the more modern Sharp and Casio calculators did worse at than the older HPs, given the different tactics: it looks like HP tries to round but doesn't have extra digits, whereas the Sharp and Casio just have a couple of extra digits but truncate into them.


Top
 Profile  
Reply with quote  
PostPosted: Tue Dec 04, 2018 10:10 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Seen on the HP Museum forums:

where we find a link to an article on all-digits-correctness:

which includes this snippet[1] describing an old version of Android's calculator app:
Quote:
The actual evaluation is performed using double precision machine floating point. The calculator rounded the result to a smaller number of decimal digits than the 16 provided by the underlying arithmetic. This reduced the probability that a number with a finite decimal expansion like 12.34, but an infinite binary expansion, would be displayed as 12.399999999. But there was an unavoidable tension between not dropping enough digits and generating unpleasant representations, and dropping too many.

and goes on to describe a later version which uses 'constructive real arithmetic' which gives the possibility of scrolling a calculated result to see as many digits as desired. There is then a bit of a difficulty in that a rounded result isn't consistent with scrolling (a simple example being 2/3), so
Quote:
We decided this would be excessively confusing, and thus try to truncate toward zero rather than rounding. It is still possible for previously displayed digits to change as we are scrolling. But we always compute a number of digits more than we actually need, so this is exceedingly unlikely.


The forum thread goes on to mention the superior calculator, 'spigot' by the inestimable Simon Tatham, which always returns correct digits, and as many as you want. It is, however, a command line calculator, or indeed an expression evaluator. It comes with this amusing note:
Quote:
tan(x) returns the tangent of x, interpreted in radians. In theory, it would be an error to use this function with x being an odd integer multiple of π/2; in practice, spigot will never actually notice.


[1] Another interesting note in the article on the Android app involves the possibility of a calculation timing out, if the result is undecidable.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: