add types for new numeric primitives

- positive-integer?
- negative-integer?
- nonpositive-integer?
- nonnegative-integer?
- natural?
This commit is contained in:
Ben Greenman 2017-09-28 23:48:02 -04:00
parent d32218ad15
commit fd5d5e9319
2 changed files with 57 additions and 0 deletions

View File

@ -1902,6 +1902,15 @@
[nan? (make-pred-ty (list -Real) B -InexactRealNan)]
[infinite? (make-pred-ty (list -Real) B (Un -PosInfinity -NegInfinity))]
[positive-integer? (asym-pred Univ B (-PS (-is-type 0 (Un -PosInt -PosFlonum -PosSingleFlonum))
(-not-type 0 -PosInt)))]
[negative-integer? (asym-pred Univ B (-PS (-is-type 0 (Un -NegInt -NegFlonum -NegSingleFlonum))
(-not-type 0 -NegInt)))]
[nonpositive-integer? (asym-pred Univ B (-PS (-is-type 0 (Un -NonPosInt -NonPosFlonum -NonPosSingleFlonum))
(-not-type 0 -NonPosInt)))]
[nonnegative-integer? (asym-pred Univ B (-PS (-is-type 0 (Un -Nat -NonNegFlonum -NonNegSingleFlonum))
(-not-type 0 -Nat)))]
[natural? (make-pred-ty -Nat)]
;; racket/fixnum
[fx+ (fx+-type)]

View File

@ -4374,6 +4374,54 @@
(void))
#:ret (ret -Void #f #f)
#:msg #rx"type mismatch"]
;; pr615 : positive-integer?
[tc-e/t (let: ([x : Exact-Rational 3/2])
(if (positive-integer? x) x 0))
-Nat]
[tc-e/t (let: ([x : Flonum 1.0])
(if (positive-integer? x) x 2.0))
-PosFlonum]
[tc-e/t (let: ([x : (Un Flonum Positive-Integer) 1.0])
(if (not (positive-integer? x)) x 1.0))
-Flonum]
;; pr615 : negative-integer?
[tc-e/t (let: ([x : Exact-Rational -3/2])
(if (negative-integer? x) x -5))
-NegInt]
[tc-e/t (let: ([x : Flonum 1.0])
(if (negative-integer? x) x -2.0))
-NegFlonum]
[tc-e/t (let: ([x : (Un Flonum Negative-Integer) -1.0])
(if (not (negative-integer? x)) x -1.0))
-Flonum]
;; pr615 : nonpositive-integer?
[tc-e/t (let: ([x : Exact-Rational -3/2])
(if (nonpositive-integer? x) x 0))
-NonPosInt]
[tc-e/t (let: ([x : Flonum -1.0])
(if (nonpositive-integer? x) x 0.0))
-NonPosFlonum]
[tc-e/t (let: ([x : (Un Flonum Negative-Integer) -1.0])
(if (not (nonpositive-integer? x)) x -1.0))
-Flonum]
;; pr615 : nonnegative-integer?
[tc-e/t (let: ([x : Exact-Rational 3/2])
(if (nonnegative-integer? x) x 0))
-Nat]
[tc-e/t (let: ([x : Flonum 1.0])
(if (nonnegative-integer? x) x 2.0))
-NonNegFlonum]
[tc-e/t (let: ([x : (Un Flonum Natural) 1.0])
(if (not (nonnegative-integer? x)) x 1.0))
-Flonum]
;; pr615 : natural?
[tc-e/t (let: ([x : Real 1])
(if (natural? x) x 1))
-Nat]
[tc-e/t (let: ([x : (Un Flonum Natural) 0.0])
(if (not (natural? x)) x 1.0))
-Flonum]
)
(test-suite