Floating point non-exactness
Andrew Koenig
ark at alice.UUCP
Mon Aug 6 14:19:01 AEST 1990
In article <4958 at memqa.uucp>, r91400 at memqa.uucp (Michael C. Grant) writes:
> For example, assuming a standard which
> requires normalization, this algorithm might work (note this is
> just a near-equality test, not a complete comparison):
> if (exponent_a!=exponent_b) return false
> if abs(mantissa_a-mantissa_b)<error_limit return true
> else return false
You can use frexp() to split numbers into mantissa and exponent
(though I forget whether frexp is actually part of the ANSI standard
or not). However, the algorithm shown here doesn't work because
the two numbers being compared could straddle a power of 2,
which would give them different exponents even though they're
arbitrarily close together.
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list