my $d_1 = 0.1e0; # double 0.1 ( == 3602879701896397/36028797018963968 )
my $r_1 = 0.1; # rational 1/10
my $d_2 = 0.10000000000000001e0;# double, same value as $d_1
my $r_2 = 0.10000000000000001; # rational 10000000000000001/100000000000000000
# check that $d_1 == 3602879701896397/36028797018963968
say "not ok 0" if $d_1 != 3602879701896397/36028797018963968;
# Check that $d_1 == 1 / 10
# This should be true because the RHS will be rounded to 0.1e0
say "not ok 1" if $d_1 != 1 / 10;
# Check that $d_1 and $d_2 are assigned to exactly the same value:
say "not ok 2" if $d_1 != $d_2;
# Check that $r_ and $r_2 are assigned different values:
say "not ok 3" if $r_1 == $r_2;
# Although $r_1 and $r_2 are unequal, $d_1 should be equal to both $r_1 && $r_2.
# This is because both $r_1 and $r_2 round to 0.1e0
# We check this, interchanging LHS and RHS operands in case that makes a
# difference:
say "not ok 4" if ($d_1 != $r_1 && $d_1 != $r_2);
say "not ok 5" if ($r_1 != $d_1 && $r_2 != $d_1);
# Similarly $d_2 should be equal to both $r_1 and $r_2:
say "not ok 6" if ($d_2 != $r_1 && $d_2 != $r_2);
say "not ok 7" if ($r_1 != $d_2 && $r_2 != $d_2);
# The following 9 rationals should all round to 0.1e0.
# They equate to the 56-bit values:
# 0.11001100110011001100110011001100110011001100110011001100E-3
# 0.11001100110011001100110011001100110011001100110011001101E-3
# 0.11001100110011001100110011001100110011001100110011001110E-3
# 0.11001100110011001100110011001100110011001100110011001111E-3
# 0.11001100110011001100110011001100110011001100110011010000E-3
# 0.11001100110011001100110011001100110011001100110011010001E-3
# 0.11001100110011001100110011001100110011001100110011010010E-3
# 0.11001100110011001100110011001100110011001100110011010011E-3
# 0.11001100110011001100110011001100110011001100110011010100E-3
say "not ok 8" if 14411518807585587/144115188075855872 != 0.1e0;
say "not ok 9" if 57646075230342349/576460752303423488 != 0.1e0;
say "not ok 10" if 28823037615171175/288230376151711744 != 0.1e0;
say "not ok 11" if 57646075230342351/576460752303423488 != 0.1e0;
say "not ok 12" if 3602879701896397/36028797018963968 != 0.1e0;
say "not ok 13" if 57646075230342353/576460752303423488 != 0.1e0;
say "not ok 14" if 28823037615171177/288230376151711744 != 0.1e0;
say "not ok 15" if 57646075230342355/576460752303423488 != 0.1e0;
say "not ok 16" if 14411518807585589/144115188075855872 != 0.1e0;
# The following 2 rationals should not round to 0.1e0.
# They equate to the 56-bit values:
# 0.11001100110011001100110011001100110011001100110011001011E-3 (less than 0.1 by 1ULP)
# 0.11001100110011001100110011001100110011001100110011010101E-3 (greater than 0.1 by 1ULP)
say "not ok 17" if 57646075230342347/576460752303423488 == 0.1e0;
say "not ok 18" if 57646075230342357/576460752303423488 == 0.1e0;
# Each of the 11 rationals just provided should be unequal to each other.
# We check this for a few (selected) values of these rationals.
say "not ok 19" if 14411518807585587/144115188075855872 == 57646075230342349/576460752303423488;
say "not ok 20" if 14411518807585587/144115188075855872 == 14411518807585589/144115188075855872;
say "not ok 21" if 14411518807585587/144115188075855872 == 57646075230342347/576460752303423488;
say "not ok 22" if 14411518807585589/144115188075855872 == 57646075230342357/576460752303423488;
####
> say 838861/8388608
0.10000002
####
> say 838861/8388608 == 0.10000002
False
> say 838861/8388608 == 0.10000002e0
False
####
> say 838861/8388608 == 0.10000002384185791e0
True
####
> say 56294995342131/562949953421312
0.0999999999999996
> say 56294995342131/562949953421312 == 0.0999999999999996
False
> say 56294995342131/562949953421312 == 0.0999999999999996e0
False
####
> say 56294995342131/562949953421312 == 0.09999999999999964e0
True