File: blame_eye_triple_eee-float.scala

package info (click to toggle)
scala 2.11.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,828 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,250; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (61 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
object Test extends App {
  import Float.NaN

  // NaN must not equal NaN no matter what optimizations are applied
  // All the following will seem redundant, but to an optimizer
  // they can appear different

  val x = NaN

  if (NaN == NaN)
    println("if (NaN == NaN) is broken")
  else
    println("if (NaN == NaN) is good")

  if (x == x)
    println("if (x == x) is broken")
  else
    println("if (x == x) is good")

  if (x == NaN)
    println("if (x == NaN) is broken")
  else
    println("if (x == NaN) is good")

  if (NaN != NaN)
    println("if (NaN != NaN) is good")
  else
    println("if (NaN != NaN) broken")

  if (x != x)
    println("if (x != x) is good")
  else
    println("if (x != x) broken")

  if (NaN != x)
    println("if (NaN != x) is good")
  else
    println("if (NaN != x) is broken")

  x match {
    case 0.0f => println("x matched 0!")
    case NaN => println("x matched NaN!")
    case _ => println("x matching was good")
  }

  NaN match {
    case 0.0f => println("NaN matched 0!")
    case NaN => println("NaN matched NaN!")
    case _ => println("NaN matching was good")
  }

  var z = 0.0f
  var i = 0
  while (i < 10) {
    if (i % 2 == 0) z = NaN
    else z = NaN
    i += 1
  }
  if (z.isNaN && i == 10) println("loop with NaN was good")
  else println("loop with NaN was broken")
}