Front page | perl.perl5.porters |
Postings from December 2010
integer prevails on returned doubles
Thread Next
From:
Wolfgang Laun
Date:
December 21, 2010 13:10
Subject:
integer prevails on returned doubles
Message ID:
AANLkTinTAMVOreHbffB+=L9URb7YjK5_MqYdWZd8e3G1@mail.gmail.com
Hi Porters,
below is some Perl code taken from a larger program and NOT
reproducing the effect.
The problem is that the returned values appear as truncated to integer
in the calling module,
even when they should not be. The effect disappears if either of the
commented lines is
uncommented (and the other return commented).
It seems that I have a workaround, but I'd really like to know what
causes it. The program is
biggish, but it isn't doing anything special; use Tk is the most
sophisticated thing it does.
And, no, there's no "use integer" anywhere.
I'm not on the p5p list; direct replies are appreciated. If I should
run some code dump or
similar, please advise - I'm rather out of touch with today's Perl ;-).
Wolfgang
(This is perl, v5.10.0 built for i486-linux-gnu-thread-multi)
package Map;
my( $xMax, $yMax, $xMin, $yMin );
$xMax = 100;
$yMax = 200;
( $xMin, $yMin ) = MapGraphEl->pix2grid( $xMin, $yMin )
( $xMax, $yMax ) = MapGraphEl->pix2grid( $xMax, $yMax );
package MapGraphEl;
$MapGraphEl::xGrid = 3.6;
$MapGraphEl::yGrid = 4.8;
sub pix2grid {
my ( $class, $x, $y ) = @_;
my ( $xf, $yf, $xi, $yi );
$xf = $x/$MapGraphEl::xGrid;
$yf = $y/$MapGraphEl::yGrid;
$xi = int( $xf + 0.5 );
$yi = int( $yf + 0.5 );
if( abs( $xf - $xi ) < 0.05 ){ $xf = $xi; }
if( abs( $yf - $yi ) < 0.05 ){ $yf = $yi; }
# print "f: $xf $yf, i: $xi $yi\n";
return ( $xf, $yf );
# return ( $xf*1.0, $yf*1.0 );
}
Thread Next
-
integer prevails on returned doubles
by Wolfgang Laun