Changeset 10166
 Timestamp:
 10/19/05 16:51:43 (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/j/src/org/armedbear/lisp/tests/mathtests.lisp
r10157 r10166 2 2 ;;; 3 3 ;;; Copyright (C) 2005 Peter Graves 4 ;;; $Id: mathtests.lisp,v 1. 1 20051018 13:34:21piso Exp $4 ;;; $Id: mathtests.lisp,v 1.2 20051019 16:51:43 piso Exp $ 5 5 ;;; 6 6 ;;; This program is free software; you can redistribute it and/or … … 20 20 ;;; Some of these tests are based on tests in the CLISP test suite. 21 21 22 ;; SETFLOATINGPOINTMODES, GETFLOATINGPOINTMODES 23 #+abcl 24 (progn 25 (ext:setfloatingpointmodes :traps nil) 26 (assert (equal (ext:getfloatingpointmodes) '(:traps nil))) 27 (assert (equal (getf (ext:getfloatingpointmodes) :traps) nil)) 28 (ext:setfloatingpointmodes :traps '(:overflow)) 29 (assert (equal (ext:getfloatingpointmodes) '(:traps (:overflow)))) 30 (assert (equal (getf (ext:getfloatingpointmodes) :traps) '(:overflow))) 31 (ext:setfloatingpointmodes :traps '(:underflow)) 32 (assert (equal (ext:getfloatingpointmodes) '(:traps (:underflow)))) 33 (assert (equal (getf (ext:getfloatingpointmodes) :traps) '(:underflow))) 34 (ext:setfloatingpointmodes :traps '(:overflow :underflow)) 35 (assert (equal (ext:getfloatingpointmodes) '(:traps (:overflow :underflow)))) 36 (assert (equal (getf (ext:getfloatingpointmodes) :traps) '(:overflow :underflow))) 37 ) 38 #+sbcl 39 (progn 40 (sbint:setfloatingpointmodes :traps nil) 41 (assert (equal (getf (sbint:getfloatingpointmodes) :traps) nil)) 42 (sbint:setfloatingpointmodes :traps '(:overflow)) 43 (assert (equal (getf (sbint:getfloatingpointmodes) :traps) '(:overflow))) 44 (sbint:setfloatingpointmodes :traps '(:underflow)) 45 (assert (equal (getf (sbint:getfloatingpointmodes) :traps) '(:underflow))) 46 (sbint:setfloatingpointmodes :traps '(:overflow :underflow)) 47 (assert (null (setexclusiveor (getf (sbint:getfloatingpointmodes) :traps) 48 '(:overflow :underflow)))) 49 ) 50 51 ;; Restore defaults. 52 #+abcl 53 (ext:setfloatingpointmodes :traps '(:overflow :underflow)) 54 #+sbcl 55 (sbint:setfloatingpointmodes :traps '(:overflow :invalid :dividebyzero)) 56 57 #clisp 58 (progn 59 (assert (= mostpositivesinglefloat 3.4028235e+38)) 60 (assert (= leastpositivesinglefloat 1.4012985e45)) 61 62 (assert (= (log mostpositivesinglefloat) 88.72284)) 63 (assert (= (log leastpositivesinglefloat) 103.27893)) 64 ) 22 (unless (member "RT" *modules* :test #'string=) 23 (unless (ignoreerrors (logicalpathnametranslations "ansitests")) 24 (error "~S is not defined as a logical pathname host." "ansitests")) 25 (load "ansitests:rtpackage.lsp") 26 (load #+abcl (compilefileifneeded "ansitests:rt.lsp") 27 ;; Force compilation to avoid fasl name conflict between SBCL and 28 ;; Allegro. 29 #abcl (compilefile "ansitests:rt.lsp")) 30 (provide "RT")) 31 32 (regressiontest:remalltests) 33 34 (let ((*package* (findpackage '#:regressiontest))) 35 (export (findsymbol (string '#:*expectedfailures*)))) 36 37 (setf regressiontest:*expectedfailures* nil) 38 39 (unless (findpackage '#:test) 40 (defpackage #:test (:use #:cl #:regressiontest))) 41 42 (inpackage #:test) 43 44 #+(or abcl cmu sbcl) 45 (defmacro setfloatingpointmodes (&rest args) 46 `(funcall #+abcl 'ext:setfloatingpointmodes 47 #+cmu 'ext:setfloatingpointmodes 48 #+sbcl 'sbint:setfloatingpointmodes 49 ,@args)) 50 51 #+(or abcl cmu sbcl) 52 (defmacro getfloatingpointmodes () 53 #+abcl `(ext:getfloatingpointmodes) 54 #+cmu `(ext:getfloatingpointmodes) 55 #+sbcl `(sbint:getfloatingpointmodes)) 56 57 #+(or abcl cmu sbcl) 58 (defun restoredefaultfloatingpointmodes () 59 #+abcl 60 (setfloatingpointmodes :traps '(:overflow :underflow)) 61 #+(or cmu sbcl) 62 (setfloatingpointmodes :traps '(:overflow :invalid :dividebyzero))) 63 64 #+(or abcl cmu sbcl) 65 (evalwhen (:compiletoplevel :loadtoplevel :execute) 66 (restoredefaultfloatingpointmodes)) 67 68 (deftest mostnegativefixnum.1 69 (= (/ mostnegativefixnum 1) ( mostnegativefixnum)) 70 t) 71 72 (deftest mostnegativefixnum.2 73 (= (abs mostnegativefixnum) ( mostnegativefixnum)) 74 t) 75 76 #+(or abcl cmu sbcl) 77 (deftest floatingpointmodes.1 78 (unwindprotect 79 (progn 80 (setfloatingpointmodes :traps nil) 81 (getf (getfloatingpointmodes) :traps)) 82 (restoredefaultfloatingpointmodes)) 83 nil) 84 85 #+(or abcl cmu sbcl) 86 (deftest floatingpointmodes.2 87 (unwindprotect 88 (progn 89 (setfloatingpointmodes :traps '(:overflow)) 90 (getf (getfloatingpointmodes) :traps)) 91 (restoredefaultfloatingpointmodes)) 92 (:overflow)) 93 94 #+(or abcl cmu sbcl) 95 (deftest floatingpointmodes.3 96 (unwindprotect 97 (progn 98 (setfloatingpointmodes :traps '(:underflow)) 99 (getf (getfloatingpointmodes) :traps)) 100 (restoredefaultfloatingpointmodes)) 101 (:underflow)) 102 103 #+(or abcl cmu sbcl) 104 (deftest floatingpointmodes.4 105 (unwindprotect 106 (progn 107 (setfloatingpointmodes :traps '(:overflow :underflow)) 108 (setexclusiveor (getf (getfloatingpointmodes) :traps) 109 '(:overflow :underflow))) 110 (restoredefaultfloatingpointmodes)) 111 nil) 112 113 (deftest mostpositivesinglefloat.1 114 mostpositivesinglefloat 115 #lispworks 116 3.4028235e+38 117 #+lispworks 118 1.7976931348623157E308) 119 120 (deftest mostpositivesinglefloat.2 121 (log mostpositivesinglefloat) 122 #lispworks 88.72284 123 #+lispworks 709.782712893384) 124 125 (deftest leastpositivesinglefloat.1 126 leastpositivesinglefloat 127 #(or clisp lispworks) 1.4012985e45 128 #+clisp 1.1754944E38 129 #+lispworks 4.9406564584124646E324) 130 131 (deftest leastpositivesinglefloat.2 132 (log leastpositivesinglefloat) 133 #(or clisp lispworks) 103.27893 134 #+clisp 87.33655 135 #+lispworks 744.4400719213812) 65 136 66 137 ;; SQRT 67 #+clisp 68 (assert (eql (sqrt 0) 0)) 69 #clisp 70 (assert (= (sqrt 0) 0.0)) 71 #+clisp 72 (assert (eql (sqrt 1) 1)) 73 #clisp 74 (assert (= (sqrt 1) 1.0)) 75 #+clisp 76 (assert (eql (sqrt 9) 3)) 77 #clisp 78 (assert (= (sqrt 9) 3.0)) 79 #+clisp 80 (assert (eql (sqrt 9) #c(0 3))) 81 #clisp 82 (assert (eql (sqrt 9) #c(0.0 3.0))) 83 #+clisp 84 (assert (eql (sqrt #c(7 24)) #c(3 4))) 85 #clisp 86 (assert (= (sqrt #c(7 24)) #c(3.0 4.0))) 87 88 (assert (= (sqrt 1d0) 1.0d0)) 89 (assert (= (sqrt 1) #c(0 1))) 90 (assert (= (sqrt 1d0) #c(0 1.0d0))) 91 (assert (= (sqrt #c(0.0 0.0)) #c(0.0 0.0))) 92 (assert (= (sqrt #c(4.0 0.0)) #c(2.0 0.0))) 93 (assert (= (sqrt #c(4.0 0.0)) #c(0.0 2.0))) 94 (assert (= (sqrt #c(4.4855622e7 0.0)) #c(0.0 6.697434e4))) 95 96 #clisp 97 (progn 98 ;; (sqrt 0.0) => 0.0 99 (assert (minusp (floatsign (sqrt 0.0)))) 100 (assert (minusp (floatsign (sqrt 0.0d0))))) 138 (deftest sqrt.1 139 (sqrt 0) 140 #+clisp 0 141 #clisp 0.0) 142 143 (deftest sqrt.2 144 (sqrt 1) 145 #+clisp 1 146 #clisp 1.0) 147 148 (deftest sqrt.3 149 (sqrt 9) 150 #+clisp 3 151 #clisp 3.0) 152 153 (deftest sqrt.4 154 (sqrt 9) 155 #+clisp #c(0 3) 156 #clisp #c(0.0 3.0)) 157 158 (deftest sqrt.5 159 (sqrt #c(7 24)) 160 #(or clisp lispworks) #c(3.0 4.0) 161 #+clisp #c(3 4) 162 #+lispworks #c(3.0 3.999999999999999)) 163 164 (deftest sqrt.6 165 (sqrt 1d0) 166 1.0d0) 167 168 (deftest sqrt.7 169 (sqrt 1) 170 #+(or clisp) #c(0 1) 171 #+(or abcl allegro cmu lispworks sbcl) #c(0.0 1.0)) 172 173 (deftest sqrt.8 174 (sqrt 1d0) 175 #c(0 1.0d0)) 176 177 (deftest sqrt.9 178 (sqrt #c(0.0 0.0)) 179 #c(0.0 0.0)) 180 181 (deftest sqrt.10 182 (sqrt #c(4.0 0.0)) 183 #c(2.0 0.0)) 184 185 (deftest sqrt.11 186 (sqrt #c(4.0 0.0)) 187 #c(0.0 2.0)) 188 189 (deftest sqrt.12 190 (sqrt #c(4.4855622e7 0.0)) 191 #lispworks 192 #c(0.0 6.697434e4) 193 #+lispworks 194 #c(0.0 6.697433986236818e4)) 195 196 #+(or abcl cmu lispworks sbcl) 197 (deftest sqrt.13 198 (floatsign (sqrt 0.0)) 199 1.0) 200 201 #+(or abcl cmu lispworks sbcl) 202 (deftest sqrt.13 203 (floatsign (sqrt 0.0d0)) 204 1.0d0) 101 205 102 206 ;; EXP 103 (assert (= (exp #c(0 0)) 1)) 104 (assert (= (exp #c(0 1)) #c(0.5403023 0.84147096))) 105 #clisp 106 (assert (= (exp #c(1 1)) #c(1.4686939 2.2873552))) 107 #+clisp 108 (assert (= (exp #c(1 1)) #c(1.468694 2.2873552))) 109 (assert (= (exp #c(1 1d0)) #c(1.4686939399158851d0 2.2873552871788423d0))) 110 (assert (= (exp #c(1d0 1d0)) #c(1.4686939399158851d0 2.2873552871788423d0))) 111 (assert (= (exp #c(0 1d0)) #c(0.5403023058681398d0 0.8414709848078965d0))) 112 (assert (= (exp 1) 2.7182817)) 113 (assert (= (exp 1f0) 2.7182817)) 114 (assert (= (exp 1d0) 2.718281828459045d0)) 207 (deftest exp.1 208 (exp #c(0 0)) 209 #+(or abcl allegro cmu lispworks sbcl) 1.0 210 #+clisp 1) 211 212 (deftest exp.2 213 (exp #c(0 1)) 214 #lispworks #c(0.5403023 0.84147096) 215 #+lispworks #c(0.5403023058681398 0.8414709848078965)) 216 217 (deftest exp.3 218 (exp #c(1 1)) 219 #+(or abcl cmu sbcl) #c(1.4686939 2.2873552) 220 #+(or allegro clisp) #c(1.468694 2.2873552) 221 #+lispworks #c(1.4686939399158851 2.2873552871788423)) 222 223 (deftest exp.4 224 (exp #c(1 1d0)) 225 #c(1.4686939399158851d0 2.2873552871788423d0)) 226 227 (deftest exp.5 228 (exp #c(1d0 1d0)) 229 #c(1.4686939399158851d0 2.2873552871788423d0)) 230 231 (deftest exp.6 232 (exp #c(0 1d0)) 233 #c(0.5403023058681398d0 0.8414709848078965d0)) 234 235 (deftest exp.7 236 (exp 1) 237 #lispworks 2.7182817 238 #+lispworks 2.718281828459045) 239 240 (deftest exp.8 241 (exp 1f0) 242 #lispworks 2.7182817 243 #+lispworks 2.718281828459045) 244 245 (deftest exp.9 246 (exp 1d0) 247 2.718281828459045d0) 115 248 116 249 ;; EXPT 117 (assert (= (expt 5s0 2s0) #c(25s0 0s0))) 118 (assert (= (expt 5f0 2f0) #c(25f0 0f0))) 119 (assert (= (expt 5d0 2d0) #c(25d0 0d0))) 120 (assert (= (expt 5l0 2l0) #c(25l0 0l0))) 121 (assert (= (expt 5 2) 25)) 122 (assert (= (expt 5s0 3s0) 125s0)) 123 (assert (= (expt 5f0 3f0) 125f0)) 124 (assert (= (expt 5d0 3d0) 125d0)) 125 (assert (= (expt 5l0 3l0) 125l0)) 126 (assert (= (expt 5 3) 125)) 127 (assert (= (expt #c(10 11) 1) #c(10 11))) 128 (assert (= (expt 0 1/2) 0)) 129 (assert (= (expt 1 1/2) 1)) 130 (assert (= (expt 9 1/2) 3)) 131 #+clisp 132 (assert (= (expt 9 1/2) #c(0 3))) 133 #+(or sbcl cmu) 134 (assert (= (expt 9 1/2) #c(1.8369095e16 3.0))) 135 #+abcl 136 (assert (= (expt 9 1/2) #c(1.8369701e16 3.0))) 137 (assert ( (expt 8 1/3) #c(1.0 1.7320508))) 138 (assert (= (expt #c(7 24) 1/2) #c(3 4))) 139 (assert (= (expt 729 1/6) 3)) 140 (assert (= (expt 3 1) 1/3)) 141 (assert (= (expt #c(3 4) 1) #c(3/25 4/25))) 142 #clisp 143 (assert (= (expt 14 #c(1.0 1.0)) #c(12.269101 6.743085))) 144 #+clisp 145 (assert (= (expt 14 #c(1.0 1.0)) #c(12.269099 6.7430854))) 250 (deftest expt.1 251 (expt 5f0 2) 252 25.0) 253 254 (deftest expt.2 255 (expt 5f0 2f0) 256 #+(or abcl cmu sbcl) 25f0 257 #+allegro #c(25.0 6.1230318e15) 258 #+clisp #c(25f0 0f0) 259 #+lispworks #c(24.999999999999993 6.123031769111885e15)) 260 261 (deftest expt.3 262 (expt 5d0 2d0) 263 #+(or abcl cmu sbcl) 25d0 264 #+allegro #c(24.999999999999996d0 6.1230317691118855d15) 265 #+clisp #c(25d0 0d0)) 266 267 (deftest expt.4 268 (expt 5 2) 269 25) 270 271 (deftest expt.5 272 (eql (expt 5f0 3f0) (* 5.0 5.0 5.0)) 273 t) 274 275 (deftest expt.6 276 (expt 5f0 3f0) 277 125f0) 278 279 (deftest expt.7 280 (expt 5d0 3d0) 281 125d0) 282 283 (deftest expt.8 284 (expt 5 3) 285 125) 286 287 (deftest expt.9 288 (expt #c(10 11) 1) 289 #c(10 11)) 290 291 (deftest expt.10 292 (expt 0 1/2) 293 #+(or allegro clisp lispworks) 0 294 #+(or abcl cmu sbcl) 0.0) 295 296 (deftest expt.11 297 (expt 1 1/2) 298 #+clisp 1 299 #clisp 1.0) 300 301 (deftest expt.12 302 (expt 9 1/2) 303 #+clisp 3 304 #clisp 3.0) 305 306 (deftest expt.13 307 (expt 9 1/2) 308 #+clisp 309 #c(0 3) 310 #+(or allegro sbcl cmu) 311 #c(1.8369095e16 3.0) 312 #+abcl 313 #c(1.8369701e16 3.0)) 314 315 (deftest expt.14 316 (expt 8 1/3) 317 #c(1.0 1.7320508)) 318 319 (deftest expt.15 320 (expt #c(7 24) 1/2) 321 #+clisp #c(3 4) 322 #clisp #c(3.0 4.0)) 323 324 (deftest expt.16 325 (expt 729 1/6) 326 #+clisp 3 327 #clisp 3.0) 328 329 (deftest expt.17 330 (expt 3 1) 331 1/3) 332 333 (deftest expt.18 334 (expt #c(3 4) 1) 335 #c(3/25 4/25)) 336 337 (deftest expt.19 338 (expt 14 #c(1.0 1.0)) 339 #(or clisp allegro) 340 #c(12.269101 6.743085) 341 #+(or clisp allegro) 342 #c(12.269099 6.7430854)) 343 344 (deftest log.1 345 (typep (log 17d0 10) 'doublefloat) 346 t) 347 348 (deftest log.2 349 (typep (log 17 10d0) 'doublefloat) 350 t) 351 352 (deftest log.3 353 (log 17 10) 354 #+abcl 1.2304488 355 #+(or allegro clisp cmu sbcl) 1.230449 356 #+lispworks #.(log 17d0 10d0)) 357 358 (deftest log.4 359 (log 17.0 10.0) 360 #+(or abcl cmu sbcl) 1.2304488 361 #+(or allegro clisp) 1.230449 362 #+lispworks #.(log 17d0 10d0)) 363 364 (deftest log.5 365 (log 17d0 10) 366 #(or allegro clisp lispworks) 1.2304489042913307d0 367 #+(or allegro clisp lispworks) #.(log 17d0 10d0)) 368 369 (deftest log.6 370 (log 17 10d0) 371 #(or allegro clisp lispworks) 1.2304489149763256d0 372 #+(or allegro clisp lispworks) #.(log 17d0 10d0)) 373 374 (deftest log.7 375 (log 17d0 10d0) 376 1.2304489213782739d0) 377 378 (dotests)
Note: See TracChangeset
for help on using the changeset viewer.