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

Fix overflow for hypot in Float16 #38322

Merged
merged 3 commits into from
Dec 4, 2020
Merged

Fix overflow for hypot in Float16 #38322

merged 3 commits into from
Dec 4, 2020

Conversation

simonbyrne
Copy link
Contributor

Fixes #38311, includes tests from #38272.

@KristofferC KristofferC added this to the 1.6 features milestone Nov 17, 2020
@KristofferC
Copy link
Member

Bump, here's another one from PkgEval:

julia> hypot(Float16(0.004406) - Float16(0.01092)im)
NaN16

@JeffBezanson
Copy link
Member

Bump. Looks like this has some test failures?

@JeffBezanson
Copy link
Member

Bump.

@stevengj
Copy link
Member

stevengj commented Dec 1, 2020

Wouldn't we be better off doing the Float16 calculations as:

_hypot(x::Float16, y::Float16) = Float16(_hypot(Float32(x), Float32(y)))
_hypot(x::ComplexF16, y::ComplexF16) = Float16(_hypot(ComplexF32(x), ComplexF32(y)))

Though I guess we can do that in addition to this PR, since there might be other types (e.g. quaternions) defined in packages whose absolute value gives a Float16.

@simonbyrne
Copy link
Contributor Author

I think that is the best way forward. I don't think it is possible to handle Float16 without at least some special casing, simply because the subnormal range is so wide compared to the exponent range.

@simonbyrne simonbyrne closed this Dec 1, 2020
@simonbyrne simonbyrne reopened this Dec 1, 2020
@stevengj stevengj merged commit 8dd959e into master Dec 4, 2020
@stevengj stevengj deleted the sb/hypot-float16 branch December 4, 2020 01:14
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

Successfully merging this pull request may close these issues.

hypot for Float16 regressed
5 participants