Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of other real types (Float32, auxiliary) #1929

Closed
wants to merge 8 commits into from
8 changes: 6 additions & 2 deletions src/auxiliary/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ Given ε = 1.0e-4, we use the following algorithm.
[https://www.agner.org/optimize/instruction_tables.pdf](https://www.agner.org/optimize/instruction_tables.pdf)
"""
@inline function ln_mean(x, y)
RealT = eltype(x)
epsilon_f2 = 1.0e-4
f2 = (x * (x - 2 * y) + y * y) / (x * (x + 2 * y) + y * y) # f2 = f^2
if f2 < epsilon_f2
return (x + y) / @evalpoly(f2, 2, 2/3, 2/5, 2/7)
return (x + y) / @evalpoly(f2, 2, convert(RealT, 2 / 3), convert(RealT, 2 / 5),
convert(RealT, 2 / 7))
else
huiyuxie marked this conversation as resolved.
Show resolved Hide resolved
return (y - x) / log(y / x)
end
Expand All @@ -171,10 +173,12 @@ logarithmic mean is needed, by replacing a (slow) division by a (fast)
multiplication.
"""
@inline function inv_ln_mean(x, y)
RealT = eltype(x)
epsilon_f2 = 1.0e-4
f2 = (x * (x - 2 * y) + y * y) / (x * (x + 2 * y) + y * y) # f2 = f^2
if f2 < epsilon_f2
return @evalpoly(f2, 2, 2/3, 2/5, 2/7) / (x + y)
return @evalpoly(f2, 2, convert(RealT, 2 / 3), convert(RealT, 2 / 5),
convert(RealT, 2 / 7)) / (x + y)
huiyuxie marked this conversation as resolved.
Show resolved Hide resolved
else
return log(y / x) / (y - x)
end
Expand Down
Loading