Re: Weirdness: (-0.666667 + 0.333333)
From: Richard Herring (junk_at_[127.0.0.1)
Date: 05/07/04
- Next message: Surya Kiran: "getting New line character"
- Previous message: Richard Herring: "Re: What is boost's unspecified_bool_type?"
- In reply to: Corne' Cornelius: "Re: Weirdness: (-0.666667 + 0.333333)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 7 May 2004 11:07:08 +0100
In message <ZK2dnZEXiNV0ewTd4p2dnA@is.co.za>, Corne' Cornelius
<cornec@nospam-for-noreason.uy> writes
>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 often improve matters by using an integer loop counter:
instead of: for (double x=xstart; x<xend; x+=step) {...}
use something like: for (int i=istart; i<iend; ++i) { double x=i*xstep;
...}
It doesn't get rid of the rounding errors, but it does ensure that they
don't accumulate as you progress through the loop.
-- Richard Herring
- Next message: Surya Kiran: "getting New line character"
- Previous message: Richard Herring: "Re: What is boost's unspecified_bool_type?"
- In reply to: Corne' Cornelius: "Re: Weirdness: (-0.666667 + 0.333333)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|