Re: printf "%.100f" the value 2 ^ (-127)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tim Roberts (timr_at_probo.com)
Date: 03/24/04


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


Relevant Pages

  • Re: Integer to Double conversion
    ... > IntToExtended or Int64ToExtended conversion function. ... > is compiler supported the code is generated inline. ... > floating point arithmetic. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Floating Point and C casts? (was: Re: typecast internals)
    ... You are mixing a discussion of integer and floating point storage ... What particular data conversion problem are you really ... formats), but these formats are not typically implemented off the VAX ... IEEE floating point conversions are detailed in the compiler manuals ...
    (comp.os.vms)
  • Re: converting float to double
    ... but this is also true of the integer math ... back conversion resulted in the original. ... of approximate inverse functions and what you have to do ... Doing it in floating point would be much more problematical. ...
    (comp.lang.c)
  • Re: converting float to double
    ... > Dik T. Winter wrote: ... floating point it is irrelevent. ... So it will not work for conversion of pre-euro valuta to euro valuta ... easier in the floating point case. ...
    (comp.lang.c)
  • Re: converting float to double
    ... but this is also true of the integer math ... > easier in the floating point case. ... >> when converting gulden to euro and the reverse did work, ... >> back conversion resulted in the original. ...
    (comp.lang.c)