File: Test174.ML

package info (click to toggle)
polyml 5.8.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 57,736 kB
  • sloc: cpp: 44,918; ansic: 26,921; asm: 13,495; sh: 4,670; makefile: 610; exp: 525; python: 253; awk: 91
file content (50 lines) | stat: -rw-r--r-- 1,772 bytes parent folder | download
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
(* Tests on Real32.  Currently just rounding from Real. *)

fun check true = () | check false = raise Fail "incorrect";

val p32 = Real32.Math.pi;
val m32 = ~ p32;

val p = Real32.toLarge Real32.Math.pi;
val m = Real32.toLarge m32;

(* Construct values that are slightly more or less than the original. *)
val pp = Real.nextAfter(p, Real.posInf);
check(pp > p);
val pm = Real.nextAfter(p, Real.negInf);
check(pm < p);
val mp = Real.nextAfter(m, Real.posInf);
check(mp > m);
val mm = Real.nextAfter(m, Real.negInf);
check(mm < m);

infix 4 ==;
val op == = Real32.==;

(* Check the rounding of these values. *)
(* To nearest.  These all remove the small difference. *)
check(Real32.fromLarge IEEEReal.TO_NEAREST pp == p32);
check(Real32.fromLarge IEEEReal.TO_NEAREST pm == p32);
check(Real32.fromLarge IEEEReal.TO_NEAREST mp == m32);
check(Real32.fromLarge IEEEReal.TO_NEAREST mm == m32);

(* To zero.  If it's slightly nearer zero it will go to
   the next value. *)
check(Real32.fromLarge IEEEReal.TO_ZERO pp == p32);
check(Real32.fromLarge IEEEReal.TO_ZERO pm < p32);
check(Real32.fromLarge IEEEReal.TO_ZERO mp > m32);
check(Real32.fromLarge IEEEReal.TO_ZERO mm == m32);

(* To positive infinity.  If it's slightly above it will
   go to the next value. *)
check(Real32.fromLarge IEEEReal.TO_POSINF pp > p32);
check(Real32.fromLarge IEEEReal.TO_POSINF pm == p32);
check(Real32.fromLarge IEEEReal.TO_POSINF mp > m32);
check(Real32.fromLarge IEEEReal.TO_POSINF mm == m32);

(* To negative infinity.  If it's slightly below it will
   go to the next value. *)
check(Real32.fromLarge IEEEReal.TO_NEGINF pp == p32);
check(Real32.fromLarge IEEEReal.TO_NEGINF pm < p32);
check(Real32.fromLarge IEEEReal.TO_NEGINF mp == m32);
check(Real32.fromLarge IEEEReal.TO_NEGINF mm < m32);