Skip to content

Arithmetic operators allow manifesting NaN #47

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

Closed
dhaffey opened this issue Apr 22, 2015 · 5 comments
Closed

Arithmetic operators allow manifesting NaN #47

dhaffey opened this issue Apr 22, 2015 · 5 comments
Labels

Comments

@dhaffey
Copy link

dhaffey commented Apr 22, 2015

$ jsonnet -e '1e309 - 1e309'
-nan
@sparkprime
Copy link
Collaborator

I think you need #2 to get the behavior you're looking for?

@dhaffey
Copy link
Author

dhaffey commented Apr 23, 2015

The spec mentioned "floating-point arithmetic", so I'd already assumed IEEE doubles. It's more an issue of consistently handling special float values and avoiding invalid JSON output (eg, "1 / 0" sensibly produces an error rather than manifesting "inf").

Switching to arbitrary-precision rationals would certainly do the trick. Though std.sin and friends may get a little trickier to implement :)

@dhaffey
Copy link
Author

dhaffey commented Apr 23, 2015

On a related note:

$ jsonnet -e 1e309
inf

@sparkprime
Copy link
Collaborator

Ah yes, I had forgotten that JSON does not allow these values. So the question is, should they generate errors whenever they appear as immediate values (fail fast) or should there only be an error if they reach manifestation time. It seems to me that the latter behavior will be quite annoying. The NaN / inf will propagate through values and it will be hard to know where it originally came from. I can't think of any compelling use cases for allowing NaN and inf in a config language.

@sparkprime sparkprime added bug and removed duplicate labels Apr 23, 2015
@dhaffey
Copy link
Author

dhaffey commented Apr 23, 2015

+1 for failing fast. NaN is an atrocity, and the best argument I can think of for allowing an intermediate inf is that it's occasionally convenient as an initial value in algorithms like computing a minimum. Not very compelling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants