Thursday, February 4, 2010

[Ruby] Difference between NaN and Infinity

I am not sure if this is limited to ruby,
but came across a sweet data type that ruby
maintains when some sort of "wrong" operation
is encountered.

Infinity: Is the typical value, when a number
is divided by zero or a very small number (close
to zero).

NaN: Not a number is Ruby's way of saying that
zero was divided by a zero ==> resulting
in an undefined result which is indicated
by the NaN. Unfortunately, I am not sure if
Ruby has support for testing if a variable has
NaN value.

0 comments:

Post a Comment