[comp.lang.c] Floating constants

franka@mmintl.UUCP (Frank Adams) (06/26/87)

[I'm not sure who wrote what here, so I have deleted the references.]

>>>> 4.  Allow floating point numbers to be given in hex.  Try putting
>>>> in 2^-32 as a floating point or double constant.  Why should one
>>>> have to risk computer roundoff when it is totally unnecessary?
>
>There is a problem with both of those: suppose floating-point is not
>stored in a binary format - say it uses floating-point ternary?
>Suppose the machine uses packed decimal?  Suppose you figure out your
>hex constant for your VAX and then have to port to your Sun?  Then to
>your 80x86?  Then to your IBM mainframe?  Then to that packed decimal
>machine I mentioned?  Yech.  Just write 1/65536.0/65536.0 and let the
>compiler figure it out.

I may be missing something here, but I think the proposal was to permit
floating point numbers to be entered in radix 16, not as the bit pattern
required to represent the number on the target machine.  That is, to enter
2^-32, one would write something like 0x1e-8.  (This is assuming that only A
through F are available for hex digits, not a through f, and that only e is
usable for floating point exponents, not E.)

Even if this isn't what the original poster wanted, *I* think it would be a
good idea, if a suitable notation can be found.  The notation I used above
is not backward compatible, and thus unacceptable.

One suggestion: use h for the hexadecimal exponent: 0x1h-8.  I like this
well enough to recommend it compiler writers as an extension.
-- 

Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
Ashton-Tate          52 Oakland Ave North         E. Hartford, CT 06108