[Cfp-interest 2554] Re: exact DFP from BFP

Fred J. Tydeman tydeman at tybor.com
Fri Oct 28 13:25:27 PDT 2022


On Fri, 28 Oct 2022 22:42:26 +0300 (EAT) Fred J. Tydeman wrote:
>
>Preferred quantum exponent for exact conversion from non-decimal
>floating type.
>
>Consider a binary float of 1/64 == 0.015625f converted (exactly) to
>Decimal32.  I believe the DFP would be (+,15625,-6), rather than
>(+,156250,-7) or (+,1562500,-8) or (+,0,0).  Correct?
>
>If the above is correct, why does the "Preferred quantum exponents"
>table in C23 in 5.2.4.2.3, around page 31, say it should be 0, instead
>of -6 for this case?  Should it not be either "greatest possible" or
>"least possible" instead of 0?

I now see (before the table):

"When exact, these operations produce a result with their preferred
quantum exponent, or as close to it as possible within the limitations
of the type."

So, (+,15625,-6) is the correct value.

In case I was not clear, I was looking at:
 float f = 0.015625f;
 _Decimal32 dfp = f;

In looking in IEEE-754-2019, I found in 5.4.2:
For exact conversions from binary to decimal formats, the preferred exponent is 0.

In my re-reading of IEEE-754 today, I missed 5.2:
If the result's cohort does not include a member with the preferred
exponent, the member with the exponent closest to the preferred exponent is used.


---
Fred J. Tydeman        Tydeman Consulting
tydeman at tybor.com      Testing, numerics, programming
+1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.



More information about the Cfp-interest mailing list