Re: support for bitwise comparison of floats

2007-03-31 Thread Bruno Haible
Paul Eggert wrote: > It is referring to the behavior of the VAX floating point unit, where the > hardware representation that one thinks would represent -0.0 behaves > sort of like a NaN. To avoid this problem, on a VAX copysign(0, -1) > returns +0.0, not the usual -0.0. That is why the C and POS

Re: support for bitwise comparison of floats

2007-03-29 Thread Paul Eggert
Bruno Haible <[EMAIL PROTECTED]> writes: > In other words, the standard allows the function to be buggy... The wording you quoted is talking about something else. It is referring to the behavior of the VAX floating point unit, where the hardware representation that one thinks would represent -0.

Re: support for bitwise comparison of floats

2007-03-29 Thread Bruno Haible
Paul Eggert wrote: > vasnprintf.c should do this: > > if (copysignl (1, arg) < 0) > { > sign = -1; > arg = -arg; > } > > I think it's much cleaner. And the code is smaller on my platform, > anyway: no function call is generated for copysignl.

Re: support for bitwise comparison of floats

2007-03-29 Thread Paul Eggert
The "right" way to test for -0 versus +0 is to use copysign. For example, instead of this: if (arg < 0.0L) { sign = -1; arg = -arg; } else if (arg == 0.0L) { /* Distinguish 0.0L and -0.0L. */ static long

Re: support for bitwise comparison of floats

2007-03-25 Thread Bruno Haible
Clarification: > > - On Alpha processors, division by zero (and even overflow!) leads to a > > SIGFPE > > signal by default. And it requires the use of a system call to change > > the FP exceptions control mask (the routines in glibc >= 2.1, > > the __setfpucw function in glibc 2.0

Re: support for bitwise comparison of floats

2007-03-25 Thread Bruno Haible
Eric Blake wrote: > recent coreutils snapshots have used it, and no one has complained so far. Plenty of packages have used it for 10 years or longer: GCC installs or installed files in $prefix/include/g++, and a library called libstdc++. binutils has a program called 'c++filt'. gettext is using a

Re: support for bitwise comparison of floats

2007-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 3/24/2007 7:04 PM: > > 2007-03-24 Bruno Haible <[EMAIL PROTECTED]> > > * lib/float+.h: New file. Is + a reasonable file name character these days? On the one hand, it is not listed in the "portable filename char

Re: support for bitwise comparison of floats

2007-03-25 Thread Ben Pfaff
Eric Blake <[EMAIL PROTECTED]> writes: > According to Bruno Haible on 3/25/2007 9:57 AM: >> Eric Blake wrote: >>> /* return true iff the representation of d needs a leading '-' */ >>> bool >>> is_negative (long double d) >>> { >>> if (d == 0) >>> { >>> union { >>> long double d

Re: support for bitwise comparison of floats

2007-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 3/25/2007 9:57 AM: > Eric Blake wrote: >> Is this any more portable, by avoiding floating point division altogether? >> >> /* return true iff the representation of d needs a leading '-' */ >> bool >> is_negative (long doubl

Re: support for bitwise comparison of floats

2007-03-25 Thread Bruno Haible
Eric Blake wrote: > Is this any more portable, by avoiding floating point division altogether? > > /* return true iff the representation of d needs a leading '-' */ > bool > is_negative (long double d) > { > if (d == 0) > { > union { > long double d; > long l; > }

Re: support for bitwise comparison of floats

2007-03-25 Thread Bruno Haible
PS: I wrote: > - On Alpha processors, division by zero (and even overflow!) leads to a > SIGFPE > signal by default. And it requires the use of a system call to change > the FP exceptions control mask (the routines in glibc >= 2.1, > the __setfpucw function in glibc 2.0). memcmp is

Re: support for bitwise comparison of floats

2007-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 3/25/2007 4:54 AM: > Eric Blake wrote: >> You can also assume IEEE rules, and compare against signed infinity: >> 1 / +0. => +infinity >> 1 / -0. => -infinity > > Nice trick :-) > > But here you depend on the IEEE rules f

Re: support for bitwise comparison of floats

2007-03-25 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 3/25/2007 4:54 AM: > Eric Blake wrote: >> You can also assume IEEE rules, and compare against signed infinity: >> 1 / +0. => +infinity >> 1 / -0. => -infinity > > Nice trick :-) Thanks for correcting my typo; which I real

Re: support for bitwise comparison of floats

2007-03-25 Thread Bruno Haible
Eric Blake wrote: > You can also assume IEEE rules, and compare against signed infinity: > 1 / +0. => +infinity > 1 / -0. => -infinity Nice trick :-) But here you depend on the IEEE rules for exceptions upon division by zero. - On Alpha processors, division by zero (and even overflow!) leads to

Re: support for bitwise comparison of floats

2007-03-24 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Bruno Haible on 3/24/2007 7:04 PM: > Hi, > > How can one distinguish +0.0 and -0.0. printf() needs to be able to do it. > How can this be done portably? I can see two ways: > a) By knowing the bit position of the sign bit. > b) By doi

support for bitwise comparison of floats

2007-03-24 Thread Bruno Haible
Hi, How can one distinguish +0.0 and -0.0. printf() needs to be able to do it. How can this be done portably? I can see two ways: a) By knowing the bit position of the sign bit. b) By doing a bit-for-bit comparison against +0.0. The second approach appears to be implementable with less portab