@@ -19,7 +19,13 @@ const diadic = [max, min, hypot, atan, mod, rem, copysign,
1919 polygamma, beta, logbeta]
2020const previously_declared_for = Set ([])
2121
22- # TODO : it's not possible to dispatch on the symtype! (only problem is Parameter{})
22+ # ################### SafeReal #########################
23+ export SafeReal
24+
25+ # ideally the relationship should be the other way around
26+ abstract type SafeReal <: Real end
27+
28+ # ######################################################
2329
2430assert_like (f, T) = nothing
2531function assert_like (f, T, a, b... )
@@ -86,19 +92,44 @@ for f in diadic
8692 @eval promote_symtype (:: $ (typeof (f)),
8793 T:: Type{<:Number} ,
8894 S:: Type{<:Number} ) = promote_type (T, S)
95+ @eval function promote_symtype (:: $ (typeof (f)),
96+ T:: Type{<:SafeReal} ,
97+ S:: Type{<:Real} )
98+ X = promote_type (T, Real)
99+ X == Real ? SafeReal : X
100+ end
101+ @eval function promote_symtype (:: $ (typeof (f)),
102+ T:: Type{<:Real} ,
103+ S:: Type{<:SafeReal} )
104+ X = promote_type (Real, S)
105+ X == Real ? SafeReal : X
106+ end
107+ @eval function promote_symtype (:: $ (typeof (f)),
108+ T:: Type{<:SafeReal} ,
109+ S:: Type{<:SafeReal} )
110+ X = promote_type (Real, Real)
111+ X == Real ? SafeReal : X
112+ end
89113end
90114
91115for f in [+ , - , * , \ , / , ^ ]
92116 @eval promote_symtype (:: $ (typeof (f)),
93117 T:: Type{<:Number} ,
94118 S:: Type{<:Number} ) = promote_type (T, S)
119+ @eval function promote_symtype (:: $ (typeof (f)),
120+ T:: Type{<:SafeReal} ,
121+ S:: Type{<:Number} )
122+ X = promote_type (Real, S)
123+ X == Real ? SafeReal : X
124+ end
95125end
96126
97127promote_symtype (:: typeof (rem2pi), T:: Type{<:Number} , mode) = T
98128Base. rem2pi (x:: Symbolic{<:Number} , mode:: Base.RoundingMode ) = term (rem2pi, x, mode)
99129
100130for f in monadic
101131 @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:Number} ) = promote_type (T, Real)
132+ @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:SafeReal} ) = SafeReal
102133 @eval (:: $ (typeof (f)))(a:: Symbolic{<:Number} ) = term ($ f, a)
103134end
104135
0 commit comments