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

Add non-finite floats and clarify signed zeros #506

Merged
merged 4 commits into from
Nov 29, 2017

Conversation

mojombo
Copy link
Member

@mojombo mojombo commented Nov 28, 2017

Closes #389.

This adds support for non-finite float values (-inf, inf, +inf, nan) and clarifies that signed zeros (integer and float) are valid and what they mean.

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

🎉

Values such as "infinity" and "not a number" that cannot be expressed as a
series of digits are not allowed.
Leading zeros are not allowed. Integer values `-0` and `+0` are valid and
identical to an unprefixed zero. Hex, octal, and binary forms are not allowed.
Copy link
Member

Choose a reason for hiding this comment

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

#409?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, one thing at a time!

README.md Outdated

64 bit (signed long) range expected (−9,223,372,036,854,775,808 to
9,223,372,036,854,775,807).

Float
-----

Floats should be implemented as 64-bit IEEE 754 values.
Copy link
Member

Choose a reason for hiding this comment

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

It should say IEEE 754 binary64 values, since there's a 64-bit decimal64 as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, fair enough, will change.

README.md Outdated
nf1 = +inf # positive infinity
nf2 = inf # positive infinity
nf3 = -inf # negative infinity
nf4 = nan # not a number
Copy link
Member

Choose a reason for hiding this comment

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

IEEE 754 has 2 types of NaNs -- sNaN and qNaN.

It might be worthwhile to mention that which one it is would be implementation dependant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, and many of each! I'll add a note as you suggest.

toml.abnf Outdated
@@ -117,14 +117,19 @@ underscore = %x5F ; _

;; Float

float = integer ( frac / ( frac exp ) / exp )
float = integer ( frac / ( frac exp ) / exp )
Copy link
Member

Choose a reason for hiding this comment

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

maybe now would be a good time to change this to?

float = integer ( exp / frac [ exp ] )

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems reasonable.

toml.abnf Outdated
@@ -117,14 +117,19 @@ underscore = %x5F ; _

;; Float

float = integer ( frac / ( frac exp ) / exp )
float = integer ( frac / ( frac exp ) / exp )
float =/ non-finite
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call them "named float values"?

Copy link
Member Author

Choose a reason for hiding this comment

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

From a bit of googling, it seems like "special values" is the preferred nomenclature. How does that strike you?

Copy link
Member

Choose a reason for hiding this comment

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

Works well. :)

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

Happy to see this go as is.

toml.abnf Outdated
@@ -117,14 +117,19 @@ underscore = %x5F ; _

;; Float

float = integer ( frac / ( frac exp ) / exp )
float = integer ( exp / frac [ exp ] )
float =/ non-finite
Copy link
Member

Choose a reason for hiding this comment

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

float-special-values then?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with just special-float. values seems redundant.

Copy link
Member

@pradyunsg pradyunsg Nov 28, 2017

Choose a reason for hiding this comment

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

special-float works. :)

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

I'll pretend I needed to approve. ;)

@mojombo
Copy link
Member Author

mojombo commented Nov 28, 2017

@pradyunsg Haha, thanks. =) I'll wait for a few more thoughts from others before final merge.

@mojombo mojombo mentioned this pull request Nov 28, 2017
Copy link

@StefanKarpinski StefanKarpinski left a comment

Choose a reason for hiding this comment

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

Minor comments, but overall LGTM.

toml.abnf Outdated

frac = decimal-point zero-prefixable-int
decimal-point = %x2E ; .
zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT )

exp = "e" integer

special-float = ( [ minus / plus ] inf ) / nan

Choose a reason for hiding this comment

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

I wonder if allowing ± in front of nan also would be simpler – keeping the universal rule that numbers can have a sign prefix. Of course +nan, nan and -nan would all mean the same thing, but it could be simpler. Not a big issue, just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an interesting point. It would keep the consistency across all values, which would be a nice behavior. I suppose if the implementation wanted to, it could carry over the sign to the NaN value, even though it's insignificant, but who knows!

CHANGELOG.md Outdated
@@ -2,6 +2,7 @@

## HEAD

* Add non-finite float values (+inf, inf, -inf, nan)

Choose a reason for hiding this comment

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

Perhaps only list one of +inf and inf here – since this says "values" and those are the same value written with different syntaxes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough, will tighten in up.

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.

4 participants