@@ -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... )
8288@number_methods (Pow, term (f, a), term (f, a, b), skipbasics)
8389@number_methods (Div, term (f, a), term (f, a, b), skipbasics)
8490
85- for f in diadic
86- @eval promote_symtype (:: $ (typeof (f)),
87- T:: Type{<:Number} ,
88- S:: Type{<:Number} ) = promote_type (T, S)
89- end
90-
91- for f in [+ , - , * , \ , / , ^ ]
91+ for f in vcat (diadic, [+ , - , * , \ , / , ^ ])
9292 @eval promote_symtype (:: $ (typeof (f)),
9393 T:: Type{<:Number} ,
9494 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
95113end
96114
97115promote_symtype (:: typeof (rem2pi), T:: Type{<:Number} , mode) = T
98116Base. rem2pi (x:: Symbolic{<:Number} , mode:: Base.RoundingMode ) = term (rem2pi, x, mode)
99117
100118for f in monadic
101119 @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:Number} ) = promote_type (T, Real)
120+ @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:SafeReal} ) = SafeReal
102121 @eval (:: $ (typeof (f)))(a:: Symbolic{<:Number} ) = term ($ f, a)
103122end
104123
0 commit comments