-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
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
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
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
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
<>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
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
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
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:
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
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
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
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
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
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
- 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
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
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'
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
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
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
21 matches
Mail list logo