Add an Exact-Number type.
This commit is contained in:
parent
80a9027f1e
commit
88fac43d55
|
@ -871,7 +871,7 @@
|
||||||
(tc-l -5# -NegFlonum)
|
(tc-l -5# -NegFlonum)
|
||||||
(tc-l -5.0 -NegFlonum)
|
(tc-l -5.0 -NegFlonum)
|
||||||
(tc-l -5.1 -NegFlonum)
|
(tc-l -5.1 -NegFlonum)
|
||||||
(tc-l 1+1i N)
|
(tc-l 1+1i -ExactNumber)
|
||||||
(tc-l 1+1.0i -FloatComplex)
|
(tc-l 1+1.0i -FloatComplex)
|
||||||
(tc-l 1.0+1i -FloatComplex)
|
(tc-l 1.0+1i -FloatComplex)
|
||||||
(tc-l 1.0+1.1i -FloatComplex)
|
(tc-l 1.0+1.1i -FloatComplex)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
[Inexact-Complex -InexactComplex]
|
[Inexact-Complex -InexactComplex]
|
||||||
[Single-Flonum-Complex -SingleFlonumComplex]
|
[Single-Flonum-Complex -SingleFlonumComplex]
|
||||||
[Float-Complex -FloatComplex]
|
[Float-Complex -FloatComplex]
|
||||||
|
[Exact-Number -ExactNumber]
|
||||||
[Real -Real]
|
[Real -Real]
|
||||||
[Nonpositive-Real -NonPosReal]
|
[Nonpositive-Real -NonPosReal]
|
||||||
[Negative-Real -NegReal]
|
[Negative-Real -NegReal]
|
||||||
|
|
|
@ -164,6 +164,7 @@
|
||||||
[(== t:-NegReal type-equal?) #'(flat-named-contract 'Negative-Real (and/c real? negative?))]
|
[(== t:-NegReal type-equal?) #'(flat-named-contract 'Negative-Real (and/c real? negative?))]
|
||||||
[(== t:-NonPosReal type-equal?) #'(flat-named-contract 'Nonpositive-Real (and/c real? (lambda (x) (<= x 0))))]
|
[(== t:-NonPosReal type-equal?) #'(flat-named-contract 'Nonpositive-Real (and/c real? (lambda (x) (<= x 0))))]
|
||||||
[(== t:-Real type-equal?) #'(flat-named-contract 'Real real?)]
|
[(== t:-Real type-equal?) #'(flat-named-contract 'Real real?)]
|
||||||
|
[(== t:-ExactNumber type-equal?) #'(flat-named-contract 'Exact-Number (and/c number? exact?))]
|
||||||
[(== t:-InexactComplex type-equal?)
|
[(== t:-InexactComplex type-equal?)
|
||||||
#'(flat-named-contract 'Inexact-Complex
|
#'(flat-named-contract 'Inexact-Complex
|
||||||
(and/c number?
|
(and/c number?
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
[(~var i (3d inexact-real?)) -InexactReal] ; catch-all, just in case
|
[(~var i (3d inexact-real?)) -InexactReal] ; catch-all, just in case
|
||||||
[(~var i (3d real?)) -Real] ; catch-all, just in case
|
[(~var i (3d real?)) -Real] ; catch-all, just in case
|
||||||
;; a complex number can't have a float imaginary part and an exact real part
|
;; a complex number can't have a float imaginary part and an exact real part
|
||||||
|
[(~var i (3d (conjoin number? exact?)))
|
||||||
|
-ExactNumber]
|
||||||
[(~var i (3d (conjoin number? (lambda (x) (and (flonum? (imag-part x))
|
[(~var i (3d (conjoin number? (lambda (x) (and (flonum? (imag-part x))
|
||||||
(flonum? (real-part x)))))))
|
(flonum? (real-part x)))))))
|
||||||
-FloatComplex]
|
-FloatComplex]
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
[(? (lambda (t) (subtype t -SingleFlonum))) -SingleFlonum]
|
[(? (lambda (t) (subtype t -SingleFlonum))) -SingleFlonum]
|
||||||
[(? (lambda (t) (subtype t -InexactReal))) -InexactReal]
|
[(? (lambda (t) (subtype t -InexactReal))) -InexactReal]
|
||||||
[(? (lambda (t) (subtype t -Real))) -Real]
|
[(? (lambda (t) (subtype t -Real))) -Real]
|
||||||
|
[(? (lambda (t) (subtype t -ExactNumber))) -ExactNumber]
|
||||||
[(? (lambda (t) (subtype t -FloatComplex))) -FloatComplex]
|
[(? (lambda (t) (subtype t -FloatComplex))) -FloatComplex]
|
||||||
[(? (lambda (t) (subtype t -SingleFlonumComplex))) -SingleFlonumComplex]
|
[(? (lambda (t) (subtype t -SingleFlonumComplex))) -SingleFlonumComplex]
|
||||||
[(? (lambda (t) (subtype t -Number))) -Number]
|
[(? (lambda (t) (subtype t -Number))) -Number]
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
-SingleFlonumPosZero -SingleFlonumNegZero -SingleFlonumZero -PosSingleFlonum -NonNegSingleFlonum -NegSingleFlonum -NonPosSingleFlonum -SingleFlonum
|
-SingleFlonumPosZero -SingleFlonumNegZero -SingleFlonumZero -PosSingleFlonum -NonNegSingleFlonum -NegSingleFlonum -NonPosSingleFlonum -SingleFlonum
|
||||||
-InexactRealPosZero -InexactRealNegZero -InexactRealZero -PosInexactReal -NonNegInexactReal -NegInexactReal -NonPosInexactReal -InexactReal
|
-InexactRealPosZero -InexactRealNegZero -InexactRealZero -PosInexactReal -NonNegInexactReal -NegInexactReal -NonPosInexactReal -InexactReal
|
||||||
-RealZero -PosReal -NonNegReal -NegReal -NonPosReal -Real
|
-RealZero -PosReal -NonNegReal -NegReal -NonPosReal -Real
|
||||||
-FloatComplex -SingleFlonumComplex -InexactComplex -Number
|
-ExactNumber -FloatComplex -SingleFlonumComplex -InexactComplex -Number
|
||||||
(rename-out (-Int -Integer)))
|
(rename-out (-Int -Integer)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,6 +204,16 @@
|
||||||
;; Both parts of a complex number must be of the same exactness.
|
;; 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
|
;; Real/Real, Flonum/Flonum, SingleFlonum/SingleFlonum
|
||||||
|
(define -ExactNumberNotReal
|
||||||
|
(make-Base 'Complex-Not-Real
|
||||||
|
#'(and/c number?
|
||||||
|
(not/c real?)
|
||||||
|
(lambda (x) (exact? (imag-part x))))
|
||||||
|
(conjoin number?
|
||||||
|
(negate real?)
|
||||||
|
(lambda (x) (exact? (imag-part x))))
|
||||||
|
#'-ExactNumberNotReal))
|
||||||
|
(define -ExactNumber (*Un -ExactNumberNotReal -Rat))
|
||||||
(define -FloatComplex (make-Base 'Float-Complex
|
(define -FloatComplex (make-Base 'Float-Complex
|
||||||
#'(and/c number?
|
#'(and/c number?
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
@ -225,14 +235,5 @@
|
||||||
(single-flonum? (real-part x)))))
|
(single-flonum? (real-part x)))))
|
||||||
#'-SingleFlonumComplex))
|
#'-SingleFlonumComplex))
|
||||||
(define -InexactComplex (*Un -FloatComplex -SingleFlonumComplex))
|
(define -InexactComplex (*Un -FloatComplex -SingleFlonumComplex))
|
||||||
(define -ExactComplexNotReal
|
(define -Complex (*Un -Real -InexactComplex -ExactNumberNotReal))
|
||||||
(make-Base 'Complex-Not-Real
|
|
||||||
#'(and/c number?
|
|
||||||
(not/c real?)
|
|
||||||
(lambda (x) (exact? (imag-part x))))
|
|
||||||
(conjoin number?
|
|
||||||
(negate real?)
|
|
||||||
(lambda (x) (exact? (imag-part x))))
|
|
||||||
#'-ExactComplexNotReal))
|
|
||||||
(define -Complex (*Un -Real -InexactComplex -ExactComplexNotReal))
|
|
||||||
(define -Number -Complex)
|
(define -Number -Complex)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user