#include "fson/Number.hh"
Stores the parsed double, the original source lexeme, and a Kind recording which lexical form it came from — so a number round-trips exactly.
enum class Kind { Decimal, Hex, Infinity, NegativeInfinity, NaN };
| Member | Description |
|---|---|
Number(double) / Number(long long) | lexeme generated (shortest round-trip via std::to_chars for finite values); a non-finite double sets the matching Kind and lexeme ("Infinity" / "-Infinity" / "NaN") instead of throwing |
Number(double, std::string lexeme, Kind = Kind::Decimal) | parser entry; lexeme must satisfy the number grammar |
asDouble() → double | numeric value |
asInteger() → long long | truncates; clamps to LLONG_MAX / LLONG_MIN / 0 for +Infinity / -Infinity / NaN rather than UB |
isIntegral() → bool | Decimal: no . / e / E in the lexeme; Hex: always true; non-finite: always false |
getKind() → Kind | the lexical form |
getLexeme() → std::string const& | exact source spelling — written verbatim in the Fson and Json5 dialects |
setValue(double) / setValue(long long) | sets the value, regenerates the lexeme, updates Kind; accepts non-finite doubles |
Round-trip and conversion
1.50 stays 1.50, 0xFF stays 0xFF, 1e3 stays 1e3, Infinity stays Infinity — in the Fson and Json5 dialects. The Json dialect rewrites hex to decimal and throws std::domain_error on a non-finite value.
asInteger() goes through double, so an integer beyond 2^53 keeps its lexeme on round-trip but loses precision when read as an integer.

