Issue2218.agda 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. open import Agda.Builtin.Float
  2. open import Agda.Builtin.Unit
  3. open import Agda.Builtin.Reflection
  4. open import Agda.Builtin.String
  5. open import Agda.Builtin.Bool
  6. open import Common.IO
  7. data It (a : Float) : Set where
  8. it : It a
  9. Inf : Float
  10. Inf = primFloatDiv 1.0 0.0
  11. -Inf : Float
  12. -Inf = primFloatNegate Inf
  13. NaN : Float
  14. NaN = primFloatDiv 0.0 0.0
  15. -NaN : Float
  16. -NaN = primFloatNegate NaN
  17. _==_ = primFloatEquality
  18. macro
  19. literal : Float → Term → TC ⊤
  20. literal x hole = unify hole (lit (float x))
  21. nl = putStrLn ""
  22. header = putStrLn " Inf -Inf NaN -NaN | x"
  23. tick : Bool → String
  24. tick true = " x "
  25. tick false = " - "
  26. check : Float → IO _
  27. check x = putStr (tick (x == Inf)) ,,
  28. putStr (tick (x == -Inf)) ,,
  29. putStr (tick (x == NaN)) ,,
  30. putStr (tick (x == -NaN)) ,,
  31. putStr "| " ,, printFloat x ,,
  32. nl
  33. main : IO _
  34. main =
  35. header ,,
  36. check (literal Inf) ,,
  37. check (literal -Inf) ,,
  38. check (literal NaN) ,,
  39. check (literal -NaN)