Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

exeunt (319)


My perlmonks Personal Node []

Journal of exeunt (319)

Tuesday March 11, 2003
02:07 PM

Divide bug?

[ #10993 ]

I just sent this post to perl5-porters. This had me pulling my hair out as to what is causing it.

Below is a copy of the email I sent...

A co-worker of mine came across something strange that had me pulling my hair
out. Below is an example of the bug in action. Logically you would think that if
you divide 72.9 by 100, you get 0.729, so it should match the if statement. At
first we thought it was because we had 0.729000 as the condition, but that
doesn't matter. Also in the below code I have it test against 0.729 and 0.729000
without it resulting from a divide, and it passes.

I tested this against 5.005_03, 5.6.0, 5.6.1 and 5.8.0, all exhibit this

use warnings;
use strict;

my $test = 72.9;
my $divtest = $test/100;
my $condition = 0.729;
my $hardcode = 0.729000;
print "divtest => $divtest\ncondition => $condition\n";
if ($divtest == $condition) {
    print "Should be true\n";
elsif ($divtest == $hardcode) {
    print "This also should be true\n";
else {
    print "What the?!!?\n";
if ($condition == $hardcode) {
    print "Without divide it works\n";

UPDATE: Mark Jason Dominus set me straight, but as I just wrote back, I figured since their NV's are both 0.729 in the output from Devel:Peel, it would work... guess not, someone else replied directly to me and suggested using 'eq', but using that for numerical comparisons makes me feel a bit ill.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.