From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) From: Bakul Shah In-Reply-To: Date: Wed, 21 Aug 2013 10:42:57 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <2FEB81A6-7D40-427D-BF9B-07D90872E307@bitblocks.com> References: <04891ed00c35de2583c1da9a017dd7e2@hamnavoe.com> To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] comparisons with NaN Topicbox-Message-UUID: 7342a6f4-ead8-11e9-9d60-3106f5b1d025 On Aug 21, 2013, at 9:55 AM, erik quanstrom = wrote: > On Wed Aug 21 12:09:26 EDT 2013, 9fans@hamnavoe.com wrote: >>> at least in terms of passing floating point test suites >>> (like python's) the NaN issue doesn't come up >>=20 >> Actually it was a test suite that revealed the NaN errors. >> I wouldn't think it's something anyone needs in normal >> day-to-day computation, but sometimes boxes must be ticked. >=20 > :-) it is hard to imagine how this is useful. it's not like > =E2=88=91{i=E2=86=92=E2=88=9E}-0 is interesting. at least = =E2=88=8F{i=E2=86=92=E2=88=9E}-0 has an alternating > sign. (so does it converge with no limit?) >=20 > the difference i have seen is a situation like > atan2(-0, x) =E2=89=A1 -=CF=80 > atan2(+0, x) =E2=89=A1 pi, =E2=88=80 x<0. >=20 > any ideas on how this is useful? See comments by Stephen Canon in = http://stackoverflow.com/questions/1565164/what-is-the-rationale-for-all-c= omparisons-returning-false-for-ieee754-nan-values Try this: #include #include main(){ double a, b; setfcr(0); a =3D 0.0; b =3D a/a; if(a < b) print(" (a < b)"); if(a <=3D b) print(" (a <=3D b)"); if(a =3D=3D b) print(" (a =3D=3D b)"); if(a !=3D b) print(" (a !=3D b)"); if(a >=3D b) print(" (a >=3D b)"); if(a > b) print(" (a > b)"); if(b < a) print(" (b < a)"); if(b <=3D a) print(" (b <=3D a)"); if(b =3D=3D a) print(" (b =3D=3D a)"); if(b !=3D a) print(" (b !=3D a)"); if(b >=3D a) print(" (b >=3D a)"); if(b > a) print(" (b > a)"); if(b !=3D b) print(" (b !=3D b)"); if(b =3D=3D b) print(" (b =3D=3D b)"); print("\n"); return 0; } It falsely reports b =3D=3D b when b is NaN.=20=