Chautauqua Logo

Ruby class Float interactive

Prompt icon → Click to get an interactive sample (type in code)
(  ) → Optional argument

Methods

Querying

finite?2.0.finite?;(1.0/0.0).finite? # true;false Documentation Interactive samplePlayground
true
infinite?2.0.infinite?;(1.0/0.0).infinite? # nil;1 Documentation Interactive samplePlayground
nil
nan?2.0.nan?;(0.0/0.0).nan? # false;true Documentation Interactive samplePlayground
true
hash2.0.hash # 6345789 (differs) Documentation Interactive samplePlayground

Comparing

<2.0 < 2 # false Documentation Interactive samplePlayground
false
<=2.0 <= 2 # true Documentation Interactive samplePlayground
true
<=>1.0<=>2; 1.0<=>1; 2.0<=>1 # -1;0;1 Documentation Interactive samplePlayground
-1
== (alias === eql?)2.0 == 2 # true Documentation Interactive samplePlayground
true
>2.0 > 2 # false Documentation Interactive samplePlayground
false
>=2.0 >= 2 # true Documentation Interactive samplePlayground
true

Converting

% (alias modulo)11.0 % 3; 11.0.modulo(3) # 2.0 Documentation Interactive samplePlayground
2.0
*2 * 3 # 6.0 Documentation Interactive samplePlayground
6.300000000000001
** (also pow)3.0 ** 2 # 9.0 Documentation Interactive samplePlayground
9.0
+3.0 + 2 # 5.0 Documentation Interactive samplePlayground
5.0
-3.0 - 2 # 1.0 Documentation Interactive samplePlayground
1.0
/8.0 / 2 # 2.0 Documentation Interactive samplePlayground
4.0
round(d)12.36.round(1);-12.36.round(1) # 12,4;-12.4 Documentation Interactive samplePlayground
12.4
ceil(d)12.36.ceil(1);-12.36.ceil(1) # 12.4;12.3 Documentation Interactive samplePlayground
12.4
floor(d)12.36.floor(1);-12.36.floor(1) # 12.3;-12.4 Documentation Interactive samplePlayground
12.3
truncate(d)12.36.truncate(1);-12.36.t…(1) # 12.3;-12.3 Documentation Interactive samplePlayground
12.3
coerce3.14.coerce(2) # [2.0,3.14] Documentation Interactive samplePlayground
[2.0, 3.14]
divmod9.0.divmod(4) # [2,1.0] Documentation Interactive samplePlayground
[2, 1.0]; [-3, -1.0]; [-3, 1.0]
fdiv9.0.fdiv(3);4.0.fdiv(3) # 3;1.33 Documentation Interactive samplePlayground
3.0
next_float1.0.next_float # 1.0000000000000002 Documentation Interactive samplePlayground
1.0000000000000002
prev_float1.0.prev_float # 0.9999999999999999 Documentation Interactive samplePlayground
0.9999999999999999
quo1.0.quo(2) # 0.5 Documentation Interactive samplePlayground
0.5
to_i4.8.to_i; -4.8.to_i # 4;-4 Documentation Interactive samplePlayground
4
to_s (alias inspect)4.8.to_s;-4.8.to_s # "4.8";"-4.8" Documentation Interactive samplePlayground
"4.8"