next_float -> Float
[permalink][rdoc]浮動小数点数で表現可能な self の次の値を返します。
Float::MAX.next_float、Float::INFINITY.next_float は Float::INFINITY を返します。Float::NAN.next_float は Float::NAN を返します。
p 0.01.next_float # => 0.010000000000000002
p 1.0.next_float # => 1.0000000000000002
p 100.0.next_float # => 100.00000000000001
p 0.01.next_float - 0.01 # => 1.734723475976807e-18
p 1.0.next_float - 1.0 # => 2.220446049250313e-16
p 100.0.next_float - 100.0 # => 1.4210854715202004e-14
f = 0.01; 20.times { printf "%-20a %s\n", f, f.to_s; f = f.next_float }
# => 0x1.47ae147ae147bp-7 0.01
# 0x1.47ae147ae147cp-7 0.010000000000000002
# 0x1.47ae147ae147dp-7 0.010000000000000004
# 0x1.47ae147ae147ep-7 0.010000000000000005
# 0x1.47ae147ae147fp-7 0.010000000000000007
# 0x1.47ae147ae148p-7 0.010000000000000009
# 0x1.47ae147ae1481p-7 0.01000000000000001
# 0x1.47ae147ae1482p-7 0.010000000000000012
# 0x1.47ae147ae1483p-7 0.010000000000000014
# 0x1.47ae147ae1484p-7 0.010000000000000016
# 0x1.47ae147ae1485p-7 0.010000000000000018
# 0x1.47ae147ae1486p-7 0.01000000000000002
# 0x1.47ae147ae1487p-7 0.010000000000000021
# 0x1.47ae147ae1488p-7 0.010000000000000023
# 0x1.47ae147ae1489p-7 0.010000000000000024
# 0x1.47ae147ae148ap-7 0.010000000000000026
# 0x1.47ae147ae148bp-7 0.010000000000000028
# 0x1.47ae147ae148cp-7 0.01000000000000003
# 0x1.47ae147ae148dp-7 0.010000000000000031
# 0x1.47ae147ae148ep-7 0.010000000000000033
[SEE_ALSO] Float#prev_float