Re: Ceil double problem



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.
.



Relevant Pages

  • Re: So far OT its over the horizon: Anyone into 3D modelling?
    ... > screws, 2.5 metre ball screws have a certain minimum cost, even if you ... > cut out ALL the middle men you'll be looking at IRO 500 quid per axis ... you could use precision threaded bar and a couple of nuts to ... > eliminate backlash, but it's gonna wear quickly, take more power to ...
    (uk.rec.motorcycles)
  • Re: So far OT its over the horizon: Anyone into 3D modelling?
    ... screws, 2.5 metre ball screws have a certain minimum cost, even if you ... cut out ALL the middle men you'll be looking at IRO 500 quid per axis ... you could use precision threaded bar and a couple of nuts to ... eliminate backlash, but it's gonna wear quickly, take more power to ...
    (uk.rec.motorcycles)
  • Re: My Homework: how to calculate natural log, e?
    ... > So GT's claim of 1ulp precision are demonstrably false. ... with pwr equal to a power of two) throws away a lot ... couple of hundred ULPs when the input is around 700. ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: Unwanted rounding
    ... might tease you to believe you have precision to 40+ digits. ... A floating point number is a number of the form ... because that is not the exact representation ... Nothing infinite about it. ...
    (comp.lang.c)
  • Re: computing t = pow(-11.5, .333)
    ... approach was to first convert the float, with a binary exponent, to ... a 'decimalfloat' with a power of 10 exponent (always with a binary ... significand). ... systems accuracy was only 4.7 decimal digits, ...
    (comp.lang.c)