Re: Weirdness: (-0.666667 + 0.333333)

From: Gert Van den Eynde (gvdeynde_at_hotmail.com)
Date: 05/06/04


Date: Thu, 06 May 2004 09:24:33 +0200

Corne' Cornelius wrote:

> i should've made it more clear what i actually want to do.
>
> I'm not really trying to compare 2 double which could be in accurate
> becuase of rounding errors.
>
> I'm writing a program that draws graphs on a cartesian plane, so in
> order to go on the x-axis from say -2, to +2, in 20 intervals, i need
> one of these point to be zero or very close to it.
>
> how could i make sure i don't get rounding problems ?
>
You can't. The only thing you can do is to compare your value of x to zero
(using fcmp) and if it's close enough force it to be zero. Btw, Is the
difference between 1e-16 and 0.0 so significant that it will show up on a
graph in the range [-1,1] ?

bye,
gert



Relevant Pages

  • Re: Weirdness: (-0.666667 + 0.333333)
    ... x - epsilon() < 0 ... >>becuase of rounding errors. ... The only thing you can do is to compare your value of x to zero ...
    (comp.lang.cpp)
  • Re: if statement
    ... The zero argument tells Matchto return the first *exact* match. ... > There can be 6 different numbers in the target evaluation cell and I want ... > compare it 6 different ways and if it matches the correct value compared ... > can't get it to string together more than the one comparison. ...
    (microsoft.public.excel.misc)
  • Re: writing a two hour movie script
    ... You're an idiot, appropriately named "Zero". ... includes TV movies and small companies. ... but to top it all off, you don't compare the number of aspiring ... agent in Florida on the Net who sold the book for him. ...
    (misc.writing)
  • Re: Why is "False" = "-1"?
    ... A must be compared to zero or some other ... (Excepting perhaps for a dumb compiler and I ... dumb--actually a couple of his examples show better code generation than ... the machine instruction to compare to--whether it's zero or nonzero ...
    (microsoft.public.vb.general.discussion)
  • Re: Value close to zero.
    ... floating point value is zero may become a problem. ... Just comparing some quantity x with matlab's 'eps' is not an adequate test ... are likely to differ from zero only because of rounding errors, ...
    (comp.soft-sys.matlab)