in reply to Re: IF condition with a range (updated)
in thread IF condition with a range

There are longdoubles and quadmath. With my perl (built with -Duselongdouble) I get:

2 2.00000000000000123 in exact range in <= range in abs range

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: IF condition with a range
by AnomalousMonk (Archbishop) on Jul 16, 2018 at 15:52 UTC

    Is this with or without the use of integer?


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

      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