Re: comparing doubles for equality
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 30 Apr 2007 20:13:48 GMT
Richard Weeks <rweeks@xxxxxxxxxx> wrote:
Jens Thoms Toerring wrote:
Richard Weeks <rweeks@xxxxxxxxxx> wrote:
int dbl_isequal(double a, double b)
{
double fraca, fracb, reldiff;
if((int)a == (int)b)
This probably will fail for numbers that can't be represented as
integers, e.g. for numbers like the numbers in the order of the
number of particles in one Mol of a substance which is ca. 6e23
and probably not an uncommon number in scientific calculations.
But on many systems such a number (or just the national debt of
some countries;-) won't fit into an int (or even a long int)
In which case standard C (without extended precision routines)
will be inadequate for the calculations anyway.
Not necessarily - you may not need 24 digits of precision (you
rarely care about a few million molecules in a Mol of gas;-)
but you may want to know if two results you arrived at using
different methods are identical within the precision your double
type give you.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- comparing doubles for equality
- From: Richard Weeks
- Re: comparing doubles for equality
- From: Jens Thoms Toerring
- Re: comparing doubles for equality
- From: Richard Weeks
- comparing doubles for equality
- Prev by Date: Re: OT somewhat: Do you telecommute? What do you wish the boss understood about it?
- Previous by thread: Re: comparing doubles for equality
- Next by thread: OT somewhat: Do you telecommute? What do you wish the boss understood about it?
- Index(es):
Relevant Pages
|