FAQ
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 );
}

Search Discussions

  • Zefram at Dec 21, 2010 at 9:18 pm

    Wolfgang Laun wrote:
    below is some Perl code taken from a larger program and NOT
    reproducing the effect.
    If you want advice on a problem of this nature, you'll really have to
    show us some code that demonstrates your problem. The code you've posted
    contains a syntax error (missing semicolon), and also calls pix2grid
    before the $xGrid and $yGrid constants that it relies on are set up.
    Even with those fixed, as you say, it doesn't show any problem of the
    nature that you describe.

    -zefram
  • Wolfgang Laun at Dec 21, 2010 at 9:38 pm
    Agreed, and sorry for the sloppy posting. But I wrote that the code
    does NOT reproduce the problem. What can I do to narrow it down?
    I can provide the full program.
    -W
    On 21 December 2010 22:18, Zefram wrote:
    Wolfgang Laun wrote:
    below is some Perl code taken from a larger program and NOT
    reproducing the effect.
    If you want advice on a problem of this nature, you'll really have to
    show us some code that demonstrates your problem.  The code you've posted
    contains a syntax error (missing semicolon), and also calls pix2grid
    before the $xGrid and $yGrid constants that it relies on are set up.
    Even with those fixed, as you say, it doesn't show any problem of the
    nature that you describe.

    -zefram
  • Zefram at Dec 21, 2010 at 10:06 pm

    Wolfgang Laun wrote:
    Agreed, and sorry for the sloppy posting. But I wrote that the code
    does NOT reproduce the problem. What can I do to narrow it down?
    I can provide the full program.
    The usual approach is to start with the full program and progressively
    remove parts of it, watching for the problem to disappear. Keep in
    only those parts that are necessary in order to demonstrate the problem.
    You will eventually have either discovered your bug or produced a minimal
    test case which you can post.

    -zefram

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedDec 21, '10 at 9:56a
activeDec 21, '10 at 10:06p
posts4
users2
websiteperl.org

2 users in discussion

Wolfgang Laun: 2 posts Zefram: 2 posts

People

Translate

site design / logo © 2022 Grokbase