Skip to content

Commit

Permalink
Merge pull request #506 from toml-lang/signed-zeros-and-non-finite-fl…
Browse files Browse the repository at this point in the history
…oats

Add special float values and clarify signed zeros
  • Loading branch information
mojombo authored Nov 29, 2017
2 parents dfdf208 + 50bf81b commit 446e5bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## HEAD

* Add special float values (inf, nan)
* Rename Datetime to Offset Date-Time.
* Add Local Date-Time.
* Add Local Date.
Expand All @@ -19,6 +20,7 @@
* Clarify that literal strings can be table keys.
* Clarify that at least millisecond precision expected for Date-Time and Time.
* Clarify that comments are OK in multiline arrays.
* Clarify that +0, -0, +0.0, and -0.0 are valid and what they mean.
* TOML has a logo!

## 0.4.0 / 2015-02-12
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,17 @@ int6 = 5_349_221
int7 = 1_2_3_4_5 # VALID but discouraged
```

Leading zeros are not allowed. Hex, octal, and binary forms are not allowed.
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.

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 IEEE 754 binary64 values.

A float consists of an integer part (which follows the same rules as integer
values) followed by a fractional part and/or an exponent part. If both a
fractional part and exponent part are present, the fractional part must precede
Expand Down Expand Up @@ -338,7 +339,21 @@ underscore must be surrounded by at least one digit.
flt8 = 9_224_617.445_991_228_313
```

64-bit (double) precision expected.
Float values `-0.0` and `+0.0` are valid and should map according to IEEE 754.

Special float values can also be expressed. They are always lowercase.

```toml
# infinity
sf1 = inf # positive infinity
sf2 = +inf # positive infinity
sf3 = -inf # negative infinity

# not a number
sf4 = nan # actual sNaN/qNaN encoding is implementation specific
sf5 = +nan # same as `nan`
sf6 = -nan # valid, actual encoding is implementation specific
```

Boolean
-------
Expand Down
7 changes: 6 additions & 1 deletion toml.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@ underscore = %x5F ; _

;; Float

float = integer ( frac / ( frac exp ) / exp )
float = integer ( exp / frac [ exp ] )
float =/ special-float

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 )
inf = %x69.6e.66 ; inf
nan = %x6e.61.6e ; nan

;; Boolean

boolean = true / false
Expand Down

0 comments on commit 446e5bc

Please sign in to comment.