D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Float
/
Filename :
next_float-i.ri
back
Copy
U:RDoc::AnyMethod[iI"next_float:ETI"Float#next_float;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"2Returns the next-larger representable \Float.;To:RDoc::Markup::BlankLine o; ; [I"KThese examples show the internally stored values (64-bit hexadecimal) ;TI"Ifor each \Float +f+ and for the corresponding <tt>f.next_float</tt>:;T@o:RDoc::Markup::Verbatim; [ I"'f = 0.0 # 0x0000000000000000 ;TI"'f.next_float # 0x0000000000000001 ;TI" ;TI"'f = 0.01 # 0x3f847ae147ae147b ;TI"'f.next_float # 0x3f847ae147ae147c ;T:@format0o; ; [I"JIn the remaining examples here, the output is shown in the usual way ;TI"(result +to_s+):;T@o;; [I"20.01.next_float # => 0.010000000000000002 ;TI"01.0.next_float # => 1.0000000000000002 ;TI"0100.0.next_float # => 100.00000000000001 ;TI" ;TI"f = 0.01 ;TI"[(0..3).each_with_index {|i| printf "%2d %-20a %s\n", i, f, f.to_s; f = f.next_float } ;T; 0o; ; [I"Output:;T@o;; [I"" 0 0x1.47ae147ae147bp-7 0.01 ;TI"2 1 0x1.47ae147ae147cp-7 0.010000000000000002 ;TI"2 2 0x1.47ae147ae147dp-7 0.010000000000000004 ;TI"2 3 0x1.47ae147ae147ep-7 0.010000000000000005 ;TI" ;TI"%f = 0.0; 100.times { f += 0.1 } ;TI"bf # => 9.99999999999998 # should be 10.0 in the ideal world. ;TI"Y10-f # => 1.9539925233402755e-14 # the floating point error. ;TI"_10.0.next_float-10 # => 1.7763568394002505e-15 # 1 ulp (unit in the last place). ;TI"T(10-f)/(10.0.next_float-10) # => 11.0 # the error is 11 ulp. ;TI"[(10-f)/(10*Float::EPSILON) # => 8.8 # approximation of the above. ;TI"1"%a" % 10 # => "0x1.4p+3" ;TI"j"%a" % f # => "0x1.3fffffffffff5p+3" # the last hex digit is 5. 16 - 5 = 11 ulp. ;T; 0o; ; [I"Related: Float#prev_float;T: @fileI"numeric.c;T:0@omit_headings_from_table_of_contents_below0I"next_float -> float ;T0[ I"();T@;FI" Float;TcRDoc::NormalClass00