Added the Inexact-Complex type.
This commit is contained in:
parent
ef576e27c5
commit
dcfb2d8a94
9
collects/tests/typed-scheme/fail/inexact-complex.rkt
Normal file
9
collects/tests/typed-scheme/fail/inexact-complex.rkt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#;
|
||||||
|
(exn-pred 2)
|
||||||
|
#lang typed/scheme
|
||||||
|
|
||||||
|
(ann 1+2i Inexact-Complex)
|
||||||
|
|
||||||
|
(: f (Real -> Inexact-Complex))
|
||||||
|
(define (f x)
|
||||||
|
(* x 2.0)) ; x can be exact 0
|
9
collects/tests/typed-scheme/succeed/inexact-complex.rkt
Normal file
9
collects/tests/typed-scheme/succeed/inexact-complex.rkt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#lang typed/scheme
|
||||||
|
|
||||||
|
(ann 1.1+2.0i Inexact-Complex)
|
||||||
|
(ann 1+2.0i Inexact-Complex)
|
||||||
|
(ann (real-part 1.1+2.0i) Float)
|
||||||
|
(ann (real-part 1+2.0i) Float)
|
||||||
|
(ann (imag-part 1.1+2.0i) Float)
|
||||||
|
(ann (+ 2.0 2.0+2.0i) Inexact-Complex)
|
||||||
|
(ann (+ 2 2.0+2.0i) Inexact-Complex)
|
|
@ -842,6 +842,10 @@
|
||||||
(tc-l 5# -Flonum)
|
(tc-l 5# -Flonum)
|
||||||
(tc-l 5.0 -Flonum)
|
(tc-l 5.0 -Flonum)
|
||||||
(tc-l 5.1 -Flonum)
|
(tc-l 5.1 -Flonum)
|
||||||
|
(tc-l 1+1i N)
|
||||||
|
(tc-l 1+1.0i -InexactComplex)
|
||||||
|
(tc-l 1.0+1i -InexactComplex)
|
||||||
|
(tc-l 1.0+1.1i -InexactComplex)
|
||||||
(tc-l #t (-val #t))
|
(tc-l #t (-val #t))
|
||||||
(tc-l "foo" -String)
|
(tc-l "foo" -String)
|
||||||
(tc-l foo (-val 'foo))
|
(tc-l foo (-val 'foo))
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
[complex? (make-pred-ty N)]
|
[complex? (make-pred-ty N)]
|
||||||
[rational? (make-pred-ty -Real)]
|
[rational? (make-pred-ty -Real)]
|
||||||
[exact? (asym-pred N B (-FS -top (-not-filter -ExactRational 0)))]
|
[exact? (asym-pred N B (-FS -top (-not-filter -ExactRational 0)))]
|
||||||
[inexact? (asym-pred N B (-FS -top (-not-filter -Flonum 0)))]
|
[inexact? (asym-pred N B (-FS -top (-not-filter (Un -Flonum -InexactComplex) 0)))]
|
||||||
[fixnum? (make-pred-ty -Fixnum)]
|
[fixnum? (make-pred-ty -Fixnum)]
|
||||||
[positive? (-> -Real B)]
|
[positive? (-> -Real B)]
|
||||||
[negative? (-> -Real B)]
|
[negative? (-> -Real B)]
|
||||||
|
@ -94,6 +94,7 @@
|
||||||
[* (apply cl->*
|
[* (apply cl->*
|
||||||
(append (for/list ([t (list -Pos -Nat -Integer -ExactRational -Flonum)]) (->* (list) t t))
|
(append (for/list ([t (list -Pos -Nat -Integer -ExactRational -Flonum)]) (->* (list) t t))
|
||||||
(list (->* (list) -Real -Real))
|
(list (->* (list) -Real -Real))
|
||||||
|
(list (->* (list) -InexactComplex -InexactComplex))
|
||||||
(list (->* (list) N N))))]
|
(list (->* (list) N N))))]
|
||||||
[+ (apply cl->*
|
[+ (apply cl->*
|
||||||
(append (for/list ([t (list -Pos -Nat -Integer -ExactRational -Flonum)]) (->* (list) t t))
|
(append (for/list ([t (list -Pos -Nat -Integer -ExactRational -Flonum)]) (->* (list) t t))
|
||||||
|
@ -102,6 +103,9 @@
|
||||||
(list (->* (list -Flonum) -Real -Flonum))
|
(list (->* (list -Flonum) -Real -Flonum))
|
||||||
(list (->* (list -Real -Flonum) -Real -Flonum))
|
(list (->* (list -Real -Flonum) -Real -Flonum))
|
||||||
(list (->* (list) -Real -Real))
|
(list (->* (list) -Real -Real))
|
||||||
|
(list (->* (list -Real) -InexactComplex -InexactComplex))
|
||||||
|
(list (->* (list -InexactComplex) -Real -InexactComplex))
|
||||||
|
(list (->* (list) -InexactComplex -InexactComplex))
|
||||||
(list (->* (list) N N))))]
|
(list (->* (list) N N))))]
|
||||||
|
|
||||||
[- (apply cl->*
|
[- (apply cl->*
|
||||||
|
@ -110,6 +114,9 @@
|
||||||
(list (->* (list -Flonum) -Real -Flonum))
|
(list (->* (list -Flonum) -Real -Flonum))
|
||||||
(list (->* (list -Real -Flonum) -Real -Flonum))
|
(list (->* (list -Real -Flonum) -Real -Flonum))
|
||||||
(list (->* (list -Real) -Real -Real))
|
(list (->* (list -Real) -Real -Real))
|
||||||
|
(list (->* (list -Real) -InexactComplex -InexactComplex))
|
||||||
|
(list (->* (list -InexactComplex) -Real -InexactComplex))
|
||||||
|
(list (->* (list -InexactComplex) -InexactComplex -InexactComplex))
|
||||||
(list (->* (list N) N N))))]
|
(list (->* (list N) N N))))]
|
||||||
[/ (apply cl->*
|
[/ (apply cl->*
|
||||||
(append (list (->* (list -Integer) -Integer -ExactRational))
|
(append (list (->* (list -Integer) -Integer -ExactRational))
|
||||||
|
@ -118,6 +125,7 @@
|
||||||
;; only exact 0 as first argument can cause the result of a division involving inexacts to be exact
|
;; only exact 0 as first argument can cause the result of a division involving inexacts to be exact
|
||||||
(list (->* (list -Flonum) -Real -Flonum))
|
(list (->* (list -Flonum) -Real -Flonum))
|
||||||
(list (->* (list -Real) -Real -Real))
|
(list (->* (list -Real) -Real -Real))
|
||||||
|
(list (->* (list -InexactComplex) -InexactComplex -InexactComplex))
|
||||||
(list (->* (list N) N N))))]
|
(list (->* (list N) N N))))]
|
||||||
|
|
||||||
[max (cl->* (->* (list -PositiveFixnum) -Fixnum -PositiveFixnum)
|
[max (cl->* (->* (list -PositiveFixnum) -Fixnum -PositiveFixnum)
|
||||||
|
@ -149,6 +157,7 @@
|
||||||
(-> -ExactRational -ExactRational)
|
(-> -ExactRational -ExactRational)
|
||||||
(-> -Flonum -Flonum)
|
(-> -Flonum -Flonum)
|
||||||
(-> -Real -Real)
|
(-> -Real -Real)
|
||||||
|
(-> -InexactComplex -InexactComplex)
|
||||||
(-> N N))]
|
(-> N N))]
|
||||||
|
|
||||||
[sub1 (cl->* (-> -Pos -Nat)
|
[sub1 (cl->* (-> -Pos -Nat)
|
||||||
|
@ -156,6 +165,7 @@
|
||||||
(-> -ExactRational -ExactRational)
|
(-> -ExactRational -ExactRational)
|
||||||
(-> -Flonum -Flonum)
|
(-> -Flonum -Flonum)
|
||||||
(-> -Real -Real)
|
(-> -Real -Real)
|
||||||
|
(-> -InexactComplex -InexactComplex)
|
||||||
(-> N N))]
|
(-> N N))]
|
||||||
|
|
||||||
[quotient (cl->* (-NonnegativeFixnum -NonnegativeFixnum . -> . -NonnegativeFixnum)
|
[quotient (cl->* (-NonnegativeFixnum -NonnegativeFixnum . -> . -NonnegativeFixnum)
|
||||||
|
@ -199,7 +209,7 @@
|
||||||
;; exactness
|
;; exactness
|
||||||
[exact->inexact (cl->*
|
[exact->inexact (cl->*
|
||||||
(-Real . -> . -Flonum)
|
(-Real . -> . -Flonum)
|
||||||
(N . -> . N))]
|
(N . -> . -InexactComplex))]
|
||||||
[inexact->exact (cl->*
|
[inexact->exact (cl->*
|
||||||
(-Real . -> . -ExactRational)
|
(-Real . -> . -ExactRational)
|
||||||
(N . -> . N))]
|
(N . -> . N))]
|
||||||
|
@ -208,33 +218,47 @@
|
||||||
[ceiling rounder]
|
[ceiling rounder]
|
||||||
[truncate rounder]
|
[truncate rounder]
|
||||||
[round rounder]
|
[round rounder]
|
||||||
[make-rectangular (-Real -Real . -> . N)]
|
[make-rectangular (cl->* (-Flonum -Flonum . -> . -InexactComplex)
|
||||||
[make-polar (-Real -Real . -> . N)]
|
(-Real -Real . -> . N))]
|
||||||
[real-part (N . -> . -Real)]
|
[make-polar (cl->* (-Flonum -Flonum . -> . -InexactComplex)
|
||||||
[imag-part (N . -> . -Real)]
|
(-Real -Real . -> . N))]
|
||||||
[magnitude (N . -> . -Real)]
|
[real-part (cl->* (-InexactComplex . -> . -Flonum)
|
||||||
[angle (N . -> . -Real)]
|
(N . -> . -Real))]
|
||||||
[numerator (-Real . -> . -Real)]
|
[imag-part (cl->* (-InexactComplex . -> . -Flonum)
|
||||||
[denominator (-Real . -> . -Real)]
|
(N . -> . -Real))]
|
||||||
[rationalize (-Real -Real . -> . N)]
|
[magnitude (cl->* (-InexactComplex . -> . -Flonum)
|
||||||
|
(N . -> . -Real))]
|
||||||
|
[angle (cl->* (-InexactComplex . -> . -Flonum)
|
||||||
|
(N . -> . -Real))]
|
||||||
|
[numerator (cl->* (-ExactRational . -> . -Integer)
|
||||||
|
(-Real . -> . -Real))]
|
||||||
|
[denominator (cl->* (-ExactRational . -> . -Integer)
|
||||||
|
(-Real . -> . -Real))]
|
||||||
|
[rationalize (cl->* (-ExactRational -ExactRational . -> . -ExactRational)
|
||||||
|
(-Flonum . -> . -Flonum)
|
||||||
|
(-Real -Real . -> . N))]
|
||||||
[expt (cl->* (-Nat -Nat . -> . -Nat)
|
[expt (cl->* (-Nat -Nat . -> . -Nat)
|
||||||
(-Integer -Nat . -> . -Integer)
|
(-Integer -Nat . -> . -Integer)
|
||||||
(-Real -Integer . -> . -Real)
|
(-Real -Integer . -> . -Real)
|
||||||
|
(-InexactComplex -InexactComplex . -> . -InexactComplex)
|
||||||
(N N . -> . N))]
|
(N N . -> . N))]
|
||||||
[sqrt (cl->*
|
[sqrt (cl->*
|
||||||
(-Nat . -> . -Real)
|
(-Nat . -> . -Real)
|
||||||
|
(-InexactComplex . -> . -InexactComplex)
|
||||||
(N . -> . N))]
|
(N . -> . N))]
|
||||||
[log (cl->*
|
[log (cl->*
|
||||||
(-Pos . -> . -Real)
|
(-Pos . -> . -Real)
|
||||||
|
(-InexactComplex . -> . -InexactComplex)
|
||||||
(N . -> . N))]
|
(N . -> . N))]
|
||||||
[exp (cl->* (-Real . -> . -Real)
|
[exp (cl->* (-Real . -> . -Real)
|
||||||
|
(-InexactComplex . -> . -InexactComplex)
|
||||||
(N . -> . N))]
|
(N . -> . N))]
|
||||||
[cos (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N))]
|
[cos (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N))]
|
||||||
[sin (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N))]
|
[sin (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N))]
|
||||||
[tan (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N))]
|
[tan (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N))]
|
||||||
[acos (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N))]
|
[acos (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N))]
|
||||||
[asin (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N))]
|
[asin (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N))]
|
||||||
[atan (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (N . -> . N) (-Real -Real . -> . N))]
|
[atan (cl->* (-Flonum . -> . -Flonum) (-Real . -> . -Real) (-InexactComplex . -> . -InexactComplex) (N . -> . N) (-Real -Real . -> . N))]
|
||||||
[gcd (cl->* (null -Fixnum . ->* . -Fixnum) (null -Integer . ->* . -Integer))]
|
[gcd (cl->* (null -Fixnum . ->* . -Fixnum) (null -Integer . ->* . -Integer))]
|
||||||
[lcm (null -Integer . ->* . -Integer)]
|
[lcm (null -Integer . ->* . -Integer)]
|
||||||
|
|
||||||
|
@ -248,12 +272,16 @@
|
||||||
(-> -ExactRational -ExactRational)
|
(-> -ExactRational -ExactRational)
|
||||||
(-> -Flonum -Flonum)
|
(-> -Flonum -Flonum)
|
||||||
(-> -Real -Real)
|
(-> -Real -Real)
|
||||||
|
(-> -InexactComplex -InexactComplex)
|
||||||
(-> N N))]
|
(-> N N))]
|
||||||
[sgn (N . -> . N)]
|
[conjugate (cl->* (-InexactComplex . -> . -InexactComplex)
|
||||||
[conjugate (N . -> . N)]
|
(N . -> . N))]
|
||||||
[sinh (N . -> . N)]
|
[sinh (cl->* (-InexactComplex . -> . -InexactComplex)
|
||||||
[cosh (N . -> . N)]
|
(N . -> . N))]
|
||||||
[tanh (N . -> . N)]
|
[cosh (cl->* (-InexactComplex . -> . -InexactComplex)
|
||||||
|
(N . -> . N))]
|
||||||
|
[tanh (cl->* (-InexactComplex . -> . -InexactComplex)
|
||||||
|
(N . -> . N))]
|
||||||
|
|
||||||
;; unsafe numeric ops
|
;; unsafe numeric ops
|
||||||
[unsafe-flabs fl-unop]
|
[unsafe-flabs fl-unop]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#lang s-exp "type-env-lang.rkt"
|
#lang s-exp "type-env-lang.rkt"
|
||||||
|
|
||||||
[Complex -Number]
|
[Complex -Number]
|
||||||
|
[Inexact-Complex -InexactComplex]
|
||||||
[Number -Number]
|
[Number -Number]
|
||||||
[Integer -Integer]
|
[Integer -Integer]
|
||||||
[Real -Real]
|
[Real -Real]
|
||||||
|
|
|
@ -34,6 +34,7 @@ any expression of this type will not evaluate to a value.}
|
||||||
@deftogether[(
|
@deftogether[(
|
||||||
@defidform[Number]
|
@defidform[Number]
|
||||||
@defidform[Complex]
|
@defidform[Complex]
|
||||||
|
@defidform[Inexact-Complex]
|
||||||
@defidform[Real]
|
@defidform[Real]
|
||||||
@defidform[Float]
|
@defidform[Float]
|
||||||
@defidform[Exact-Rational]
|
@defidform[Exact-Rational]
|
||||||
|
|
|
@ -43,6 +43,9 @@
|
||||||
[(~var i (3d (conjoin number? exact? rational?))) -ExactRational]
|
[(~var i (3d (conjoin number? exact? rational?))) -ExactRational]
|
||||||
[(~var i (3d inexact-real?)) -Flonum]
|
[(~var i (3d inexact-real?)) -Flonum]
|
||||||
[(~var i (3d real?)) -Real]
|
[(~var i (3d real?)) -Real]
|
||||||
|
;; a complex number can't have an inexact imaginary part and an exact real part
|
||||||
|
[(~var i (3d (conjoin number? (lambda (x) (inexact-real? (imag-part x))))))
|
||||||
|
-InexactComplex]
|
||||||
[(~var i (3d number?)) -Number]
|
[(~var i (3d number?)) -Number]
|
||||||
[i:str -String]
|
[i:str -String]
|
||||||
[i:char -Char]
|
[i:char -Char]
|
||||||
|
|
|
@ -150,6 +150,9 @@
|
||||||
;; Numeric hierarchy
|
;; Numeric hierarchy
|
||||||
(define -Number (make-Base 'Number #'number?))
|
(define -Number (make-Base 'Number #'number?))
|
||||||
|
|
||||||
|
;; a complex number can't have an inexact imaginary part and an exact real part
|
||||||
|
(define -InexactComplex (make-Base 'InexactComplex #'(and/c number? (lambda (x) (inexact-real? (imag-part x))))))
|
||||||
|
|
||||||
(define -Flonum (make-Base 'Flonum #'inexact-real?))
|
(define -Flonum (make-Base 'Flonum #'inexact-real?))
|
||||||
|
|
||||||
(define -ExactRational
|
(define -ExactRational
|
||||||
|
|
|
@ -237,6 +237,7 @@
|
||||||
[((Base: 'Integer _) (Base: 'Number _)) A0]
|
[((Base: 'Integer _) (Base: 'Number _)) A0]
|
||||||
[((Base: 'Flonum _) (== -Real =t)) A0]
|
[((Base: 'Flonum _) (== -Real =t)) A0]
|
||||||
[((Base: 'Integer _) (== -Real =t)) A0]
|
[((Base: 'Integer _) (== -Real =t)) A0]
|
||||||
|
[((Base: 'Flonum _) (Base: 'InexactComplex _)) A0]
|
||||||
[((Base: 'Flonum _) (Base: 'Number _)) A0]
|
[((Base: 'Flonum _) (Base: 'Number _)) A0]
|
||||||
[((Base: 'Exact-Rational _) (Base: 'Number _)) A0]
|
[((Base: 'Exact-Rational _) (Base: 'Number _)) A0]
|
||||||
[((Base: 'Integer _) (Base: 'Exact-Rational _)) A0]
|
[((Base: 'Integer _) (Base: 'Exact-Rational _)) A0]
|
||||||
|
@ -263,6 +264,8 @@
|
||||||
[((== -Fixnum =t) (Base: 'Exact-Rational _)) A0]
|
[((== -Fixnum =t) (Base: 'Exact-Rational _)) A0]
|
||||||
[((== -Fixnum =t) (Base: 'Integer _)) A0]
|
[((== -Fixnum =t) (Base: 'Integer _)) A0]
|
||||||
|
|
||||||
|
[((Base: 'InexactComplex _) (Base: 'Number _)) A0]
|
||||||
|
|
||||||
|
|
||||||
;; values are subtypes of their "type"
|
;; values are subtypes of their "type"
|
||||||
[((Value: (? exact-integer? n)) (Base: 'Integer _)) A0]
|
[((Value: (? exact-integer? n)) (Base: 'Integer _)) A0]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user