Playing with the bits of floats

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Jan 18 02:29:24 AEST 1989


In article <1096 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>> In article <MAX.89Jan13163256 at george.lbl.gov> max at george.lbl.gov (Max Rible) writes:
>> >I'm trying to do deal with floating point numbers as if they're ints.
>< <Things like "if(((3.1 - 3.14) & 0x7FFFFFF) <= 0.1)"--- lousy
>< <programming style, I know, but I'm interested in speed, not
>< <portability for this application.
>I agree that every language should make it easy for the knowledgeable
>programmer to do these things, but I am afraid the movement is in the
>opposite direction.

I utterly disagree.  Generating efficient code for routine floating-point
operations is the job of the compiler, not the high-level programmer.
There is no reason why, if the suggested replacement test represents the
most efficient code for the test, that the compiler should not generate
it in the first place.

There are a few cases, such as dealing with IEEE-754 NaNs, where bit
patterns are necessary.  C vendors on such systems have, quite properly,
provided the necessary support as macros or functions, so the programmer
still need not concern himself with bit-twiddling.



More information about the Comp.lang.c mailing list