Add types for imaginary numbers and fix type of exact? and inexact?.
This commit is contained in:
parent
ec04467282
commit
9e8cc6af3c
|
@ -697,11 +697,8 @@
|
||||||
[complex? (make-pred-ty N)]
|
[complex? (make-pred-ty N)]
|
||||||
;; `rational?' includes all Reals, except infinities and NaN.
|
;; `rational?' includes all Reals, except infinities and NaN.
|
||||||
[rational? (asym-pred Univ B (-FS (-filter -Real 0) (-not-filter -Rat 0)))]
|
[rational? (asym-pred Univ B (-FS (-filter -Real 0) (-not-filter -Rat 0)))]
|
||||||
[exact? (asym-pred N B (-FS -top (-not-filter -ExactNumber 0)))]
|
[exact? (make-pred-ty -ExactNumber)]
|
||||||
;; `inexact?' can't be a predicate for `(Un -InexactReal -InexactComplex)' because it
|
[inexact? (make-pred-ty (Un -InexactReal -InexactImaginary -InexactComplex))]
|
||||||
;; returns #t on things like 0+1.2i, which are not -InexactComplex (`real-part' of it
|
|
||||||
;; is exact 0)
|
|
||||||
[inexact? (asym-pred N B (-FS -top (-not-filter (Un -InexactReal -InexactComplex) 0)))]
|
|
||||||
[fixnum? (make-pred-ty -Fixnum)]
|
[fixnum? (make-pred-ty -Fixnum)]
|
||||||
[index? (make-pred-ty -Index)]
|
[index? (make-pred-ty -Index)]
|
||||||
[positive? (cl->* (-> -Byte B : (-FS (-filter -PosByte 0) (-filter -Zero 0)))
|
[positive? (cl->* (-> -Byte B : (-FS (-filter -PosByte 0) (-filter -Zero 0)))
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
-SingleFlonumPosZero -SingleFlonumNegZero -SingleFlonumZero -SingleFlonumNan -PosSingleFlonum -NonNegSingleFlonum -NegSingleFlonum -NonPosSingleFlonum -SingleFlonum
|
-SingleFlonumPosZero -SingleFlonumNegZero -SingleFlonumZero -SingleFlonumNan -PosSingleFlonum -NonNegSingleFlonum -NegSingleFlonum -NonPosSingleFlonum -SingleFlonum
|
||||||
-InexactRealPosZero -InexactRealNegZero -InexactRealZero -InexactRealNan -PosInexactReal -NonNegInexactReal -NegInexactReal -NonPosInexactReal -InexactReal
|
-InexactRealPosZero -InexactRealNegZero -InexactRealZero -InexactRealNan -PosInexactReal -NonNegInexactReal -NegInexactReal -NonPosInexactReal -InexactReal
|
||||||
-RealZero -PosReal -NonNegReal -NegReal -NonPosReal -Real
|
-RealZero -PosReal -NonNegReal -NegReal -NonPosReal -Real
|
||||||
-ExactNumber -FloatComplex -SingleFlonumComplex -InexactComplex -Number
|
-ExactImaginary -FloatImaginary -SingleFlonumImaginary -InexactImaginary -Imaginary
|
||||||
|
-ExactNumber -ExactComplex -FloatComplex -SingleFlonumComplex -InexactComplex -Number
|
||||||
(rename-out (-Int -Integer)))
|
(rename-out (-Int -Integer)))
|
||||||
|
|
||||||
;; all the types defined here are numeric
|
;; all the types defined here are numeric
|
||||||
|
@ -235,23 +236,60 @@
|
||||||
;; real-part, imag-part and others.
|
;; real-part, imag-part and others.
|
||||||
;; We could have Complex be a 2-argument type constructor (although it
|
;; We could have Complex be a 2-argument type constructor (although it
|
||||||
;; could construct uninhabitable types like (Complex Integer Float), which
|
;; could construct uninhabitable types like (Complex Integer Float), which
|
||||||
;; can't exist in Racket (parts must be both exact or both inexact)).
|
;; can't exist in Racket (parts must be both exact, both inexact, or one is
|
||||||
;; Imaginaries could have their own type hierarchy as well.
|
;; exact-zero)). That's future work.
|
||||||
;; That's future work.
|
|
||||||
|
|
||||||
;; Both parts of a complex number must be of the same exactness.
|
|
||||||
;; Thus, the only possible kinds of complex numbers are:
|
;; Thus, the only possible kinds of complex numbers are:
|
||||||
;; Real/Real, Flonum/Flonum, SingleFlonum/SingleFlonum
|
;; Zero/Rat, Zero/Flonum, Zero/SingleFlonum.
|
||||||
(define -ExactNumberNotReal
|
;; Rat/Rat, Flonum/Flonum, SingleFlonum/SingleFlonum.
|
||||||
(make-Base 'Exact-Number-Not-Real
|
(define -ExactImaginary
|
||||||
|
(make-Base 'Exact-Imaginary
|
||||||
#'(and/c number?
|
#'(and/c number?
|
||||||
(not/c real?)
|
(not/c real?)
|
||||||
(lambda (x) (exact? (imag-part x))))
|
(lambda (x)
|
||||||
|
(and
|
||||||
|
(eqv? 0 (real-part x))
|
||||||
|
(exact? (imag-part x)))))
|
||||||
(lambda (x) (and (number? x)
|
(lambda (x) (and (number? x)
|
||||||
(not (real? x))
|
(not (real? x))
|
||||||
|
(eqv? 0 (real-part x))
|
||||||
(exact? (imag-part x))))
|
(exact? (imag-part x))))
|
||||||
#'-ExactNumberNotReal))
|
#'-ExactImaginary))
|
||||||
(define -ExactNumber (*Un -ExactNumberNotReal -Rat))
|
(define -ExactComplex
|
||||||
|
(make-Base 'Exact-Complex
|
||||||
|
#'(and/c number?
|
||||||
|
(not/c real?)
|
||||||
|
(lambda (x)
|
||||||
|
(and
|
||||||
|
(not (eqv? 0 (real-part x)))
|
||||||
|
(exact? (real-part x))
|
||||||
|
(exact? (imag-part x)))))
|
||||||
|
(lambda (x) (and (number? x)
|
||||||
|
(not (real? x))
|
||||||
|
(not (eqv? 0 (real-part x)))
|
||||||
|
(exact? (real-part x))
|
||||||
|
(exact? (imag-part x))))
|
||||||
|
#'-ExactComplex))
|
||||||
|
(define -FloatImaginary (make-Base 'Float-Imaginary
|
||||||
|
#'(and/c number?
|
||||||
|
(lambda (x)
|
||||||
|
(and (flonum? (imag-part x))
|
||||||
|
(eqv? 0 (real-part x)))))
|
||||||
|
(lambda (x)
|
||||||
|
(and (number? x)
|
||||||
|
(flonum? (imag-part x))
|
||||||
|
(eqv? 0 (real-part x))))
|
||||||
|
#'-FloatImaginary))
|
||||||
|
(define -SingleFlonumImaginary (make-Base 'Single-Flonum-Imaginary
|
||||||
|
#'(and/c number?
|
||||||
|
(lambda (x)
|
||||||
|
(and (single-flonum? (imag-part x))
|
||||||
|
(eqv? 0 (real-part x)))))
|
||||||
|
(lambda (x)
|
||||||
|
(and (number? x)
|
||||||
|
(single-flonum? (imag-part x))
|
||||||
|
(eqv? 0 (real-part x))))
|
||||||
|
#'-SingleFlonumImaginary))
|
||||||
(define -FloatComplex (make-Base 'Float-Complex
|
(define -FloatComplex (make-Base 'Float-Complex
|
||||||
#'(and/c number?
|
#'(and/c number?
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
@ -272,6 +310,9 @@
|
||||||
(single-flonum? (imag-part x))
|
(single-flonum? (imag-part x))
|
||||||
(single-flonum? (real-part x))))
|
(single-flonum? (real-part x))))
|
||||||
#'-SingleFlonumComplex))
|
#'-SingleFlonumComplex))
|
||||||
|
(define -ExactNumber (*Un -ExactImaginary -ExactComplex -Rat))
|
||||||
|
(define -InexactImaginary (*Un -FloatImaginary -SingleFlonumImaginary))
|
||||||
|
(define -Imaginary (*Un -ExactImaginary -InexactImaginary))
|
||||||
(define -InexactComplex (*Un -FloatComplex -SingleFlonumComplex))
|
(define -InexactComplex (*Un -FloatComplex -SingleFlonumComplex))
|
||||||
(define -Complex (*Un -Real -InexactComplex -ExactNumberNotReal))
|
(define -Complex (*Un -Real -Imaginary -ExactComplex -InexactComplex))
|
||||||
(define -Number -Complex)
|
(define -Number -Complex)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user