open-axiom repository from github
;; Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.1;; All rights reserved.2;; Copyright (C) 2007-2012, Gabriel Dos Reis.3;; All rights reserved.4;;5;; Redistribution and use in source and binary forms, with or without6;; modification, are permitted provided that the following conditions are7;; met:8;;9;; - Redistributions of source code must retain the above copyright10;; notice, this list of conditions and the following disclaimer.11;;12;; - Redistributions in binary form must reproduce the above copyright13;; notice, this list of conditions and the following disclaimer in14;; the documentation and/or other materials provided with the15;; distribution.16;;17;; - Neither the name of The Numerical Algorithms Group Ltd. nor the18;; names of its contributors may be used to endorse or promote products19;; derived from this software without specific prior written permission.20;;21;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER25;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,26;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,27;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.323334(defpackage "BOOT"35#+:common-lisp (:use "COMMON-LISP")36#-:common-lisp (:use "LISP")37#+:SBCL (:use "SB-ALIEN")38(:use "AxiomCore" "BOOTTRAN"))3940(in-package "BOOT")4142(eval-when (:compile-toplevel :load-toplevel :execute)43(progn44(setq *read-default-float-format* 'double-float)45(setq *load-verbose* nil)))4647(eval-when48#+:common-lisp (:compile-toplevel :load-toplevel :execute)49#-:common-lisp (compile load eval)50(defun define-function (f v)51(setf (symbol-function f) v)))5253(defun |gensym?| (s)54(and (symbolp s) (null (symbol-package s))))5556(defmacro |complex?| (x)57`(complexp ,x))5859(defmacro |complex| (x (&optional (y 0.0)))60`(complex ,x ,y))6162(defmacro |realPart| (z)63`(realpart ,z))6465(defmacro |imagPart| (z)66`(imagpart ,z))6768(defmacro |conjugate| (z)69`(conjugate ,z))7071(defmacro |sqrt| (x)72`(sqrt ,x))7374;; Below are some missing functions. There here for lack of better75;; place (sys-funs.lisp?)76;;77;; These functions should be defined for DoubleFloat inputs but are not.78;; These are cheap and easy definitions that work but should be rewritten.7980;; Contributed by Juergen Weiss from a suggestion by Arthur Norman.8182(defun cot (a)83(if (or (> a 1000.0) (< a -1000.0))84(/ (cos a) (sin a))85(/ 1.0 (tan a))))8687(defun acot (a)88(if (> a 0.0)89(if (> a 1.0)90(atan (/ 1.0 a))91(- (/ pi 2.0) (atan a)))92(if (< a -1.0)93(- pi (atan (/ -1.0 a)))94(+ (/ pi 2.0) (atan (- a))))))9596; This is a Mantissa and Exponent function.97(defun manexp (u)98(multiple-value-bind (f e s)99(decode-float u)100(cons (* s f) e)))101102;; Format a DoubleFloat value in a reasonable way. Similar code103;; has been submitted for inclusion in SBCL. If and when104;; that version is integrated, we should remove it from here.105#- :sbcl106(defun dfloat-format-general (number)107(format nil "~G" number))108#+ :sbcl109(defun dfloat-format-general (number)110(declare (type double-float number))111(cond112((zerop number) "0.")113(t114(with-output-to-string (stream)115(if (or (sb-ext:float-infinity-p number)116(sb-ext:float-nan-p number))117(prin1 number stream)118(flet ((dfloat-format-fixed (stream number d)119(declare (type double-float number))120(multiple-value-bind (str len lpoint tpoint)121(sb-impl::flonum-to-string number nil d)122(declare (ignore len))123;;if caller specifically requested no fraction digits,124;;suppress the optional trailing zero125(when (and d (zerop d))126(setq tpoint nil))127(when lpoint128(write-char #\0 stream))129(write-string str stream)130nil))131(dfloat-format-exp (stream number)132(declare (type double-float number))133(multiple-value-bind (num expt)134(sb-impl::scale-exponent number)135(let* ((expt (1- expt))136(estr (sb-format::decimal-string (abs expt))))137(multiple-value-bind (fstr flen lpoint tpoint)138(sb-impl::flonum-to-string num nil nil 1)139(declare (ignore tpoint))140(when lpoint (write-char #\0 stream))141(write-string fstr stream)142(when (char= (aref fstr (1- flen)) #\.)143(write-char #\0 stream))144(write-char #\E stream)145(write-char (if (minusp expt) #\- #\+) stream)146(write-string estr stream))147nil))))148(when (minusp number)149(setq number (- number))150(write-char #\- stream))151(multiple-value-bind (ignore n) (sb-impl::scale-exponent number)152(declare (ignore ignore))153(let* ((q (length154(nth-value 1 (sb-impl::flonum-to-digits number))))155(d (max q (min n 7)))156(dd (- d n)))157(if (<= 0 dd d)158(dfloat-format-fixed stream number dd)159(dfloat-format-exp stream number))))))))))160161162163