real.mlw 1.18 KB
 Sylvain Dailler committed Aug 13, 2019 1 2 3 4 5 ``````module R use real.Real use ref.Ref use real.Square `````` Sylvain committed Aug 22, 2019 6 `````` use real.ExpLog `````` Sylvain Dailler committed Aug 13, 2019 7 8 9 `````` exception BenchFailure `````` MARCHE Claude committed Aug 20, 2019 10 `````` `````` MARCHE Claude committed Aug 20, 2019 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) `````` MARCHE Claude committed Aug 20, 2019 26 `````` `````` Sylvain committed Aug 22, 2019 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 `````` Sylvain Dailler committed Aug 13, 2019 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 committed Aug 20, 2019 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 `````` Sylvain Dailler committed Aug 13, 2019 58 59 60 61 `````` use real.Trigonometry let bench3 () = `````` MARCHE Claude committed Aug 20, 2019 62 `````` (pi, sqrt (pi)) `````` Sylvain Dailler committed Aug 13, 2019 63 `````` `````` MARCHE Claude committed Aug 22, 2019 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) `````` Sylvain Dailler committed Aug 13, 2019 70 ``end``