1+ module PTYQoLIrrationalConstantsExt
2+
3+ using IrrationalConstants
4+ import Base: + , - , * , / , inv, sqrt, exp, log
5+
6+ # x+x=2x, 2x-x=x, x/2x=1/2, 2x/x=2
7+ for (x, halfx) in ((halfπ,quartπ), (π,halfπ), (twoπ,π), (fourπ,twoπ), (inv2π,inv4π), (invπ,inv2π), (twoinvπ,invπ), (fourinvπ,twoinvπ), (sqrt2,invsqrt2), (sqrt2π,sqrthalfπ), (sqrt4π,sqrtπ))
8+ @eval + (:: $ (typeof (halfx)), :: $ (typeof (halfx))) = $ x
9+ @eval - (:: $ (typeof (x)), :: $ (typeof (halfx))) = $ halfx
10+ @eval / (:: $ (typeof (halfx)), :: $ (typeof (x))) = 1 / 2
11+ @eval / (:: $ (typeof (x)), :: $ (typeof (halfx))) = 2
12+ end
13+
14+ # x*inv(x)=1
15+ for (x,invx) in ((quartπ,fourinvπ), (halfπ,twoinvπ), (π,invπ), (twoπ,inv2π), (fourπ,inv4π), (sqrt2,invsqrt2), (sqrtπ,invsqrtπ), (sqrt2π,invsqrt2π))
16+ @eval inv (:: $ (typeof (x))) = $ invx
17+ @eval inv (:: $ (typeof (invx))) = $ x
18+ @eval * (:: $ (typeof (x)), :: $ (typeof (invx))) = 1
19+ @eval * (:: $ (typeof (invx)), :: $ (typeof (x))) = 1
20+ end
21+
22+ # sqrt(x)*sqrt(x)=x, x/sqrt(x)=sqrt(x)
23+ for (x,sqrtx) in ((π,sqrtπ), (twoπ,sqrt2π), (fourπ,sqrt4π), (halfπ,sqrthalfπ), (invπ,invsqrtπ), (inv2π,invsqrt2π))
24+ @eval sqrt (:: $ (typeof (x))) = $ sqrtx
25+ @eval * (:: $ (typeof (sqrtx)), :: $ (typeof (sqrtx))) = $ x
26+ @eval / (:: $ (typeof (x)), :: $ (typeof (sqrtx))) = $ sqrtx
27+ @eval / (:: $ (typeof (sqrtx)), :: $ (typeof (x))) = inv ($ sqrtx)
28+ end
29+
30+ # exp(log(x))=x
31+ for (x,logx) in ((π,logπ), (twoπ,log2π), (fourπ,log4π))
32+ @eval log (:: $ (typeof (x))) = $ logx
33+ @eval exp (:: $ (typeof (logx))) = $ x
34+ end
35+
36+ end # module
0 commit comments