method
prev_float
v2_4_6 -
Show latest stable
-
0 notes -
Class: Float
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
prev_float()
public
Returns the previous representable floating-point number.
(-Float::MAX).prev_float and (-Float::INFINITY).prev_float is -Float::INFINITY.
Float::NAN.prev_float is Float::NAN.
For example:
p 0.01.prev_float #=> 0.009999999999999998 p 1.0.prev_float #=> 0.9999999999999999 p 100.0.prev_float #=> 99.99999999999999 p 0.01 - 0.01.prev_float #=> 1.734723475976807e-18 p 1.0 - 1.0.prev_float #=> 1.1102230246251565e-16 p 100.0 - 100.0.prev_float #=> 1.4210854715202004e-14 f = 0.01; 20.times { printf "%-20a %s\n", f, f.to_s; f = f.prev_float } #=> 0x1.47ae147ae147bp-7 0.01 # 0x1.47ae147ae147ap-7 0.009999999999999998 # 0x1.47ae147ae1479p-7 0.009999999999999997 # 0x1.47ae147ae1478p-7 0.009999999999999995 # 0x1.47ae147ae1477p-7 0.009999999999999993 # 0x1.47ae147ae1476p-7 0.009999999999999992 # 0x1.47ae147ae1475p-7 0.00999999999999999 # 0x1.47ae147ae1474p-7 0.009999999999999988 # 0x1.47ae147ae1473p-7 0.009999999999999986 # 0x1.47ae147ae1472p-7 0.009999999999999985 # 0x1.47ae147ae1471p-7 0.009999999999999983 # 0x1.47ae147ae147p-7 0.009999999999999981 # 0x1.47ae147ae146fp-7 0.00999999999999998 # 0x1.47ae147ae146ep-7 0.009999999999999978 # 0x1.47ae147ae146dp-7 0.009999999999999976 # 0x1.47ae147ae146cp-7 0.009999999999999974 # 0x1.47ae147ae146bp-7 0.009999999999999972 # 0x1.47ae147ae146ap-7 0.00999999999999997 # 0x1.47ae147ae1469p-7 0.009999999999999969 # 0x1.47ae147ae1468p-7 0.009999999999999967