File: Test110.ML

package info (click to toggle)
polyml 5.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 40,616 kB
  • sloc: cpp: 44,142; ansic: 26,963; sh: 22,002; asm: 13,486; makefile: 602; exp: 525; python: 253; awk: 91
file content (38 lines) | stat: -rw-r--r-- 923 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
(* Check integer conversion. *)

fun verifyBase radix n =
    valOf(StringCvt.scanString (LargeInt.scan radix)(LargeInt.fmt radix n)) = n

fun verify n =
    if verifyBase StringCvt.DEC n andalso verifyBase StringCvt.HEX n andalso
       verifyBase StringCvt.OCT n andalso verifyBase StringCvt.BIN n
    then () else raise Fail "failed";

(* Random number generator.  From Isabelle. *)

local
    fun rmod x y = x - y * Real.realFloor (x / y);
    val a = 16807.0;
    val m = 2147483647.0;
    val random_seed = ref 1.0;
in

    fun random () =
    let
        val r = rmod (a * ! random_seed) m
    in
        random_seed := r;
        Real.toLargeInt IEEEReal.TO_NEGINF r
    end
end;

fun doFor f 0 = () | doFor f n = (f(); doFor f (n-1));

verify 0;
verify 1;
verify ~1;
verify 100000000000000000000000;
verify 100000000000000000000001;
verify 9051234567;

doFor(fn () => (verify(random()); verify(~(random())))) 100;