S
suedecold
I should have left it alone but I decided to clean up
a script and replace a number of calls to "int()" in a
subroutine with "use integer".
I do not understand why I am getting different
results with the following code...
-------------------- begin script --------------------
use strict;
&method_a(730791);
&method_b(730791);
exit;
sub method_a {
my($g) = @_;
my $y;
$y = int((10000*$g + 14780)/3652425);
printf STDOUT "Method A = %d\n", $y;
}
sub method_b {
use integer;
my($g) = @_;
my $y;
$y = (10000*$g + 14780)/3652425;
printf STDOUT "Method B = %d\n", $y;
}
-------------------- end script --------------------
When I run it I get the following on my Win2K box:
C:\Perl\bin>buggy.pl
Method A = 2000
Method B = -351
I thought I understood "use integer" but maybe I
don't. Would someone care to explain the reason for the
different results? perl -v produces:
This is perl, v5.8.3 built for MSWin32-x86-multi-thread
(with 8 registered patches, see perl -V for more detail)
Copyright 1987-2003, Larry Wall
Binary build 809 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Feb 3 2004 00:28:51
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
TIA,
JAPH wannabe
a script and replace a number of calls to "int()" in a
subroutine with "use integer".
I do not understand why I am getting different
results with the following code...
-------------------- begin script --------------------
use strict;
&method_a(730791);
&method_b(730791);
exit;
sub method_a {
my($g) = @_;
my $y;
$y = int((10000*$g + 14780)/3652425);
printf STDOUT "Method A = %d\n", $y;
}
sub method_b {
use integer;
my($g) = @_;
my $y;
$y = (10000*$g + 14780)/3652425;
printf STDOUT "Method B = %d\n", $y;
}
-------------------- end script --------------------
When I run it I get the following on my Win2K box:
C:\Perl\bin>buggy.pl
Method A = 2000
Method B = -351
I thought I understood "use integer" but maybe I
don't. Would someone care to explain the reason for the
different results? perl -v produces:
This is perl, v5.8.3 built for MSWin32-x86-multi-thread
(with 8 registered patches, see perl -V for more detail)
Copyright 1987-2003, Larry Wall
Binary build 809 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Feb 3 2004 00:28:51
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
TIA,
JAPH wannabe