Post Reply 
[VA] "Introducing APRIL !" microchallenge
04-05-2022, 02:30 PM (This post was last modified: 04-06-2022 06:44 AM by J-F Garnier.)
Post: #21
RE: [VA] "Introducing APRIL !" microchallenge
.
The "APRIL" Case, Day #5.

This is continuation of my previous post.

We are now concentrating on our primary suspect, the >DEG, >RAD pair, and are searching for evidences.
So we visited our source, the VASM 41 - the HP-41 source file location.
Quite easily, we found the sections related to >DEG (alias R-D) and >RAD (alias D-R) and found out how they are computed:

The routine RTOD does what we can translate in RPN style by: 90 * [PI/2] /
Reciprocally, DTOR is doing : [PI/2] * 90 /
[PI/2] represents the 13-digit quantity 1.570796326795 and all arithmetic is done with 13 digits (truncated, not rounded).
The rounding to 10 digits is done at the end, and only once.

But we have no equivalent source for the Spice Series.
"No problem", our Experts said, "We don't need the sources, we have access to an emulator able to trace the code (1), we will find it out."
And here is what we found for the 33E:
The equivalent of RTOD does [PI/4] / 45 * and DTOR does 45 / [PI/4] *
[PI/4] represents the 13-digit quantity 0.7853981633975, exactly half of the 41C's [PI/2] quantity.

So the problem doesn't come from a flawed constant.


Let's summarize:

Model | --- >DEG ---- | ---- >RAD ----
HP41C | 90 * [PI/2] / | [PI/2] * 90 /
HP33E | [PI/4] / 45 * | 45 / [PI/4] *


The 41C and 33E expressions are mathematically equivalent, but not necessary equivalent with finite floating-point numbers.

Let's look at the >DEG operation that is easier to analyse.

The 41C version does a multiplication by 90 first, then a division by [PI/2]
This is the optimum code, because we can be sure that any 10-digit number multiply by 90 will fit in 13 digits.
The operation is exact, so the accuracy of the whole >DEG operation is only the result of the next division, that we know (the Experts...) is providing, after rounding, the best (and unique) 10-digit representation of the quantity.

This is not the case with the 33E version.
Dividing by [PI/4] is generally not exact, the result is truncated to the 13-digit value just below the infinite precision value.
For these intermediate results that have a mantissa between 1 and about 2, the next multiplication by 45 will amplify the difference up to 4 ULP (here at the 13th digit).
For most numbers, the difference will be masked when rounding to 10 digits.
But for some numbers, that give a 13-digit result ending with the last 3 digits just around the threshold of ..500 between rounding up and down, the final 10-digit will be 1 ULP below the "best representation".

All we have to do now is to find an example.

Who will be the first (after Valentin) to find a 10-digit number that gives different results with >DEG on the 33E and 41C ?
It should not be too difficult now, we even have an idea of the probability of occurrence.
Instead of the 33E, you can use the emulator referenced below (1)

J-F

(1) The CCE33 emulator, part of the Multicalc project, that I already mentioned.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] "Introducing APRIL !" microchallenge - J-F Garnier - 04-05-2022 02:30 PM



User(s) browsing this thread: 11 Guest(s)