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

Explicitly define an Inf64 and NaN64 #11841

Merged
merged 1 commit into from
Jun 25, 2015
Merged

Explicitly define an Inf64 and NaN64 #11841

merged 1 commit into from
Jun 25, 2015

Conversation

dphildebrandt
Copy link

Currently we have 32-bit version of Inf and NaN (Inf32 and NaN32) but regular Inf and NaN are assumed 64-bit. This fix creates an explicit NaN64 and Inf64 with NaN and Inf being set to the appropriate type, in the style of Int etc.

@jiahao
Copy link
Member

jiahao commented Jun 24, 2015

There is no such thing as a "native" bit depth affinity for floating point like there are for integers.

@tkelman
Copy link
Contributor

tkelman commented Jun 24, 2015

Int === typeof(1), whereas floating-point literals are always Float64 regardless of architecture. There are past (closed, most likely) issues for a Float typealias. There's no reason to do this only for Inf and NaN.

@dphildebrandt
Copy link
Author

Then why are Inf16, Inf32, NaN16 and NaN32 defined at all? It seems inconsistent. I was thinking either also introduce the Inf64/NaN64 definition as well or remove the others? Or define Inf64/NaN64 but always have Inf set to it; ie. remove the if-statement is check in this commit.

@dphildebrandt dphildebrandt changed the title Inf and NaN set to 64-bit or 32-bit depending on system architecture. Explicitly define an Inf64 and NaN64 Jun 24, 2015
@tkelman
Copy link
Contributor

tkelman commented Jun 24, 2015

Introducing Inf64 and NaN64 sounds reasonable to me for consistency's sake. Others should chime in.

@StefanKarpinski
Copy link
Member

Yes, it seems reasonable to me too. In particular, it would be pathological for those names to mean anything else, so why not have them? They should also be exported here.

@ScottPJones
Copy link
Contributor

Is there anything to show the quiet or signaling bit, sign bit, and payload of a NaN?
Also, if you are going to have these, you may also need Inf, -Inf NaN etc. for decimal floating point,
possibly defined for different sizes (important for NaN, where the payload size is different).
Also, I don't understand why Inf16, Inf32, and now Inf64 are defined... I would have thought that those should be identical, across all sizes of Float. NaN16, etc. does make sense to me...

@ScottPJones
Copy link
Contributor

Does Inf16 not === Inf?

@StefanKarpinski
Copy link
Member

That seems like a fairly easy question to get an answer to...

@StefanKarpinski
Copy link
Member

Can you squash this into one commit?

@ScottPJones
Copy link
Contributor

I keep forgetting, tone is lost on the Internet! I really meant, "shouldn't they be identical?"
Anyway, I've seen that Float16(0) also is not viewed as identical to 0.0, so I guess it's consistent.

@tkelman
Copy link
Contributor

tkelman commented Jun 24, 2015

lgtm, should merge as long as travis is green. AppVeyor has a backlog in the queue, and is likely to fail right now anyway due to #11818, so not 100% necessary to wait for it here.

@StefanKarpinski
Copy link
Member

Two values are === if and only if you can cannot write a program that distinguishes them:

julia> typeof(Inf)
Float64

julia> typeof(Inf16)
Float16

@ScottPJones
Copy link
Contributor

OK... another fun thing: why does julia give different bitpatterns than C/C++ for NaNs?
In C/C++, I get:
f = 7ff8000000000000, g = 7ff8000000000000
for both -0.0/0.0 and 0.0/0.0.
In Julia, I get a negative NaN for both: 0xfff8000000000000

@StefanKarpinski
Copy link
Member

Not sure what C/C++ is doing, but we're just calling the divsd instruction.

tkelman added a commit that referenced this pull request Jun 25, 2015
Explicitly define an Inf64 and NaN64
@tkelman tkelman merged commit 89e0871 into JuliaLang:master Jun 25, 2015
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.

5 participants