GMP Integer Storage
GMP integers are stored in BCD*Binary Coded Decimal, where each 4 bits represents one number 0-9. When viewed in a hex editor, BCD numbers may be read as base 10 numbers directly.
, most significant digit first, with a terminating nybble of 0xE for a positive number and 0xF for a negative number.*Nybbles with value 0xA, 0xB and 0xC indicate corrupted or otherwise erroneously recorded data.
The ratio type is stored as two GMP integers back-to-back, but both integers are padded*If 0xD appears immediately behind 0-9 values that is also an error, 0xD is used to pad the unused nybble in the final byte of a GMP encoding when the number has an even number of digits, plus the sign/terminator nybble, plus the 0xD padding nybble.
, if needed, to end on byte boundaries.
GMP integers (and the library used to work with them) can store and calculate with arbitrarily large numbers. For purposes of Assign Onward, only integers and ratios of integers are used, to explicitly avoid the ambiguity that can come from floating point arithmetic.
Deprecated, 2018 ideas:
GMP integers are stored in compact form, starting with a variable byte code*Reality check: a single byte VBC represents numbers up to 63, 63 bytes of storage represents over 500 bits, or numbers ranging up to ±10150, aka sufficient.
indicating the number of bytes used to represent the integer, followed by the value with most significant byte first. The most significant bit*of the first, most significant, byte
indicates the sign of the stored integer: set is negative. The sign bit is not included in the value of the integer. When necessary, a zero value most significant byte is prepended to achieve the required sign bit.
Rational fractions are stored as two integers, with two variable length byte encoded sizes: the first telling the size of the remaining size code plus the size of both integers*aka total bytes remaining in the object, as is standard for all variable sized data items
followed by a variable byte encoded size of the numerator storage, followed by the numerator and denominator.
Assign Onward
12 August 2018
MIT License
Copyright (c) 2018 Assign Onward
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.