real.mlw 1.18 KB
Newer Older
1 2 3 4 5
module R

  use real.Real
  use ref.Ref
  use real.Square
6
  use real.ExpLog
7 8 9

  exception BenchFailure

10

MARCHE Claude's avatar
MARCHE Claude committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  let test0 () =
     let x:real = 42.0 in
     let y:real = 1.5 in
     let z:real = 0.1 in
     (x,y,z)

  let test1 () =
    let x : real = 0.1 in
    let y : real = 10.0 * x in
    (x, y)

  let test2 () =
    let x : real = 3.0 in
    let y : real = 1.0 / x in
    (x, y, 3.0 * y)
26

27 28 29 30 31 32 33 34 35 36 37 38
  let test_exp () =
    let x: real = 1.0 in
    exp x

  let test_log () =
    let x: real = 1.0 in
    log x

  let test_exp_log () =
    let x: real = 42.0 in
    exp (log x), log x, exp x

39 40 41 42 43 44 45 46 47 48 49 50 51
  let bench1 ()
    (* Tries to calculate sqrt(2) *)
    diverges
    raises { BenchFailure -> false }
    ensures { result = 10.0 } =
    let incr = 0.002 (*(1.0 / 10000.0)*) in
    let i : ref real = ref 0.0 in
    while (!i * !i <= 2.0) do
      i := !i + incr;
    done;
    !i

  let bench2 ()
MARCHE Claude's avatar
MARCHE Claude committed
52 53 54 55 56 57
    raises { BenchFailure -> false }
    ensures { result = 4.0 }
  =
    let r = sqrt 16.0 in
    if r <> 4.0 then raise BenchFailure;
    r
58 59 60 61

  use real.Trigonometry

  let bench3 () =
62
    (pi, sqrt (pi))
63

MARCHE Claude's avatar
MARCHE Claude committed
64 65 66 67 68 69
  let test3 () =
    let ref x = 2.0 in
    for i=1 to 14 do x <- x * x done;
    let y = 0.0 * x in
    (x,y)

70
end