Re: Ceil double problem
- From: Jordan Abel <random832@xxxxxxxxx>
- Date: 2 Mar 2006 21:36:52 GMT
On 2006-03-02, Richard Bos <rlb@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx> wrote:
Richard Bos wrote:
"Vladimir S. Oka" <novine@xxxxxxxxxxxxxxx> wrote:
mikael.liljeroth@xxxxxxxxx wrote:
Why do I get NO as result from this ??
double du = (double)3.1415;
du = ceil(du);
if(du == (double)4)
printf("YES\n");
else
printf("NO\n");
I get YES (mingw/gcc). Your machine may not be able to represent 4.0
exactly.
If so, it's broken.
Not if it uses bas 3 arithmetic. ;-)
Do doubles have to be encoded in base 2?
Oddly enough, no. Or rather, oddly enough, the base doesn't have to be a
power of 2; base 16 FP maths would be reasonable on some systems.
However, DBL_DIG must be greater than or equal to 10; 4.0 only has 1
decimal.
DBL_DIG doesn't mandate an exact representation, it only requires that
all numbers to that precision be uniquely representable.
My c89 draft says:
* number of decimal digits of precision, $left floor~(p~-~1)~times~{
log sub 10 } b~right floor ~+~ left { lpile { 1 above 0 } ~~ lpile {
roman "if " b roman " is a power of 10" above roman otherwise }$
According to my best interpretation of eqn syntax, that becomes:
* number of decimal digits of precision, floor((p-1)*log[10]b)+(1 if b
is a power of 10, 0 otherwise)
neqn+nroff mangles this into (blank lines removed)
* number of decimal digits of precision, |_(_\bp-1)xlog10_\bb_|+{
is a power of 10 0
\b\b\b\b\botherwise
Where 'p' is DBL_MANT_DIG and 'b' is FLT_RADIX.
.
- References:
- Ceil double problem
- From: mikael . liljeroth
- Re: Ceil double problem
- From: Vladimir S. Oka
- Re: Ceil double problem
- From: Richard Bos
- Re: Ceil double problem
- From: Vladimir S. Oka
- Re: Ceil double problem
- From: Richard Bos
- Ceil double problem
- Prev by Date: Re: address of a struct or a pointer to a struct?
- Next by Date: Re: Ceil double problem
- Previous by thread: Re: Ceil double problem
- Next by thread: Re: Ceil double problem
- Index(es):
Relevant Pages
|