Re: Rounding Float in C and Remove those Zeros
- From: Vladimir Oka <novine@xxxxxxxxxxxxxxx>
- Date: Fri, 12 May 2006 17:57:55 +0100
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>
.
- Follow-Ups:
- Re: Rounding Float in C and Remove those Zeros
- From: Malcolm
- Re: Rounding Float in C and Remove those Zeros
- References:
- Rounding Float in C and Remove those Zeros
- From: kennethlou
- Re: Rounding Float in C and Remove those Zeros
- From: Vladimir Oka
- Re: Rounding Float in C and Remove those Zeros
- From: Vladimir Oka
- Rounding Float in C and Remove those Zeros
- Prev by Date: Dynamic tracing of C code execution
- Next by Date: Re: Dynamic tracing of C code execution
- Previous by thread: Re: Rounding Float in C and Remove those Zeros
- Next by thread: Re: Rounding Float in C and Remove those Zeros
- Index(es):
Relevant Pages
|