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

significand, frexp not defined #29

Closed
mcabbott opened this issue May 9, 2022 · 2 comments
Closed

significand, frexp not defined #29

mcabbott opened this issue May 9, 2022 · 2 comments

Comments

@mcabbott
Copy link

mcabbott commented May 9, 2022

julia> significand(Float64x2(123.4))
ERROR: MethodError: no method matching significand(::MultiFloat{Float64, 2})
Closest candidates are:
  significand(::T) where T<:Union{Float16, Float32, Float64} at math.jl:896
  significand(::DoubleFloat{T}) where T<:Union{Float16, Float32, Float64} at ~/.julia/packages/DoubleFloats/h3HrU/src/math/prearith/prearith.jl:68
  significand(::BigFloat) at mpfr.jl:873
...

julia> significand(123.4)
1.928125

Xref JuliaMath/DoubleFloats.jl#148

@mcabbott
Copy link
Author

More useful is probably frexp, also not defined though:

julia> frexp(Float64x2(123.4))
ERROR: MethodError: no method matching frexp(::MultiFloat{Float64, 2})
Closest candidates are:
  frexp(::T) where T<:Union{Float16, Float32, Float64} at math.jl:921
  frexp(::DoubleFloat{T}) where T<:Union{Float16, Float32, Float64} at ...
  frexp(::BigFloat) at mpfr.jl:866

@mcabbott mcabbott changed the title significand not defined significand, frexp not defined May 10, 2022
@dzhang314
Copy link
Owner

Hey @mcabbott, thanks for your interest in MultiFloats.jl! This is a good suggestion, and I am interested in having standard floating-point introspection methods work for MultiFloat types. However, it is actually impossible to implement significand and frexp for the multi-limb representation used by MultiFloats.jl without possible accuracy loss.

The core issue is this: imagine you have a Float64x2 with limbs (1.0e+308, 1.0e-308). If you call significand or frexp on this number, it has to be scaled down by a factor of 10308, which will cause the second limb to underflow to zero. This dramatically reduces the precision of the result.

For this reason, I don't want to provide significand and frexp functions in MultiFloats.jl, as they are typically specified to be lossless operations. However, I recognize that these operations are still useful in a lossy form (e.g., for implementing transcendental functions), so if you have a use case for them, I would be happy to provide MultiFloats.lossy_significand and MultiFloats.lossy_frexp functions.

If you would like this functionality, please feel free to leave another comment and reopen this thread. Until then, I will close this issue.

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