Numbers
Big and Bigger
Within the AO protocol, all counted things are represented by integers or rational fractions aka the ratio of two integers. Internally, these integers are represented by 64 bit signed integers, or when that's not big enough, by arbitrarily large integers handled by the GMP library.
Floating point numbers may be used in user interface representations of rational fractions, but calculations are performed to obtain exact results which can be duplicated on a wide variety of hardware and software which may be cross checking the calculations.*Originally, 128 bit integers were considered for the larger numbers, but even those are too small for some reasonable applications, and they are also problematic when porting to various computer architectures - the GMP library, while cumbersome, is more portable than __int128.
Storage
Both 64 bit integers and GMP integers are stored in key-value form where a 63 bit key*stored as variable byte code
preceeds the data*In arrays, a single key preceeds a count of how many values are in the array followed by all the values in the array.
, with the data format indicated by the key value: 64 bit integers are stored as 8 byte signed quantities, while 63 bit unsigned integers are stored using variable byte code, GMP integers and fractions use a different*Binary Coded Decimal
encoding.
Time is expressed in Unix Time encoded in a signed 64 bit integer, with the milliseconds multiplied by 1,000.*this encoding places the storage value rollover event approximately 280,000 years in the future.
The millisecond divisions are used to ensure that events generated on a single server are given a strictly increasing sequence in time - while events coming from multiple sources may be recorded as simultaneous, no two events recorded by a single actor may be marked as simultaneous. It is expected that actual clock times accurate to the millisecond will be used, and for events which are generated in the same millisecond of clock time, their timestamps will be adjusted to place them in proper sequence when considering the smaller divisions of time. When time values are stored, they are stored as straight 8 byte big endian storage of the integer.
Assign Onward
28 July 2018, updated 14 November 2021
MIT License
Copyright (c) 2021 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.