-
Notifications
You must be signed in to change notification settings - Fork 70
/
big-float.lisp
101 lines (87 loc) · 3.21 KB
/
big-float.lisp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;;; big-float.lisp
;;;;
;;;; Benchmarks for arbitrary precision floats
(cl:in-package #:coalton-benchmarks)
(cl:defvar *big-float-bench-precision*
#-coalton-portable-bigfloat 10000
#+coalton-portable-bigfloat 100)
(cl:defvar *big-float-bench-iterations*
#-coalton-portable-bigfloat 1000
#+coalton-portable-bigfloat 10)
(define-benchmark big-trig ()
"Benchmark at N precision big-float trigonometric functions."
(declare (optimize speed))
(loop :repeat *big-float-bench-iterations*
:do (with-benchmark-sampling
(coalton-benchmarks/native::big-trig
*big-float-bench-precision*
(* (- (random 2)) (random 100.0d0)))))
(report trivial-benchmark::*current-timer*))
(define-benchmark big-inv-trig ()
"Benchmark at N precision big-float inverse trigonometric functions."
(declare (optimize speed))
(loop :repeat *big-float-bench-iterations*
:do (with-benchmark-sampling
(coalton-benchmarks/native::big-inv-trig
*big-float-bench-precision*
(* (- (random 2)) (random 1.0d0)))))
(report trivial-benchmark::*current-timer*))
(define-benchmark big-ln-exp ()
"Benchmark at N precision big-float ln and exp."
(declare (optimize speed))
(loop :repeat *big-float-bench-iterations*
:do (with-benchmark-sampling
(coalton-benchmarks/native::big-ln-exp
*big-float-bench-precision*
(* (- (random 2)) (random 100.0d0)))))
(report trivial-benchmark::*current-timer*))
(define-benchmark big-sqrt ()
"Benchmark at N precision big-float square roots."
(declare (optimize speed))
(loop :repeat *big-float-bench-iterations*
:do (with-benchmark-sampling
(coalton-benchmarks/native::big-sqrt
*big-float-bench-precision*
(random 100.0d0))))
(report trivial-benchmark::*current-timer*))
(define-benchmark big-mult-constants ()
"Benchmark at N precision big-float multiplication of pi and euler's number."
(declare (optimize speed))
(loop :repeat *big-float-bench-iterations*
:do (with-benchmark-sampling
(coalton-benchmarks/native::big-sqrt
*big-float-bench-precision*
(* (- (random 2)) (random 100.0d0)))))
(report trivial-benchmark::*current-timer*))
(cl:in-package #:coalton-benchmarks/native)
(cl:declaim (cl:optimize (cl:speed 3) (cl:safety 1)))
(coalton-toplevel
(declare big-trig (UFix -> Double-Float -> Big-Float))
(define (big-trig n x)
(with-precision n
(fn ()
(let x = (into x))
(tan (sin (cos x))))))
(declare big-inv-trig (UFix -> Double-Float -> Big-Float))
(define (big-inv-trig n x)
(with-precision n
(fn ()
(let x = (into x))
(atan (+ (asin x) (acos x))))))
(declare big-ln-exp (UFix -> Double-Float -> Big-Float))
(define (big-ln-exp n x)
(with-precision n
(fn ()
(let x = (into x))
(ln (exp x)))))
(declare big-sqrt (UFix -> Double-Float -> Big-Float))
(define (big-sqrt n x)
(with-precision n
(fn ()
(let x = (into x))
(sqrt x))))
(define (big-mult-constants n x)
(with-precision n
(fn ()
(let x = (into x))
(* x (* pi ee))))))