@@ -19,12 +19,18 @@ const diadic = [max, min, hypot, atan, mod, rem, copysign,
1919 polygamma, beta, logbeta]
2020const previously_declared_for = Set ([])
2121
22+ const basic_monadic = [- , + ]
23+ const basic_diadic = [+ , - , * , / , // , \ , ^ ]
2224# ################### SafeReal #########################
23- export SafeReal
25+ export SafeReal, LiteralReal
2426
2527# ideally the relationship should be the other way around
2628abstract type SafeReal <: Real end
2729
30+ # ################## LiteralReal #######################
31+
32+ abstract type LiteralReal <: Real end
33+
2834# ######################################################
2935
3036assert_like (f, T) = nothing
@@ -41,14 +47,13 @@ function number_methods(T, rhs1, rhs2, options=nothing)
4147 exprs = []
4248
4349 skip_basics = options != = nothing ? options == :skipbasics : false
50+ only_basics = options != = nothing ? options == :onlybasics : false
4451 skips = Meta. isexpr (options, [:vcat , :hcat , :vect ]) ? Set (options. args) : []
45- basic_monadic = [- , + ]
46- basic_diadic = [+ , - , * , / , // , \ , ^ ]
4752
4853 rhs2 = :($ assert_like (f, Number, a, b); $ rhs2)
4954 rhs1 = :($ assert_like (f, Number, a); $ rhs1)
5055
51- for f in (skip_basics ? diadic : vcat (basic_diadic, diadic))
56+ for f in (skip_basics ? diadic : only_basics ? basic_diadic : vcat (basic_diadic, diadic))
5257 nameof (f) in skips && continue
5358 for S in previously_declared_for
5459 push! (exprs, quote
@@ -69,7 +74,7 @@ function number_methods(T, rhs1, rhs2, options=nothing)
6974 push! (exprs, expr)
7075 end
7176
72- for f in (skip_basics ? monadic : vcat (basic_monadic, monadic))
77+ for f in (skip_basics ? monadic : only_basics ? basic_monadic : vcat (basic_monadic, monadic))
7378 nameof (f) in skips && continue
7479 push! (exprs, :((f:: $ (typeof (f)))(a:: $T ) = $ rhs1))
7580 end
8792@number_methods (Mul, term (f, a), term (f, a, b), skipbasics)
8893@number_methods (Pow, term (f, a), term (f, a, b), skipbasics)
8994@number_methods (Div, term (f, a), term (f, a, b), skipbasics)
95+ @number_methods (Sym{<: LiteralReal }, term (f, a), term (f, a, b), onlybasics)
96+ @number_methods (Term{<: LiteralReal }, term (f, a), term (f, a, b), onlybasics)
9097
9198for f in vcat (diadic, [+ , - , * , \ , / , ^ ])
9299 @eval promote_symtype (:: $ (typeof (f)),
93100 T:: Type{<:Number} ,
94101 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
102+ for R in [SafeReal, LiteralReal]
103+ @eval function promote_symtype (:: $ (typeof (f)),
104+ T:: Type{<:$R} ,
105+ S:: Type{<:Real} )
106+ X = promote_type (T, Real)
107+ X == Real ? $ R : X
108+ end
109+ @eval function promote_symtype (:: $ (typeof (f)),
110+ T:: Type{<:Real} ,
111+ S:: Type{<:$R} )
112+ X = promote_type (Real, S)
113+ X == Real ? $ R : X
114+ end
115+ @eval function promote_symtype (:: $ (typeof (f)),
116+ T:: Type{<:$R} ,
117+ S:: Type{<:$R} )
118+ $ R
119+ end
112120 end
113121end
114122
@@ -118,6 +126,7 @@ Base.rem2pi(x::Symbolic{<:Number}, mode::Base.RoundingMode) = term(rem2pi, x, mo
118126for f in monadic
119127 @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:Number} ) = promote_type (T, Real)
120128 @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:SafeReal} ) = SafeReal
129+ @eval promote_symtype (:: $ (typeof (f)), T:: Type{<:LiteralReal} ) = LiteralReal
121130 @eval (:: $ (typeof (f)))(a:: Symbolic{<:Number} ) = term ($ f, a)
122131end
123132
0 commit comments