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

Correct exponent_max to conform to IEEE754-2008 #24978

Closed
wants to merge 2 commits into from

Conversation

mschauer
Copy link
Contributor

@mschauer mschauer commented Dec 7, 2017

exponent_max was not giving the maximum exponent, but a sentinel value for Inf and NaN which is not a legal exponent. I found this error prone. Exponent exponent_max returns actual maximum exponent. As a by-product the code become somewhat more readable. ("if k is one bigger than the maximum exponent, first multiply y with 2 and then with the highest power of two representable...") I added internal docstrings to help the future readers.

@simonbyrne
Copy link
Contributor

Do we need this? What's wrong with exponent(realmax(T))?

@simonbyrne
Copy link
Contributor

See also #24631

@simonbyrne
Copy link
Contributor

I would be in favour of renaming exponent_max to exponent_raw_max though.

@JeffreySarnoff
Copy link
Contributor

Julia has been assigning exponent_max values that do not conform to IEEE754-2008,

exponent_max (Emax in the Standard) has a tabulated value for each floating point type.

#   These are the tabulated values (see Table 3.2 on page 8 of the IEEE Standard).

exponent_max(::Type{Float16}) =   15
exponent_max(::Type{Float32}) =  127
exponent_max(::Type{Float64}) = 1023

All the details are here: https://github.com/JeffreySarnoff/IEEE754-2008.md.

@mschauer
Copy link
Contributor Author

mschauer commented Dec 8, 2017

exponent(realmax(T)) does give Emax, but there is some cognitive ballast asserting that it does to it.

@JeffreySarnoff
Copy link
Contributor

As I understand the writing, Emax is one of their essential quantities. Since Emin is, by design, 1-Emax always, and that almost evenly biased exponents are used, Emax is another way of writing exponent_bias (bias). The fact that exponent(realmax(T)) also resolves as Emax(T) is more a consistency check than definitional -- I agree with your observation.

@mschauer
Copy link
Contributor Author

mschauer commented Nov 2, 2018

Ping

@JeffreySarnoff
Copy link
Contributor

It seems there are no problems with this (I dunno what Xcode failure is).

@mschauer mschauer closed this Nov 2, 2018
@mschauer mschauer reopened this Nov 2, 2018
@JeffreySarnoff
Copy link
Contributor

the freebsd link is to nowhere

@mschauer
Copy link
Contributor Author

mschauer commented Nov 3, 2018

A helpful fairy fixed the tests.

@JeffreySarnoff
Copy link
Contributor

super -- I await the merge!

@mschauer mschauer changed the title Rectify exponent_max Correct exponent_max to conform to IEEE754-2008 Sep 3, 2019
@mschauer
Copy link
Contributor Author

mschauer commented Sep 3, 2019

This is still good to go.

@JeffreySarnoff
Copy link
Contributor

^ (any reason not to merge this)?

@simonbyrne
Copy link
Contributor

I'm in favour of this. Since it is a change, should probably be documented in NEWS.md

@mschauer
Copy link
Contributor Author

mschauer commented Sep 5, 2019

Yes. BTW pkg.julialang.com shows no use, only @JeffreySarnoff providing the functionality independently in https://github.com/JeffreySarnoff/LowLevelFloatFunctions.jl

@mschauer
Copy link
Contributor Author

mschauer commented Sep 5, 2019

What is the right header for the NEW item?

  • The unexported and previously undocumented function exponent_max now returns the actual maximum exponent according to IEEE754-2008, not the sentinel value.

@simonbyrne
Copy link
Contributor

Ah, if it's not exported it probably doesn't need an item.

Copy link
Contributor

@simonbyrne simonbyrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to link to exponent help.

base/math.jl Outdated Show resolved Hide resolved
@mschauer mschauer closed this Sep 5, 2019
@mschauer mschauer reopened this Sep 5, 2019
@mschauer mschauer closed this Sep 6, 2019
@mschauer mschauer reopened this Sep 6, 2019
@mschauer
Copy link
Contributor Author

mschauer commented Sep 6, 2019

Something with the CI is failing currently, I think unrelatedly to this change. I'll leave it and maybe someone with rights can trigger the tests when things run smoothly again.

@mschauer
Copy link
Contributor Author

Ping

@simonbyrne simonbyrne closed this Sep 14, 2019
@simonbyrne simonbyrne reopened this Sep 14, 2019
@musm musm added the domain:maths Mathematical functions label Dec 11, 2020
@musm
Copy link
Contributor

musm commented Dec 11, 2020

Needs a rebase

@mschauer
Copy link
Contributor Author

I am out, honestly

@JeffreySarnoff
Copy link
Contributor

JeffreySarnoff commented Dec 13, 2020

@admin fyi^

@musm
Copy link
Contributor

musm commented Dec 13, 2020

@mschauer Sorry I didn't understand this comment? Do you mean you are no longer interested in rebasing this? Thanks.

@StefanKarpinski
Copy link
Sponsor Member

That was my interpretation of the comment and frankly it's pretty understandable given that it's been three years.

@JeffreySarnoff
Copy link
Contributor

I concur. Would an appropriate admin rebase this, please.

@musm
Copy link
Contributor

musm commented Dec 13, 2020

I'll try to get around to rebasing this soon. Thanks for the effort @mschauer

@musm
Copy link
Contributor

musm commented Dec 17, 2020

#38929

@musm musm closed this Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants