#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Extreme_floating_point_values
#

var inf = (1 / 0)    #=> Inf
var nan = (0 / 0)    #=> NaN

var exprs = [
  "1.0 / 0.0", "-1.0 / 0.0", "0.0 / 0.0", "- 0.0",
  "inf + 1", "5 - inf", "inf * 5", "inf / 5", "inf * 0",
  "1.0 / inf", "-1.0 / inf", "inf + inf", "inf - inf",
  "inf * inf", "inf / inf", "inf * 0.0", " 0 < inf", "inf == inf",
  "nan + 1", "nan * 5", "nan - nan", "nan * inf", "- nan",
  "nan == nan", "nan > 0", "nan < 0", "nan == 0", "0.0 == -0.0",
]

exprs.each { |expr|
  "%15s => %s\n".printf(expr, eval(expr))
}

say "-"*40
say("NaN equality: ",        NaN ==  nan)   #=> true
say("Infinity equality: ",   Inf ==  inf)   #=> true
say("-Infinity equality: ", -Inf == -inf)   #=> true

say "-"*40
say("sqrt(-1)   = ",   sqrt(-1));     #=> i
say("tanh(-Inf) = ", tanh(-inf));     #=> -1
say("(-Inf)**2  = ",  (-inf)**2);     #=> Inf
say("(-Inf)**3  = ",  (-inf)**3);     #=> -Inf
say("acos(Inf)  = ",  acos(inf));     #=> Inf*i
say("atan(Inf)  = ",  atan(inf));     #=> pi/2
say("log(-1)    = ",    log(-1));     #=> pi*i
say("atanh(Inf) = ", atanh(inf));     #=> -pi/2*i
