Skip to content

Clarify that Float does not include NaN or infinity #780

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

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ encoding integer numbers larger than 32-bit.

### Float

The Float scalar type represents signed double-precision fractional values
as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
Response formats that support an appropriate double-precision number type
should use that type to represent this scalar.
The Float scalar type represents signed double-precision finite values as
specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
Response formats that support an appropriate double-precision number type should
use that type to represent this scalar.

**Result Coercion**

Expand All @@ -465,14 +465,18 @@ reasonable without losing information, otherwise they must raise a field error.
Examples of this may include returning `1.0` for the integer number `1`, or
`123.0` for the string `"123"`.

Non-finite floating-point internal values ({NaN} and {Infinity}) cannot be
coerced to {Float} and must raise a field error.

**Input Coercion**

When expected as an input type, both integer and float input values are
accepted. Integer input values are coerced to Float by adding an empty
fractional part, for example `1.0` for the integer input value `1`. All
other input values, including strings with numeric content, must raise a query
error indicating an incorrect type. If the integer input value represents a
value not representable by IEEE 754, a query error should be raised.
error indicating an incorrect type. If the input value otherwise represents a
value not representable by finite IEEE 754 (e.g. {NaN}, {Infinity}, or a value
outside the available precision), a query error must be raised.


### String
Expand Down
2 changes: 1 addition & 1 deletion spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ CompleteValue(fieldType, fields, result, variableValues):
* If {completedResult} is {null}, throw a field error.
* Return {completedResult}.
* If {result} is {null} (or another internal value similar to {null} such as
{undefined} or {NaN}), return {null}.
{undefined}), return {null}.
Copy link
Collaborator

@leebyron leebyron Apr 6, 2021

Choose a reason for hiding this comment

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

This change is technically a normative change, not just editorial. However I did some checking and found the reference implementation (and most others) do not adhere to short-circuiting NaN to null.

They instead treat NaN as an invalid Float and throw an error, which is exactly the behavior now accurately described above.

Copy link
Contributor

@sungam3r sungam3r Apr 6, 2021

Choose a reason for hiding this comment

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

GraphQL.NET throws on NaN.

* If {fieldType} is a List type:
* If {result} is not a collection of values, throw a field error.
* Let {innerType} be the inner type of {fieldType}.
Expand Down