Re: printf "%.100f" the value 2 ^ (-127)
From: Tim Roberts (timr_at_probo.com)
Date: 03/24/04
- Next message: Tim Roberts: "Re: question marks in formatted strings"
- Previous message: a.m.a: "Re: MsAgent SDK"
- In reply to: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Next in thread: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Reply: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 23 Mar 2004 21:49:27 -0800
"Simon Trew" <ten.egnaro@werts> wrote:
>
>But the number is represented exactly in the FP representation; it's the
>conversion function (printf) that's doing the rounding. Given that number, a
>different conversion function might produce a more precise decimal
>approximation.
"Precise" is a very fuzzy word in this context. Floating point numbers are
all approximations. The hex value 3800000000000000 contains only 54 bits
of mantissa information. It MIGHT represent the exact value 2^-127, but it
might represent 2^-127 + 2^-182. It is misleading to pretend that this
number actually contains hundreds of decimal digits.
I CAN tell you exactly why this happens, if you are interested. The
conversion of floating point values to decimal values is done using the
Pentium's FBST instruction. This instruction converts the mantissa of an
IEEE754 floating point number to a 19-digit decimal value in BCD format,
the last digit of which is unreliable and usually discarded. The
conversion routine just has to adjust the decimal point and print.
Thus, no floating point conversion in Windows will ever produce more than
18 non-zero digits.
-- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc
- Next message: Tim Roberts: "Re: question marks in formatted strings"
- Previous message: a.m.a: "Re: MsAgent SDK"
- In reply to: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Next in thread: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Reply: Simon Trew: "Re: printf "%.100f" the value 2 ^ (-127)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|