-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check that every magnitude fits in its target type (#211)
`get_value<T>(m)` converts a magnitude `m` to its representation in type `T`. It produces a hard compiler error if the value can't fit. Its relative `get_value_result<T>(m)` always returns a result, but produces an error code if the value can't be represented. Previously, there was a hole in this system. We assumed that each magnitude could be represented in `std::uintmax_t`. Of course, if it couldn't, `get_value` would fail to compile as it should. But `get_value_result` would _also_ fail to compile, instead of producing an error condition. To fix this, we need to move our checking utilities further up in the file, so that all of our utilities can use them. `product`, `int_pow`, `base_power_value` --- they all need to _check their computations_ at every step. When we do this, we're able to gracefully detect the non-representability of huge numbers even for the biggest types.
- Loading branch information
Showing
2 changed files
with
103 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters