Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Floating point non-exactness Message-ID: <11147@alice.UUCP> Date: 6 Aug 90 04:19:01 GMT References: <622@.tetrauk.UUCP> <5467@quanta.eng.ohio-state.edu> <4958@memqa.uucp> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 20 In article <4958@memqa.uucp>, r91400@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) 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@europa.att.com