JuliaMath / JuliaMath/DoubleFloats.jl
`exponent` and `significand` functions
- Dominant language
- Julia
- Stars
- 172
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
The exponent function gives an error on Double64, and does not seem to be covered by tests: https://app.codecov.io/gh/JuliaMath/DoubleFloats.jl/blob/master/src/math/prearith/prearith.jl
```julia
julia> exponent(123.4)
6
julia> exponent(Double64(123.4))
ERROR: DomainError with 0.0:
Cannot be ±0.0.
Stacktrace:
[1] (::Base.Math.var"#throw2#6")(x::Float64)
@ Base.Math ./math.jl:846
[2] exponent
@ ./math.jl:851 [inlined]
[3] exponent(x::Double64)
@ DoubleFloats ~/.julia/packages/DoubleFloats/h3HrU/src/math/prearith/prearith.jl:64
julia> exponent(big(123.4))
6
```
I think it's calling `exponent(0.0)`, to make a tuple, like that made by `significand`:
```julia
julia> significand(123.4)
1.928125
julia> significand(Double64(123.4))
(1.928125, 0.0)
julia> significand(big(123.4))
1.928125000000000088817841970012523233890533447265625
```
More generally, is this the right thing to return? I would expect the results to obey `x == significand(x) * 2^exponent(x)`, but this isn't possible if they return tuples. Maybe `significand` should return another Double64? If these tuples are needed, they could be internal functions, not overloads of Base.
The context is that it would be nice if https://github.com/JuliaStats/LogExpFunctions.jl/pull/48 could work on AbstractFloat.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.