in reply to Re^2: IF condition with a range
in thread IF condition with a range

Is this with or without the use of integer?


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: IF condition with a range
by Tux (Canon) on Jul 16, 2018 at 16:07 UTC

    with:

    $ cat test.pl use 5.18.2; use warnings; use integer; my $x = 2; my $y = 2.00000000000000123; say qq{$x $y}; if ($x == $y or $x == $y-1 or $x == $y+1) { say "in exact range"; } if ($y-1 <= $x && $x <= $y+1) { say "in <= range"; } if (abs ($y-$x) <= 1) { say "in abs range"; } $ perl -v | grep 5.2 This is perl 5, version 24, subversion 1 (v5.24.1) built for x86_64-li +nux-thread-multi-ld $ perl test.pl 2 2.00000000000000123 in exact range in <= range in abs range

    Same on 5.28.0

    2.0000000000000000123 (two more zeroes), yields

    2 2.00000000000000001 in exact range in <= range in abs range

    Enjoy, Have FUN! H.Merijn