Re: Rounding Float in C and Remove those Zeros



osmium opined:

"Vladimir Oka" writes:

I > think (before looking into the Standard) that all small integers
are guaranteed to be. Beware numbers like 1000000000000042.0000,
though.

No. For example, the number 1 can not be represented exactly. Select
as many terms as you wish from the following series:
1/2, 1/4, 1/8, ....1/2^googolplex

No way are you going to get a 1 out of that. People who write I/O
libraries are aware of this and create the *illusion* that you can.

Hmmm. A quick look into the Standard, and some searching through past
c.l.c posts seem to justify my statement that certain range of
integers is indeed exactly representable in floating point types.

Look at the <float.h>. It defines FLT_DIG, DBL_DIG and LDBL_DIG as
the number of decimal digits of precision in a `float`, `double` and
`long double`, respectively. Integers with less than this number of
digits should be exactly representable in the appropriate floating
point types.

I can't say much (anything?) about how this is exactly achieved,
though.

--
Too much of anything, even love, isn't necessarily a good thing.
-- Kirk, "The Trouble with Tribbles", stardate 4525.6

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

.



Relevant Pages

  • Re: Bit representation of a float
    ... of floating point numbers must follow certain patterns as laid out in ... You must have a fixed base and precision for each floating ... in the underlying bits is not specified by the Standard, ... number of decimal digits, q, such that any floating point number ...
    (comp.lang.c)
  • Re: FLT_DIG
    ... floating point with radix 100, the C99 formula says that it can represent ... any floating point number with 2 decimal digits while it is unable to ...
    (comp.std.c)
  • Re: This calculation is just wrong / computer cant count!
    ... BCD also has the advantage of providing more significant decimal ... arithemtic, AS IMPLEMENTED ON THE PENTIUM FPU, as demonstrated by my Floating Point ... If you can't understand that using binary to represent decimal digits ... properly rounding. ...
    (microsoft.public.vc.mfc)
  • Re: FLT_DIG
    ... floating point with radix 100, the C99 formula says that it can represent ... any floating point number with 2 decimal digits while it is unable to ... Jun, Woong ...
    (comp.std.c)
  • Re: Salt chuck scoundrels
    ... suggest floating a dingy over to them with a "reset button" on it? ...  Instigators of man-made disasters and your ilk, beware of BOzo's ... dreaded "Mixed-Tape" diplomacy!! ...
    (rec.sport.football.college)