| 1 | |
| 2 | functor Test(structure Real: REAL |
| 3 | val posZero: Real.real |
| 4 | val posOne: Real.real |
| 5 | val size: Int.int) = |
| 6 | struct |
| 7 | |
| 8 | open Real |
| 9 | |
| 10 | val negZero = ~ posZero |
| 11 | val negOne = ~ posOne |
| 12 | |
| 13 | val nan = posInf + negInf |
| 14 | |
| 15 | val posNan = copySign (nan, posOne) |
| 16 | val negNan = copySign (nan, negOne) |
| 17 | |
| 18 | val _ = print (concat ["Testing Real", Int.toString size, "\n"]) |
| 19 | |
| 20 | fun test (name, r) = |
| 21 | let |
| 22 | val () = |
| 23 | print (concat ["sign(", name, ") = ", |
| 24 | (Int.toString (sign r)) handle Domain => "raise Domain", |
| 25 | "\n"]) |
| 26 | val () = |
| 27 | print (concat ["signBit(", name, ") = ", |
| 28 | Bool.toString (signBit r), "\n"]) |
| 29 | val () = |
| 30 | print (concat ["sign(abs(", name, ")) = ", |
| 31 | (Int.toString (sign (abs r))) handle Domain => "raise Domain", |
| 32 | "\n"]) |
| 33 | val () = |
| 34 | print (concat ["signBit(abs(", name, ")) = ", |
| 35 | Bool.toString (signBit (abs r)), "\n"]) |
| 36 | in |
| 37 | () |
| 38 | end |
| 39 | |
| 40 | val () = |
| 41 | List.app test [("negNan", negNan), |
| 42 | ("negInf", negInf), |
| 43 | ("negOne", negOne), |
| 44 | ("negZero", negZero), |
| 45 | ("posZero", posZero), |
| 46 | ("posOne", posOne), |
| 47 | ("posInf", posInf), |
| 48 | ("posNan", posNan)] |
| 49 | end |
| 50 | |
| 51 | structure Z = Test(structure Real = Real32 |
| 52 | val posZero : Real32.real = 0.0 |
| 53 | val posOne : Real32.real = 1.0 |
| 54 | val size = 32) |
| 55 | val () = print "\n" |
| 56 | structure Z = Test(structure Real = Real64 |
| 57 | val posZero : Real64.real = 0.0 |
| 58 | val posOne : Real64.real = 1.0 |
| 59 | val size = 64) |