RE: comparing floating point numbers

2005-07-25 Thread robert
-Original Message- From: James Sluka Sent: Monday, July 25, 2005 9:11 AM > Robert's solution (rounding with sprintf) is pretty good, except it > requires that you know something about the numbers. you are correct about the limitations of floating point accuracy, but in this case you ar

Re: comparing floating point numbers

2005-07-25 Thread len boyle
5 3:39 PM Subject: RE: comparing floating point numbers Ed Chester <[EMAIL PROTECTED]> wrote: just a warning to be careful of subtracting or dividing similar numbers in floating point and what your expectations are for the results. google for 'catastrophic loss of precision&#x

(Was Re: comparing floating point numbers) now [OT]: catastrophic cancellation

2005-07-25 Thread Ed Chester
Mike wrote: [snipped] > items that specifically referred to the floating point Error in the first batch of Pentium chips Sorry, I should have narrowed the search then. This is not specific to that error, it is a consequence of the FP number system representation. It arises in certain circumstance

RE: comparing floating point numbers

2005-07-25 Thread Arms, Mike
Ed Chester <[EMAIL PROTECTED]> wrote: > just a warning to be careful of subtracting or dividing similar numbers in > floating point and what your expectations are for the results. google for > 'catastrophic loss of precision' or similar, or check out the floating point > standard (IEEE #754) for

re: comparing floating point numbers

2005-07-25 Thread Ed Chester
this is top-posted because it doesn't follow from any one of the previous posts. just a warning to be careful of subtracting or dividing similar numbers in floating point and what your expectations are for the results. google for 'catastrophic loss of precision' or similar, or check out the floa

Re: comparing floating point numbers

2005-07-25 Thread James Sluka
<>Robert's solution (rounding with sprintf) is pretty good, except it requires that you know something about the numbers. For example, they must differ by more than 0.01 to be considered different. What happens when the two numbers are;   0.101   0.100 Now you need to check fo

Re: comparing floating point numbers

2005-07-25 Thread robert
use "sprintf" to set the floating point field to 2 decimal places. (or more, if you want them...) $float1=-135.176# final values before rounding $float2=-135.184 $float1=sprintf("%.2f",$float1);# force $float1 to be rounded at 2 decimal places $float2=sprint

RE: comparing floating point numbers

2005-07-25 Thread robert
use "sprintf" to set the floating point field to 2 decimal places. (or more, if you want them...) $float1=-135.176# final values before rounding $float2=-135.184 $float1=sprintf("%.2f",$float1);# force $float1 to be rounded at 2 decimal places $float2=sprintf

RE: comparing floating point numbers

2005-07-25 Thread robert
On Sunday, July 24, 2005 at 6:11 PM, Ken Barker wrote: > > What kind of post is this? > > I do not see that anything was added at all. Give us all a > break - don't > bother - whatever your intentions. > well, don't you feel stupid now? > > At 06:35 PM 7/24/2005, $Bill Luebkert wrote:

re: comparing floating point numbers

2005-07-25 Thread Chris Wagner
At 04:07 PM 7/24/05 -0400, John Deighan wrote: >Sorry about the lack of sample code, but I know that people who work >with floating point numbers know about this problem, and I was >wondering what the best solution was. Here is sample code with Well ur right, the easy answer is to do the $diff

Re: comparing floating point numbers

2005-07-25 Thread Chris Wagner
At 10:40 PM 7/24/05 -0400, Ted Schuerzinger wrote: >Ken Barker graced perl with these words of wisdom: >> What kind of post is this? >It was an informative help post, made especially informative and helpful >by the fact that the relevant material was included at the relevant point >in the code, a

Re: comparing floating point numbers

2005-07-24 Thread Ted Schuerzinger
Ken Barker graced perl with these words of wisdom: > What kind of post is this? It was an informative help post, made especially informative and helpful by the fact that the relevant material was included at the relevant point in the code, as opposed to being top-posted. > I do not see that an

RE: comparing floating point numbers

2005-07-24 Thread John Serink
Comparing floating points means to ask whether one number falls within a RANGE of values. You have to say it like this: use strict; use warnings; my $bob = 630.239; my $test = 630.24; my $range1 = 0.001; my $range2 = 0.1; no warnings; if( ($test <= ($bob+$range1) ) && ($test => ($bob - $rang

Re: comparing floating point numbers

2005-07-24 Thread Ken Barker
What kind of post is this? I do not see that anything was added at all. Give us all a break - don't bother - whatever your intentions. At 06:35 PM 7/24/2005, $Bill Luebkert wrote: John Deighan wrote: > At 02:20 PM 7/24/2005, Ed Chester wrote: > > >>John Deighan:: >> >>>Is there a safe way t

Re: comparing floating point numbers

2005-07-24 Thread $Bill Luebkert
John Deighan wrote: > At 02:20 PM 7/24/2005, Ed Chester wrote: > > >>John Deighan:: >> >>>Is there a safe way to compare 2 floating point numbers in Perl? [snip] >>>My debugger says that they're both '630.24' [snip] >>>However, the == test fails and the != test succeeds >> >>can you post code wit

Re: comparing floating point numbers

2005-07-24 Thread Sisyphus
- Original Message - From: "John Deighan" > I can only think of taking their difference and checking if > that's less than something like 0.001. Is there a better way? > No. Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@li

RE: comparing floating point numbers

2005-07-24 Thread Darrell Gammill
ad the introduction to chapter 2 of the Perl Cookbook, 2d Ed and recipes 2.2 and 2.3. for idea of how to deal with this. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Deighan Sent: Sunday, July 24, 2005 3:07 PM To: perl-win32-users@listserv.ActiveSta

re: comparing floating point numbers

2005-07-24 Thread Ken Barker
When I substituted 'eq' versus '==' it works. Not sure why though... Ken At 03:07 PM 7/24/2005, John Deighan wrote: At 02:20 PM 7/24/2005, Ed Chester wrote: John Deighan:: > Is there a safe way to compare 2 floating point numbers in Perl? [snip] > My debugger says that they're both '630.24'

re: comparing floating point numbers

2005-07-24 Thread John Deighan
At 02:20 PM 7/24/2005, Ed Chester wrote: John Deighan:: > Is there a safe way to compare 2 floating point numbers in Perl? [snip] > My debugger says that they're both '630.24' [snip] > However, the == test fails and the != test succeeds can you post code with the comparison == that fails ? if t

re: comparing floating point numbers

2005-07-24 Thread Ed Chester
John Deighan:: > Is there a safe way to compare 2 floating point numbers in Perl? [snip] > My debugger says that they're both '630.24' [snip] > However, the == test fails and the != test succeeds can you post code with the comparison == that fails ? if the debugger says they're the same, they're

Re: comparing floating point numbers

2004-11-19 Thread Deane . Rothenmaier
Just the same, ought to do it $x = 50.50; $y = 36.45; if ($x > $y) { print "$x is greater than $y\n" } else         { print "$x is less than or equal to $y\n" } prints out "50.5 is greater than 36.45" on my machine... HTH, Deane "Krishna, Hari" <[EMAIL PROTECTED]> Sent by: [EMAIL PR