Re: Floating point comparisons

2007-08-04 Thread chromatic
On Wednesday 01 August 2007 13:50:45 Joshua Hoblitt wrote: I'm not sure if 0.0 == -0.0 is true on all platforms. It should be for IEEE754 compliance but in the real world... It might be nice to throw in a few tests to see if the example code below would have the same results on all

Re: Floating point comparisons

2007-08-04 Thread Doug McNutt
At 12:58 -0700 8/4/07, chromatic wrote: On Wednesday 01 August 2007 13:50:45 Joshua Hoblitt wrote: #include stdio.h #include math.h int main () { printf(0.0 : %f\n, 0.0); printf(-0.0 : %f\n, -0.0); printf(0.0 == -0.0 : %d\n, 0.0 == -0.0); } I'm afraid that would me more of

Re: Floating point comparisons

2007-08-02 Thread Andy Dougherty
On Thu, 2 Aug 2007, Joshua Isom wrote: I'm pretty sure 0.0 always equals -0.0. I think it's part of the c specification. Now, on OpenBSD, you can't print -0.0, as it will print 0.0 instead which is really annoying. This is with at least 3.8 but I don't know if it's been changed since then.

Re: Floating point comparisons

2007-08-02 Thread Doug McNutt
At 09:34 -0400 8/2/07, Andy Dougherty wrote: Guessing programmer intent doesn't seem to me to be an appropriate job for a virtual machine. Agreed. But in engineering and science floating point tests are often buried in deep loops. An operator for rapid testing of near-equal can help with

Re: Floating point comparisons

2007-08-01 Thread Paul Cochrane
On 31/07/07, Andy Lester [EMAIL PROTECTED] wrote: On Jul 31, 2007, at 1:32 PM, peter baylies wrote: That may not be a bad idea, but I think there's a bug in that code -- take, for example, the case where x and y both equal approximately a million (or more). Maybe you wanted this

Re: Floating point comparisons

2007-08-01 Thread Paul Cochrane
A couple of comments on dealing with floats. - Use FLT_EPSILON/DBL_EPSILON from float.h - You method is total overkill, return (fabs(x - y) DBL_EPSILON ? 1 : 0); should be sufficent (note: check with a numerical expert). This is what I thought in the beginning. However, whether one uses

Re: Floating point comparisons

2007-08-01 Thread Doug McNutt
At 18:32 + 7/31/07, peter baylies wrote: On 7/31/07, Paul Cochrane [EMAIL PROTECTED] wrote: return (fabs(x - y) = fabs(x + y)*EPSILON) ? 1 : 0; That may not be a bad idea, but I think there's a bug in that code -- take, for example, the case where x and y both equal approximately a

Re: Floating point comparisons

2007-08-01 Thread mark . a . biggar
if the values you are storing in floats are known to be integers of a size less then the mantissa for he floating type then exact comparisons work just as expected. Storing 10 digit phone numbers as floats is an example of this. There must be some way to access exact comparisons in the

Re: Floating point comparisons

2007-08-01 Thread Joshua Hoblitt
I'm not sure if 0.0 == -0.0 is true on all platforms. It should be for IEEE754 compliance but in the real world... It might be nice to throw in a few tests to see if the example code below would have the same results on all platforms. -- #include stdio.h #include math.h int main () {

Re: Floating point comparisons

2007-08-01 Thread Joshua Isom
I'm pretty sure 0.0 always equals -0.0. I think it's part of the c specification. Now, on OpenBSD, you can't print -0.0, as it will print 0.0 instead which is really annoying. This is with at least 3.8 but I don't know if it's been changed since then. Anyway, to test for -0.0 instead of

Floating point comparisons

2007-07-31 Thread Paul Cochrane
Hi all, I'm wanting to remove all the floating point comparison warnings which appear when compiling parrot and wanted some advice as to how best to achieve this. Floating point comparisons appear in code such as (taken from src/string.c): if (*p == '-' f == 0.0) I'd like to replace

Re: Floating point comparisons

2007-07-31 Thread peter baylies
On 7/31/07, Paul Cochrane [EMAIL PROTECTED] wrote: Hi all, I'm wanting to remove all the floating point comparison warnings which appear when compiling parrot and wanted some advice as to how best to achieve this. Floating point comparisons appear in code such as (taken from src/string.c

Re: Floating point comparisons

2007-07-31 Thread Joshua Hoblitt
)*EPSILON) ? 1 : 0; } (this code was adapted from equivalent fortran code given here: http://www.lahey.com/float.htm courtesy of particle++). Is this a good way to achieve the goal of safe floating point comparisons? The #define and function need to go somewhere. Where exactly? And which

Re: Floating point comparisons

2007-07-31 Thread Andy Dougherty
On Tue, 31 Jul 2007, Paul Cochrane wrote: Hi all, I'm wanting to remove all the floating point comparison warnings which appear when compiling parrot and wanted some advice as to how best to achieve this. Floating point comparisons appear in code such as (taken from src/string.c

Re: Floating point comparisons

2007-07-31 Thread Joshua Hoblitt
at 07:17:15PM +0200, Paul Cochrane wrote: Hi all, I'm wanting to remove all the floating point comparison warnings which appear when compiling parrot and wanted some advice as to how best to achieve this. Floating point comparisons appear in code such as (taken from src/string.c

Re: Floating point comparisons

2007-07-31 Thread Andy Lester
On Jul 31, 2007, at 1:32 PM, peter baylies wrote: That may not be a bad idea, but I think there's a bug in that code -- take, for example, the case where x and y both equal approximately a million (or more). Maybe you wanted this instead: return (fabs(x - y) = EPSILON) ? 1 : 0; The