Files

35 lines
2.7 KiB
Markdown

# Data Exact 64-Bit Signed/Unsigned JSON Numbers and Checked Conversion
Task ID: M-DATA-02
Phase: P1
Status: APPROVED
Contracts: C-01, C-05, C-07
## 1. Context and baseline
`include/Void/Data/Json.hpp` currently stores all numbers as `double`, silently rounding integers above `2^53` through parse, DOM construction, equality, serialization, SAX events, and `Reflect.hpp`. StrictJson (`Void::Json::Strict::Value`) is already signed `int64_t` and must remain completely unchanged (C-07).
## 2. Deliverables
- `src/Data/module.cmake` updated to `INTERNAL_DEPS Core Math Time`.
- Extended `include/Void/Data/Json.hpp`: `NumberKind`, `ConversionError`, `int64_t`/`uint64_t`/`double` variant alternatives, unambiguous integral/float constructors, `is_int`/`is_uint`/`is_double`/`is_integer`/`number_kind`/`as_uint`/`get_int`/`get_uint`, `number_as<T>` delegating to `Void::Numeric::checked_cast`, exact cross-type `operator==`, strict RFC 8259 numeric grammar parsing (256-byte limit, `-0` -> integer `0`, `-0.0` preserved as negative double), optional `SaxHandler::{on_int,on_uint}` retaining `on_number` compatibility, exact `std::to_chars` serialization + `try_serialize`.
- Updated `include/Void/Data/Reflect.hpp` (exact integer `leaf_to_json`, `number_as<T>` in `leaf_from_json` and versioned envelopes) and `include/Void/Configuration/Config.hpp` (exact integer stringification).
- Expanded tests in `tests/standalone/Data/{Json,Reflect}.cpp`; `StrictJson.hpp` and `tests/standalone/Data/StrictJson.cpp` untouched.
## 3. Exact files and interfaces
- `src/Data/module.cmake`
- `include/Void/Data/Json.hpp`
- `include/Void/Data/Reflect.hpp`
- `include/Void/Configuration/Config.hpp`
- `tests/standalone/Data/{Json,Reflect}.cpp`
## 4. Edge cases
- `INT64_MIN`, `INT64_MAX`, `UINT64_MAX`, and `2^53 ± 1` survive parse, serialize, equality, and reflection round trips without silent rounding; integers `< INT64_MIN` or `> UINT64_MAX` fail parsing.
- `Value{UINT64_MAX} != Value{static_cast<double>(UINT64_MAX)}` and `Value{(std::uint64_t{1} << 53) + 1} != Value{static_cast<double>(1ULL << 53)}`.
- `number_as<double>` rejects `2^53 + 1` with `Rounding::exact`, succeeds with explicit `Rounding::nearest_even`; `try_serialize` rejects `NaN`/`Inf` with `Error::NonFinite`.
## 5. Acceptance criteria
- `Data;Update;Configuration;Testing` suites (`Json*|StrictJson*|Reflect*|Update*|Config*`) pass under `-DVOID_WARNINGS_AS_ERRORS=ON` without modifying `StrictJson`.
## 6. Verification commands
```sh
dev cpp-gcc -p openssl -c bash -lc 'cmake -S . -B /tmp/void-p1-data -G Ninja -DVOID_ENABLED_MODULES="Data;Update;Configuration;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-p1-data && /tmp/void-p1-data/tests/VoidTests --filter "Json*|StrictJson*|Reflect*|Update*|Config*"'
```