# Behaviour of ruby with regards to numerical exactness (Scheme comparison)

In Ruby (1.9), are numbers always considered exact? I know Ruby does some fairly complex stuff with numbers under the hood, since you can do crazy things like ask for 1 trillion to the power of 1 trillion and you will get an answer (after waiting many moons for it to compute).

In Scheme, part of the specification dictates that implementations should indicate whether or not the implementation's internal representation of the number is "exact" or not. For example, 1/2 is always exact, 1/3 is exact, 0.3333 is exact etc etc. But the result of an imprecise mathematical operation on an exact number may produce a number that the Scheme implementation knows to be inexact (due to floating point precision).

(exact? (/ 0.33333 2))
=> #f

That's false, so it's not exact.

Is there a way to deduce the same information in Ruby? If I always use the Complex (or Rational) representation of a number during mathematical operations, will it always be exact in Ruby, or just extremely close to exact?

Complex("0.33333") / 2

Is that exact, or not?

Ruby's class Float is not exact. Class Integer on the other hand more or less "is" since it shifts seamlessly from Fixnum to Bignum

>> 1.4534346345235236346363574564356435
=> 1.45343463452352
>> 10**400
=> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> 10.0**400
=> Infinity

It looks like others would love to see the test you are asking about, namely Numeric#exact? -- see this feature request.