This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,10 +1,15 @@
1.0/0.0
# Infinity
-1.0/0.0
# -Infinity
0.0/0.0
# NaN
0.0
# 0.0
-0.0
# -0.0
inf = 1.0 / 0.0 #=> Infinity
nan = 0.0 / 0.0 #=> NaN
expression = [
"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", "nan <=> 0.0", "0.0 == -0.0",
]
expression.each do |exp|
puts "%15s => %p" % [exp, eval(exp)]
end

View file

@ -0,0 +1,15 @@
object ExtremeFloatingPoint extends App {
val negInf = -1.0 / 0.0 //also Double.NegativeInfinity
val inf = 1.0 / 0.0 // //also Double.PositiveInfinity
val nan = 0.0 / 0.0 // //also Double.NaN
val negZero = -2.0 / inf
println("Value: Result: Infinity? Whole?")
println(f"Negative inf: ${negInf}%9s ${negInf.isInfinity}%9s ${negInf.isWhole}%9s")
println(f"Positive inf: ${inf}%9s ${inf.isInfinity}%9s ${inf.isWhole}%9s")
println(f"NaN: ${nan}%9s ${nan.isInfinity}%9s ${nan.isWhole}%9s")
println(f"Negative 0: ${negZero}%9s ${negZero.isInfinity}%9s ${negZero.isWhole}%9s")
println(f"inf + -inf: ${inf + negInf}%9s ${(inf + negInf).isInfinity}%9s ${(inf + negInf).isWhole}%9s")
println(f"0 * NaN: ${0 * nan}%9s ${(inf + negInf).isInfinity}%9s ${(inf + negInf).isWhole}%9s")
println(f"NaN == NaN: ${nan == nan}%9s")
}