The 4 Laws of Numerics
How Omasheet shows a number: every type has a literal form, nothing is lost, the full value is shown, and typed columns are strict.
I was inspired to draft these laws on reading this piece by William Kahan, father of IEEE 754.
This is no place to list all the corrections Excel needs. It was cited here only to exemplify Errors Designed Not To Be Found.
The moral of Excel’s story is …
The bitter truth up front obviates obscurantist lies later.
What’s in YOUR spreadsheet?
Prof. W. Kahan
How Futile are Mindless Assessments of Roundoff in Floating-Point Computation?
What should a spreadsheet show when you type a number? Omasheet’s answer is a short set of laws: show what is held, in the literal form of its type, and round only when asked, with a mark that says so. Here they are in full, and they live on as the laws of type.
The principle
A number with no format shows what is held, in the literal form of its type. Rounding and shortening happen only on request, and are always indicated.
Law 1: each type has a literal form
The literal form sets the numeric type:
| Type | Literal | Examples |
|---|---|---|
Integer |
1 |
0, -10000 |
Fraction |
1/1 |
0/1, 2 1/3 |
Decimal |
1.0 |
0.0, -1.01 |
Float |
1e0 |
0e0, -9.999e-3, Inf |
Scientific |
1.0(00)e0 |
1.1000(82)e1, 11.000 ± 0.082 |
Complex |
1+0i |
3e0+4e0i |
Law 2: nothing is lost
Numeric data is stored either as the plaintext and formulae entered (.omx) or in Polars (.parquet). Binary types are used for Integer (i64), Decimal (decimal128), Float (f64) and String (string) values, with other types implemented as structs on these. The data is retained as entered or calculated at the full precision of the type[1][2].
Law 3: the full value is shown
Numbers are shown at full precision, unless you apply rounding. Standard and custom formats adjust display, but the underlying value is preserved. For example 1.234567 in a column declared Decimal['.2f'] is rounded to 2 decimal places and displayed as 1.23·. A cut mark · is shown whenever rounding is active and the full precision is shown in the bottom bar.
Law 4: typed columns are strict
If a column type is declared (indicated by a :), it may only contain values that conform. This applies to literals, imported values or the results of a formula. Types are strict. If required, coercion should be done explicitly via functions such as .Integer(), .Fraction().
If a column type is undeclared, the type of each cell is independent. The column type is inferred as the narrowest type wide enough to contain all the cell types.
Lemmas
Lemma: the general format option
Optionally, the [general] format may be set for a more comfortable user experience. It applies a consistent display pattern over all numeric types, quantities and durations included. It works with both typed and untyped columns. It avoid long runs of hard-to-count zeroes: a long integer is shown in exponential notation. It avoids exponential notation from 1e-9 up to, but not including, 1e10 (so 9,999,999,999 is plain and 10000000000 is 1e10). It brings in a thousands group mark , (set in the locale) at 10,000. It rounds decimal fractions to 3 places. A Float is rounded to 15 places to cut out arithmetic noise: e.g. sin(pi) is shown as 0·. The maximum column width for general format is 22 digits.[3][4][5]
Lemma: other types
Other types are provided, each with a literal form:
| Type | Literal | Examples |
|---|---|---|
Quantity |
1m |
2.3kg, 6.67430(15)e-11m^3.kg^-1.s^-2 |
Duration |
1s |
2yr, +1:30:00, -00:00:01 |
Date |
2025-01-31 |
1999-12-31 |
Time |
09:30 |
09:30:15.5, 23:59:59 |
Datetime |
2025-01-31T09:30 |
2025-07-01T12:00:00.123456 |
Dates and times use the ISO 8601 form.[6]
Lemma: Quantity units
A Quantity is a number, a prefix(optional) and a unit, written with no space: 5kg.
| Part | Rule | Examples |
|---|---|---|
| Unit | a symbol, perhaps with a prefix | m, km, MiB |
| Compound | . between terms, ^ and a whole exponent, no / |
9.81m.s^-2 |
| Dimension | what the unit measures | Length, Mass, Energy |
A column may be declared with a kind, Load : Mass, or with a unit, Load : Mass[g]: it reads a bare number in that unit, converts other units of the same dimension and shows the unit once, in its head.
Lemma: type representations
Type representations are built on a base type, but have their own literal form and display formats, for example.
| Representation | Base Type | Literal | Examples | |
|---|---|---|---|---|
Percent |
Decimal |
50% |
66.67% |
|
Binary |
Integer |
0b101 |
0b1111_0000 |
|
Hex |
Integer |
0xff |
0x1f |
|
Angle |
Quantity |
45° |
45°30′30″, -12°30′ |
|
Currency |
Quantity |
4.00USD |
$4.00, 0.001BTC |
Lemma: Decimal scale
Every Decimal has the same scale: 18 places, leaving 20 digits before the point, in a 38-digit decimal[7]. Control how many places are shown by a format, e.g. Decimal[.2f]. Decimals are exact, up to a point.
A written value must fit: a cell with more than 18 places, or more than 20 digits before the point, is refused in a Decimal column and is a Fraction in an undeclared column. A calculated Decimal value is rounded to fit: a product or a quotient is rounded once to 18 places, a tie to the even digit (banker’s rounding)[8][9], and one with no room before the point becomes an exact Fraction. Where exact thirds, sevenths and so on matter, use a Fraction.
Notes:
[1] Strictly speaking, a Float literal is expressed in decimal scientific notation (e.g. 1e2) and is converted to an IEEE 754 binary64 (f64) value before any operations are performed. When exported to Parquet, the value is stored as f64. Omasheet performs Float operations in accordance with IEEE 754 semantics, regardless of whether the value originates from a literal or binary data. It guarantees that every binary64 value can be converted to decimal notation and back without loss of precision, preserving its exact binary representation.
[2] Infectiousness: the numeric types form a hierarchy, ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, and the less exact type is the more infectious: Integer < Fraction < Decimal < Float < Scientific < Complex. An operation on two types gives the more infectious of them, so Integer + Decimal is a Decimal, and Decimal * Float is a Float. There are two cautions: a quotient of two Integers is a Fraction (or an Integer where it divides exactly), and a Scientific beside a Complex gives a Complex without its uncertainty.
[3] Many other formats are available, following the printf model used in many programming languages. Usually they may only be applied on typed columns. The cut mark · is used wherever rounding is in effect.
[4] The general format hides Float arithmetic noise, but has no affect on comparison operations since it is a display format. The =~= approximately equals comparison operator can be used to ignore small differences with a tolerance of 1e-15.
[5] The f64 scale limits are around 1e-308 to 1e308 so much smaller values like electron mass of 9.109_383_7139(28)e-31kg can be reliably used, but do not use general at this small scale.
[6] A Duration is a Quantity of time, based on the second. The ISO 8601 (PT1H30M) and clock (+11:30) forms count whole microseconds, for nanoseconds write a unit, as in 1.5ns, which is held as a Float.
[7] A Decimal (decimal128) has 38 digits to share between the two sides of the point. An Integer ( i64) has a maximum of 19 decimal digits. At 18 decimal places, 20 digits remain before it, enough for any Integer. A literal with more places is kept exactly as a Fraction.
[8] Round-to-nearest, ties-to-even (IEEE’s roundTiesToEven) is what Rust uses for f64 arithmetic and conversions, but the f64::round() method is the exception: it rounds ties away from zero, so Omasheet does that for the default IEEE behaviour.
[9] One scale suits Polars, which holds a Decimal as Decimal(38, 18). Every operand has the same scale, so no cast is needed to line them up. For example, Polars multiplies in 256 bits and rounds the result back to scale 18, with ties to the even digit[9] via dec128_mul.
Documents
| For | Read |
|---|---|
Each type shown with no format, general in detail, and literal errors |
Number display |
| What a column of each type reads, and the format letters | The file format |
| Choosing a type, and what happens when types meet | Choosing a number type |
| Arithmetic, rounding and converting | Expressions |
| Units | Units and dimensions |
The rules themselves are in value.rs (format_value, format_general).