A float value is finite if it has an end or it is measurable. It is not finite if it is infinity, negative infinity (-infinity
) or Not a Number (NaN
). To determine whether a float value is finite or not, we use the finite?
attribute.
flt.finite?
The value returned is a Boolean value. true
is returned if the float value is finite. If it isn’t, false
is returned.
# create float valuesf1 = 4.8f2 = 3.0/ 0.0 # infinityf3 = -2.33/0.0 # -infinityf4 = 499.11111# check if finiteputs f1.finite?puts f2.finite?puts f3.finite?puts f4.finite?
finite?
to check if the values are finite, and print the results to the console.