Skip to content

Commit 6dbef35

Browse files
glasserleebyron
andauthored
Clarify that Float does not include NaN or infinity (#780)
* Clarify that Float does not include NaN or infinity Fixes #778. This matches the fact that you cannot represent these values in text as FloatValue, as well as the graphql-js implementation (https://github.com/graphql/graphql-js/blob/16009cbcb0109da03f2157a868817b886801095a/src/type/scalars.js#L108-L112). This was perhaps already implied by the word "fractional", but "finite" seems to be a more standard term for "IEEE 754 floats that are not infinity or NaN". * Update Section 3 -- Type System.md * Update CompleteValue() to not return early for NaN Co-authored-by: Lee Byron <[email protected]>
1 parent 4fd39e0 commit 6dbef35

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

spec/Section 3 -- Type System.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ encoding integer numbers larger than 32-bit.
450450

451451
### Float
452452

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

458458
**Result Coercion**
459459

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

468+
Non-finite floating-point internal values ({NaN} and {Infinity}) cannot be
469+
coerced to {Float} and must raise a field error.
470+
468471
**Input Coercion**
469472

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

477481

478482
### String

spec/Section 6 -- Execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ CompleteValue(fieldType, fields, result, variableValues):
648648
* If {completedResult} is {null}, throw a field error.
649649
* Return {completedResult}.
650650
* If {result} is {null} (or another internal value similar to {null} such as
651-
{undefined} or {NaN}), return {null}.
651+
{undefined}), return {null}.
652652
* If {fieldType} is a List type:
653653
* If {result} is not a collection of values, throw a field error.
654654
* Let {innerType} be the inner type of {fieldType}.

0 commit comments

Comments
 (0)