in reply to Re: Re: .999999... == 1? (Somewhat OT)
in thread .999999... == 1? (Somewhat OT)
You'll notice that these two numbers are indeed unequal. You're probably thinking big deal, obviously, $num1 doesn't repeat forever so they shouldn't be equal. Try the script again, but add a single 9 to the end of $num1. You should find the results more interesting. (I'm by no means a Perl guru and am not sure if this will work the same from one Perl installation to another. I am using Perl 5.6.1 on a Win32 platform.) In that case, the two values, even though $num1 still does not repeat forever, are considered equal.#!/usr/bin/perl -w use strict; my $num1 = .9999999999999999; my $num2 = 1; print "num1 = $num1\n"; print "num2 = $num2\n"; print "The numbers are equal" if $num2 == $num1; print "The numbers are not equal" if $num2 != $num1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: .999999... == 1? (Somewhat OT)
by cforde (Monk) on Jul 25, 2001 at 10:00 UTC | |
|
Re: Re: Re: Re: .999999... == 1? (Somewhat OT)
by John M. Dlugosz (Monsignor) on Jul 25, 2001 at 19:40 UTC |