File: json-integer-parsing.md

package info (click to toggle)
glaze 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,948 kB
  • sloc: cpp: 121,839; sh: 99; ansic: 26; makefile: 13
file content (31 lines) | stat: -rw-r--r-- 986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# JSON Integer Parsing

JSON integer parsing in Glaze rejects negative exponents and decimal values.

Valid examples for a `uint8_t`:

```
0
123
255
1e1
1e+2
```

Invalid examples for a `uint8_t`:

```
0.0 ** decimal
256 ** out of range
1.0 ** decimal
1e-2 ** negative exponent
```

This applies for larger integer types as well, such as `int64_t`.

Glaze rejects negative exponents and decimal values for the following reasons:

- Fractional values cannot be stored exactly in integers, so data loss can be unknown to the developer.
- Fractional values should be rounded in different ways or truncated when converted to integers based on the application. It is better to parse these values as floating point values and then apply specific conversions.
- The parser runs faster
- We are able to disambiguate between values that can be stored in integer types and floating point types, which allows auto variant deduction for variants containing both integers and floating point values.