| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: SYSTEM -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 2011 Juan Jose Garcia-Ripoll |
| 6 |
;;;; |
| 7 |
;;;; See file 'LICENSE' for the copyright details. |
| 8 |
;;;; |
| 9 |
|
| 10 |
;;;; CDR 5: Sub-interval Numerical Types for Common Lisp |
| 11 |
;;;; |
| 12 |
;;;; https://common-lisp.net/project/cdr/document/5/index.html |
| 13 |
|
| 14 |
(pushnew :cdr-5 *features*) |
| 15 |
|
| 16 |
(in-package "EXT") |
| 17 |
|
| 18 |
;;; |
| 19 |
;;; List of symbols for symbols_list.h |
| 20 |
;;; |
| 21 |
#+(or) |
| 22 |
(progn |
| 23 |
(loop with *print-case* = :downcase |
| 24 |
for i in '(fixnum integer rational ratio |
| 25 |
real float short-float single-float |
| 26 |
double-float long-float) |
| 27 |
do (loop for j in '("negative-~a-p" "non-negative-~a-p" |
| 28 |
"non-positive-~a-p" "positive-~a-p") |
| 29 |
do (format t "ext:~? " j (list i))) |
| 30 |
do (terpri)) |
| 31 |
(loop for i in '(fixnum integer rational ratio |
| 32 |
real float short-float single-float |
| 33 |
double-float long-float) |
| 34 |
for name = (substitute #\_ #\- (string-downcase i)) |
| 35 |
do (loop for j in '("NEGATIVE-~A" "NON-NEGATIVE-~A" "NON-POSITIVE-~A" "POSITIVE-~A") |
| 36 |
do (format t |
| 37 |
"~%{EXT_ \"~?\", EXT_ORDINARY, NULL, -1, OBJNULL}," |
| 38 |
j (list i))) |
| 39 |
do (loop for j in |
| 40 |
'("~%{EXT_ \"NEGATIVE-~A-P\", EXT_ORDINARY, ECL_NAME(si_negative_~A_p), 1, OBJNULL}," |
| 41 |
"~%{EXT_ \"POSITIVE-~A-P\", EXT_ORDINARY, ECL_NAME(si_positive_~A_p), 1, OBJNULL}," |
| 42 |
"~%{EXT_ \"NON-NEGATIVE-~A-P\", EXT_ORDINARY, ECL_NAME(si_non_negative_~A_p), 1, OBJNULL}," |
| 43 |
"~%{EXT_ \"NON-POSITIVE-~A-P\", EXT_ORDINARY, ECL_NAME(si_non_positive_~A_p), 1, OBJNULL},") |
| 44 |
do (format t j i name)) |
| 45 |
do (terpri)) |
| 46 |
(loop for i in '(fixnum integer rational ratio |
| 47 |
real float short-float single-float |
| 48 |
double-float long-float) |
| 49 |
for name = (substitute #\_ #\- (string-downcase i)) |
| 50 |
do (loop for j in '("negative" "non_negative" "non_positive" "positive") |
| 51 |
do (format t "~%extern ECL_API cl_object si_~a_~a_p(cl_object);" j name)) |
| 52 |
do (terpri)) |
| 53 |
(loop with *print-case* = :downcase |
| 54 |
for i in '(fixnum integer rational ratio |
| 55 |
real float short-float single-float |
| 56 |
double-float long-float) |
| 57 |
do (loop for j in '("NEGATIVE-~A-P" "NON-NEGATIVE-~A-P" |
| 58 |
"NON-POSITIVE-~A-P" "POSITIVE-~A-P") |
| 59 |
for name = (format nil j (symbol-name i)) |
| 60 |
for s = (intern name (find-package "EXT")) |
| 61 |
do (print `(proclamation ,s (t) gen-bool :pure))) |
| 62 |
do (terpri))) |
| 63 |
|
| 64 |
;;; |
| 65 |
;;; Small integers |
| 66 |
;;; |
| 67 |
|
| 68 |
(deftype negative-fixnum () |
| 69 |
`(integer ,most-negative-fixnum -1)) |
| 70 |
|
| 71 |
(deftype non-positive-fixnum () |
| 72 |
`(integer ,most-negative-fixnum 0)) |
| 73 |
|
| 74 |
(deftype non-negative-fixnum () |
| 75 |
`(integer 0 , most-positive-fixnum)) |
| 76 |
|
| 77 |
(deftype positive-fixnum () |
| 78 |
`(integer 1 ,most-positive-fixnum)) |
| 79 |
|
| 80 |
(defun negative-fixnum-p (p) |
| 81 |
(and (si::fixnump p) (minusp (truly-the fixnum p)))) |
| 82 |
|
| 83 |
(defun positive-fixnum-p (p) |
| 84 |
(and (si::fixnump p) (plusp (truly-the fixnum p)))) |
| 85 |
|
| 86 |
(defun non-negative-fixnum-p (p) |
| 87 |
(and (si::fixnump p) (not (minusp (truly-the fixnum p))))) |
| 88 |
|
| 89 |
(defun non-positive-fixnum-p (p) |
| 90 |
(and (si::fixnump p) (not (plusp (truly-the fixnum p))))) |
| 91 |
|
| 92 |
(defun array-index-p (p) |
| 93 |
(and (si::fixnump p) |
| 94 |
(<= 0 (truly-the fixnum p) array-dimension-limit))) |
| 95 |
|
| 96 |
;;; |
| 97 |
;;; Integers |
| 98 |
;;; |
| 99 |
|
| 100 |
(deftype negative-integer () |
| 101 |
'(integer * -1)) |
| 102 |
|
| 103 |
(deftype non-positive-integer () |
| 104 |
'(integer * 0)) |
| 105 |
|
| 106 |
(deftype non-negative-integer () |
| 107 |
'(integer 0 *)) |
| 108 |
|
| 109 |
(deftype positive-integer () |
| 110 |
'(integer 1 *)) |
| 111 |
|
| 112 |
(defun negative-integer-p (p) |
| 113 |
(and (integerp p) (minusp (truly-the integer p)))) |
| 114 |
|
| 115 |
(defun positive-integer-p (p) |
| 116 |
(and (integerp p) (plusp (truly-the integer p)))) |
| 117 |
|
| 118 |
(defun non-negative-integer-p (p) |
| 119 |
(and (integerp p) (not (minusp (truly-the integer p))))) |
| 120 |
|
| 121 |
(defun non-positive-integer-p (p) |
| 122 |
(and (integerp p) (not (plusp (truly-the integer p))))) |
| 123 |
|
| 124 |
;;; |
| 125 |
;;; Rationals |
| 126 |
;;; |
| 127 |
|
| 128 |
(deftype negative-rational () |
| 129 |
'(rational * (0))) |
| 130 |
|
| 131 |
(deftype non-positive-rational () |
| 132 |
'(rational * 0)) |
| 133 |
|
| 134 |
(deftype non-negative-rational () |
| 135 |
'(rational 0 *)) |
| 136 |
|
| 137 |
(deftype positive-rational () |
| 138 |
'(rational (0) *)) |
| 139 |
|
| 140 |
(defun negative-rational-p (p) |
| 141 |
(and (rationalp p) (minusp (truly-the rational p)))) |
| 142 |
|
| 143 |
(defun positive-rational-p (p) |
| 144 |
(and (rationalp p) (plusp (truly-the rational p)))) |
| 145 |
|
| 146 |
(defun non-negative-rational-p (p) |
| 147 |
(and (rationalp p) (not (minusp (truly-the rational p))))) |
| 148 |
|
| 149 |
(defun non-positive-rational-p (p) |
| 150 |
(and (rationalp p) (not (plusp (truly-the rational p))))) |
| 151 |
|
| 152 |
;;; |
| 153 |
;;; Ratios |
| 154 |
;;; |
| 155 |
|
| 156 |
(defun ratiop (x) |
| 157 |
(eq (type-of x) 'RATIO)) |
| 158 |
|
| 159 |
(defun positive-ratio-p (x) |
| 160 |
(and (ratiop x) (plusp x))) |
| 161 |
|
| 162 |
(defun negative-ratio-p (x) |
| 163 |
(and (ratiop x) (minusp x))) |
| 164 |
|
| 165 |
(deftype negative-ratio () |
| 166 |
'(satisfies negative-ratio-p)) |
| 167 |
|
| 168 |
(deftype non-positive-ratio () |
| 169 |
'negative-ratio) |
| 170 |
|
| 171 |
(deftype non-negative-ratio () |
| 172 |
'positive-ratio) |
| 173 |
|
| 174 |
(deftype positive-ratio () |
| 175 |
'(satisfies positive-ratio-p)) |
| 176 |
|
| 177 |
(defun non-negative-ratio-p (p) |
| 178 |
(positive-ratio-p p)) |
| 179 |
|
| 180 |
(defun non-positive-ratio-p (p) |
| 181 |
(negative-ratio-p p)) |
| 182 |
|
| 183 |
;;; |
| 184 |
;;; Reals |
| 185 |
;;; |
| 186 |
|
| 187 |
(deftype negative-real () |
| 188 |
'(real * (0))) |
| 189 |
|
| 190 |
(deftype non-positive-real () |
| 191 |
'(real * 0)) |
| 192 |
|
| 193 |
(deftype non-negative-real () |
| 194 |
'(real 0 *)) |
| 195 |
|
| 196 |
(deftype positive-real () |
| 197 |
'(real (0) *)) |
| 198 |
|
| 199 |
(defun negative-real-p (p) |
| 200 |
(and (realp p) (minusp (truly-the real p)))) |
| 201 |
|
| 202 |
(defun positive-real-p (p) |
| 203 |
(and (realp p) (plusp (truly-the real p)))) |
| 204 |
|
| 205 |
(defun non-negative-real-p (p) |
| 206 |
(and (realp p) (not (minusp (truly-the real p))))) |
| 207 |
|
| 208 |
(defun non-positive-real-p (p) |
| 209 |
(and (realp p) (not (plusp (truly-the real p))))) |
| 210 |
|
| 211 |
;;; |
| 212 |
;;; Floats |
| 213 |
;;; |
| 214 |
|
| 215 |
(deftype negative-float () |
| 216 |
'(float * (0))) |
| 217 |
|
| 218 |
(deftype non-positive-float () |
| 219 |
'(float * 0)) |
| 220 |
|
| 221 |
(deftype non-negative-float () |
| 222 |
'(float 0 *)) |
| 223 |
|
| 224 |
(deftype positive-float () |
| 225 |
'(float (0) *)) |
| 226 |
|
| 227 |
(defun negative-float-p (p) |
| 228 |
(and (floatp p) (minusp (truly-the float p)))) |
| 229 |
|
| 230 |
(defun positive-float-p (p) |
| 231 |
(and (floatp p) (plusp (truly-the float p)))) |
| 232 |
|
| 233 |
(defun non-negative-float-p (p) |
| 234 |
(and (floatp p) (not (minusp (truly-the float p))))) |
| 235 |
|
| 236 |
(defun non-positive-float-p (p) |
| 237 |
(and (floatp p) (not (plusp (truly-the float p))))) |
| 238 |
|
| 239 |
;;; |
| 240 |
;;; SHORT-FLOAT |
| 241 |
;;; |
| 242 |
|
| 243 |
(deftype negative-short-float () |
| 244 |
'(short-float * (0S0))) |
| 245 |
|
| 246 |
(deftype non-positive-short-float () |
| 247 |
'(short-float * 0S0)) |
| 248 |
|
| 249 |
(deftype non-negative-short-float () |
| 250 |
'(short-float 0S0 *)) |
| 251 |
|
| 252 |
(deftype positive-short-float () |
| 253 |
'(short-float (0S0) *)) |
| 254 |
|
| 255 |
(defun negative-short-float-p (p) |
| 256 |
(and (short-floatp p) (minusp (truly-the short-float p)))) |
| 257 |
|
| 258 |
(defun positive-short-float-p (p) |
| 259 |
(and (short-floatp p) (plusp (truly-the short-float p)))) |
| 260 |
|
| 261 |
(defun non-negative-short-float-p (p) |
| 262 |
(and (short-floatp p) (not (minusp (truly-the short-float p))))) |
| 263 |
|
| 264 |
(defun non-positive-short-float-p (p) |
| 265 |
(and (short-floatp p) (not (plusp (truly-the short-float p))))) |
| 266 |
|
| 267 |
;;; |
| 268 |
;;; SINGLE-FLOAT |
| 269 |
;;; |
| 270 |
|
| 271 |
(deftype negative-single-float () |
| 272 |
'(single-float * (0F0))) |
| 273 |
|
| 274 |
(deftype non-positive-single-float () |
| 275 |
'(single-float * 0F0)) |
| 276 |
|
| 277 |
(deftype non-negative-single-float () |
| 278 |
'(single-float 0F0 *)) |
| 279 |
|
| 280 |
(deftype positive-single-float () |
| 281 |
'(single-float (0F0) *)) |
| 282 |
|
| 283 |
(defun negative-single-float-p (p) |
| 284 |
(and (single-floatp p) (minusp (truly-the single-float p)))) |
| 285 |
|
| 286 |
(defun positive-single-float-p (p) |
| 287 |
(and (single-floatp p) (plusp (truly-the single-float p)))) |
| 288 |
|
| 289 |
(defun non-negative-single-float-p (p) |
| 290 |
(and (single-floatp p) (not (minusp (truly-the single-float p))))) |
| 291 |
|
| 292 |
(defun non-positive-single-float-p (p) |
| 293 |
(and (single-floatp p) (not (plusp (truly-the single-float p))))) |
| 294 |
|
| 295 |
;;; |
| 296 |
;;; DOUBLE-FLOAT |
| 297 |
;;; |
| 298 |
|
| 299 |
(deftype negative-double-float () |
| 300 |
'(double-float * (0D0))) |
| 301 |
|
| 302 |
(deftype non-positive-double-float () |
| 303 |
'(double-float * 0D0)) |
| 304 |
|
| 305 |
(deftype non-negative-double-float () |
| 306 |
'(double-float 0D0 *)) |
| 307 |
|
| 308 |
(deftype positive-double-float () |
| 309 |
'(double-float (0D0) *)) |
| 310 |
|
| 311 |
(defun negative-double-float-p (p) |
| 312 |
(and (double-floatp p) (minusp (truly-the double-float p)))) |
| 313 |
|
| 314 |
(defun positive-double-float-p (p) |
| 315 |
(and (double-floatp p) (plusp (truly-the double-float p)))) |
| 316 |
|
| 317 |
(defun non-negative-double-float-p (p) |
| 318 |
(and (double-floatp p) (not (minusp (truly-the double-float p))))) |
| 319 |
|
| 320 |
(defun non-positive-double-float-p (p) |
| 321 |
(and (double-floatp p) (not (plusp (truly-the double-float p))))) |
| 322 |
|
| 323 |
;;; |
| 324 |
;;; LONG-FLOAT |
| 325 |
;;; |
| 326 |
|
| 327 |
(deftype negative-long-float () |
| 328 |
'(long-float * (0L0))) |
| 329 |
|
| 330 |
(deftype non-positive-long-float () |
| 331 |
'(long-float * 0L0)) |
| 332 |
|
| 333 |
(deftype non-negative-long-float () |
| 334 |
'(long-float 0L0 *)) |
| 335 |
|
| 336 |
(deftype positive-long-float () |
| 337 |
'(long-float (0L0) *)) |
| 338 |
|
| 339 |
(defun negative-long-float-p (p) |
| 340 |
(and (long-floatp p) (minusp (truly-the long-float p)))) |
| 341 |
|
| 342 |
(defun positive-long-float-p (p) |
| 343 |
(and (long-floatp p) (plusp (truly-the long-float p)))) |
| 344 |
|
| 345 |
(defun non-negative-long-float-p (p) |
| 346 |
(and (long-floatp p) (not (minusp (truly-the long-float p))))) |
| 347 |
|
| 348 |
(defun non-positive-long-float-p (p) |
| 349 |
(and (long-floatp p) (not (plusp (truly-the long-float p))))) |