Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
;; Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
2
;; All rights reserved.
3
;; Copyright (C) 2007-2012, Gabriel Dos Reis.
4
;; All rights reserved.
5
;;
6
;; Redistribution and use in source and binary forms, with or without
7
;; modification, are permitted provided that the following conditions are
8
;; met:
9
;;
10
;; - Redistributions of source code must retain the above copyright
11
;; notice, this list of conditions and the following disclaimer.
12
;;
13
;; - Redistributions in binary form must reproduce the above copyright
14
;; notice, this list of conditions and the following disclaimer in
15
;; the documentation and/or other materials provided with the
16
;; distribution.
17
;;
18
;; - Neither the name of The Numerical Algorithms Group Ltd. nor the
19
;; names of its contributors may be used to endorse or promote products
20
;; derived from this software without specific prior written permission.
21
;;
22
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23
;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24
;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25
;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26
;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35
(defpackage "BOOT"
36
#+:common-lisp (:use "COMMON-LISP")
37
#-:common-lisp (:use "LISP")
38
#+:SBCL (:use "SB-ALIEN")
39
(:use "AxiomCore" "BOOTTRAN"))
40
41
(in-package "BOOT")
42
43
(eval-when (:compile-toplevel :load-toplevel :execute)
44
(progn
45
(setq *read-default-float-format* 'double-float)
46
(setq *load-verbose* nil)))
47
48
(eval-when
49
#+:common-lisp (:compile-toplevel :load-toplevel :execute)
50
#-:common-lisp (compile load eval)
51
(defun define-function (f v)
52
(setf (symbol-function f) v)))
53
54
(defun |gensym?| (s)
55
(and (symbolp s) (null (symbol-package s))))
56
57
(defmacro |complex?| (x)
58
`(complexp ,x))
59
60
(defmacro |complex| (x (&optional (y 0.0)))
61
`(complex ,x ,y))
62
63
(defmacro |realPart| (z)
64
`(realpart ,z))
65
66
(defmacro |imagPart| (z)
67
`(imagpart ,z))
68
69
(defmacro |conjugate| (z)
70
`(conjugate ,z))
71
72
(defmacro |sqrt| (x)
73
`(sqrt ,x))
74
75
;; Below are some missing functions. There here for lack of better
76
;; place (sys-funs.lisp?)
77
;;
78
;; These functions should be defined for DoubleFloat inputs but are not.
79
;; These are cheap and easy definitions that work but should be rewritten.
80
81
;; Contributed by Juergen Weiss from a suggestion by Arthur Norman.
82
83
(defun cot (a)
84
(if (or (> a 1000.0) (< a -1000.0))
85
(/ (cos a) (sin a))
86
(/ 1.0 (tan a))))
87
88
(defun acot (a)
89
(if (> a 0.0)
90
(if (> a 1.0)
91
(atan (/ 1.0 a))
92
(- (/ pi 2.0) (atan a)))
93
(if (< a -1.0)
94
(- pi (atan (/ -1.0 a)))
95
(+ (/ pi 2.0) (atan (- a))))))
96
97
; This is a Mantissa and Exponent function.
98
(defun manexp (u)
99
(multiple-value-bind (f e s)
100
(decode-float u)
101
(cons (* s f) e)))
102
103
;; Format a DoubleFloat value in a reasonable way. Similar code
104
;; has been submitted for inclusion in SBCL. If and when
105
;; that version is integrated, we should remove it from here.
106
#- :sbcl
107
(defun dfloat-format-general (number)
108
(format nil "~G" number))
109
#+ :sbcl
110
(defun dfloat-format-general (number)
111
(declare (type double-float number))
112
(cond
113
((zerop number) "0.")
114
(t
115
(with-output-to-string (stream)
116
(if (or (sb-ext:float-infinity-p number)
117
(sb-ext:float-nan-p number))
118
(prin1 number stream)
119
(flet ((dfloat-format-fixed (stream number d)
120
(declare (type double-float number))
121
(multiple-value-bind (str len lpoint tpoint)
122
(sb-impl::flonum-to-string number nil d)
123
(declare (ignore len))
124
;;if caller specifically requested no fraction digits,
125
;;suppress the optional trailing zero
126
(when (and d (zerop d))
127
(setq tpoint nil))
128
(when lpoint
129
(write-char #\0 stream))
130
(write-string str stream)
131
nil))
132
(dfloat-format-exp (stream number)
133
(declare (type double-float number))
134
(multiple-value-bind (num expt)
135
(sb-impl::scale-exponent number)
136
(let* ((expt (1- expt))
137
(estr (sb-format::decimal-string (abs expt))))
138
(multiple-value-bind (fstr flen lpoint tpoint)
139
(sb-impl::flonum-to-string num nil nil 1)
140
(declare (ignore tpoint))
141
(when lpoint (write-char #\0 stream))
142
(write-string fstr stream)
143
(when (char= (aref fstr (1- flen)) #\.)
144
(write-char #\0 stream))
145
(write-char #\E stream)
146
(write-char (if (minusp expt) #\- #\+) stream)
147
(write-string estr stream))
148
nil))))
149
(when (minusp number)
150
(setq number (- number))
151
(write-char #\- stream))
152
(multiple-value-bind (ignore n) (sb-impl::scale-exponent number)
153
(declare (ignore ignore))
154
(let* ((q (length
155
(nth-value 1 (sb-impl::flonum-to-digits number))))
156
(d (max q (min n 7)))
157
(dd (- d n)))
158
(if (<= 0 dd d)
159
(dfloat-format-fixed stream number dd)
160
(dfloat-format-exp stream number))))))))))
161
162
163