Skip to main content

Module number

Module number 

Source
Expand description

Number text, shared by the renderers.

A number reaches a renderer as a machine value and, when the source could hand it over, the lexeme it was spelled with. The lexeme wins, because it is the only thing that keeps 50.25 as 50.25 and keeps the digits of a number beyond f64’s exact range; but a lexeme is data from a source, so it is checked against the JSON number grammar before it is copied into an output that promises to be JSON or CSV. Without a lexeme the shortest text that reads back as the same f64 is written. A value with no finite text (NaN, infinity) is rejected as unrepresentable rather than written as null, which would silently change the data, and it is rejected whatever lexeme stands beside it: 1e999 spells a number, but the value the pipeline holds is infinity, and a JSON reader given the lexeme refuses it as out of range.

Validation and formatting are separate functions so a renderer can check a whole row before it writes any of it, and format each number once.

Functions§

is_json_number
Whether text is a number by RFC 8259’s grammar: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?, nothing else and nothing around it.