This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Comparing doubles


At 8:15 PM +0200 7/1/02, Lars Brinkhoff wrote:
Does the C standard define exactly how floating-point comparisons
should work?  Sections 6.5.8 Relational operators and 6.5.9 Equality
operators in C99 doesn't spell out any details.

In particular, would it be acceptable for a GCC back end to compare
two doubles by subtracting them, converting the result to float, and
then compare the result against zero?
I don't quite remember what PDP10 doubles were like, but if you don't have NANs, then using subtraction is probably a viable approach. You might look at how this is implemented in the softfloat libraries. It is probably reasonable to check the signs, check the exponents and then as a last resort check the magnitudes. The problem with using subtract is that you may trigger underflow exceptions or have an undetected underflow interpreted as equality when it isn't.

If you can run paranoia successfully, you probably have dealt with the whole class of comparison problems that are possible....

-- Al

--
Quality Software Management
http://home.earthlink.net/~qsmgmt
apl@alum.mit.edu
(978)287-0435 Voice
(978)808-6836 Cell

Software Process Improvement / Management Consulting
Language Design / Compiler Implementation



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]