-
Notifications
You must be signed in to change notification settings - Fork 33
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
invalid sqrt
and cbrt
result on subnormal numbers
#166
Comments
Thank you. This is an issue. |
!! cbrt has a similar and more widespread problem !!
|
Worth noting |
Thanks for the comments.
It's hard to propose something without knowing the internal more. |
Would you consider |
I'm not sure I follow (do you imply truncating ?). The following fixes my issue for diff --git a/src/math/ops/op_dd_dd.jl b/src/math/ops/op_dd_dd.jl
index ea3ea7a..1ad0818 100644
--- a/src/math/ops/op_dd_dd.jl
+++ b/src/math/ops/op_dd_dd.jl
@@ -59,6 +59,7 @@ end
function sqrt_dd_dd(x::Tuple{T,T}) where {T<:IEEEFloat}
(isnan(HI(x)) | iszero(HI(x))) && return x
signbit(HI(x)) && throw(DomainError("sqrt(x) expects x >= 0"))
+ issubnormal(HI(x)) && return x
half = T(0.5)
dhalf = (half, zero(T)) |
I was suggesting something like this, so there is some square root used
|
That would enhance the current (consistent with |
This also seems to fix function cbrt_dd_dd(a::Tuple{T,T}) where {T<:IEEEFloat}
- hi, lo = HILO(a)
+ issubnormal(HI(a)) && return DoubleFloat{T}(cbrt(HI(a)), zero(T))
a2 = mul_dddd_dd(a,a)
one1 = one(T)
onethird = (0.3333333333333333, 1.850371707708594e-17) |
thanks for the PR |
sqrt
and cbrt
result on subnormal numbers
For sqrt, I think the alternative algorithm proposed in issue #187 handles subnormals without issue (and is faster). That said, my opinion is that subnormals should not exist (flush to zero is sometimes implemented by hardware). If you hit the subnormal range, you are in hazardous terrain anyway and I would not mind DoubleFloats.jl giving no guarantee in subnormal range rather than being slowed down by many checks for special cases... |
I'm hitting
NaN
s in my codes, induced by callingsqrt
on subnormal numbers, with inconsistencies w.r.t Float64:Maybe related to #151, but subnormal numbers are more annoying than overflows.
The text was updated successfully, but these errors were encountered: