# 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 64 bit key^{*}stored as variable byte code

preceeds the data, with the data format indicated by the key value: 64 bit integers are stored as variable byte code, GMP integers and fractions use a different^{*}more compact for larger numbers

encoding.

Time is expressed in Unix Time encoded in a signed 64 bit integer, with the seconds multiplied by 189,000,000.^{*}this encoding places the storage value rollover event approximately 1,500 years in the future.

The 189,000,000^{*}Why 189? 189 is 3x3x3x7, enabling even division by any number up to 10, and many more common larger numbers.

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
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.