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

Absolute value is broken for ArbComplex #55

Closed
DanielVandH opened this issue Jul 30, 2022 · 2 comments
Closed

Absolute value is broken for ArbComplex #55

DanielVandH opened this issue Jul 30, 2022 · 2 comments

Comments

@DanielVandH
Copy link

DanielVandH commented Jul 30, 2022

Maybe I'm doing something wrong, but absolute values on ArbComplex returns zero every time:

julia> z = 0.5 + 0.3im;

julia> abs(z)
0.5830951894845301

julia> z = ArbComplex(0.5, 0.3)
0.5 + 0.2999999999999999888977697537484im

julia> abs(z)
0

The issue seems to be with z = ArbReal{P}() in

function abs(x::ArbComplex{P}) where {P}
z = ArbReal{P}()
ccall(@libarb(acb_abs), Cvoid, (Ref{ArbComplex}, Ref{ArbComplex}, Clong), z, x, P)
return z
end
. If I instead use this method:

function _abs(x::ArbComplex{P}) where {P}
    z = ArbComplex{P}()
    ccall(ArbNumerics.@libarb(acb_abs), Cvoid, (Ref{ArbComplex}, Ref{ArbComplex}, Clong), z, x, P)
    return real(z)
end
_abs(ArbComplex(0.5, 0.3, bits=256))
abs(0.5 + 0.3im)
julia> _abs(ArbComplex(0.5, 0.3, bits=256))
0.58309518948453004137536495027902554867375965029811700288720077783633574140908

julia> abs(0.5 + 0.3im)
0.5830951894845301

Then it seems to work.

@JeffreySarnoff
Copy link
Owner

thank you for this

@JeffreySarnoff
Copy link
Owner

fixed in master, merge pending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants