Numeric tower

^ Up

2025 March

exacts:

  uint : 0...n

  sint : -n...-1 | uint

  ratn : ( p: sint, q: uint )

  comp : ( r: ratn, i: ratn )


inexacts:

  double : ieee754 double with +inf, -inf, +nan, -nan

  cmp128 : ( r: double , i: double )


exact operations:

  uint + uint = uint

  sint + uint = sint

  ratn + uint = ratn  [ ratn + ( p = uint , q = 0 ) ]

  ratn + sint = ratn  [ ratn + ( p = sint , q = 0 ) ]

  ratn + ratn = ratn

  comp + uint = comp  [ comp + ( r = ( p = uint , q = 0 ) , i = 0 ) ]

  comp + sint = comp  [ comp + ( r = ( p = sint , q = 0 ) , i = 0 ) ]

  comp + ratn = comp  [ comp + ( r = ratn , i = 0 ) ]

  comp + comp = comp


inexact operations:

  double + double = double

  cmp128 + double = cmp128  [ cmp128 + ( r = double , i = 0 ) ]

2025 December

Mixing exact and inexact numbers implicitly should not be allowed. It should be a type error. Conversion must be explicit.

Basically there are two numeric towers, not one. The exact numbers use integers all the way down; for example, an exact complex is a pair of exact rationals which are each a pair of integers. Inexact numbers use double, with the only other type being complex128 which is a pair of doubles.

Not sure yet how exactly to deal with unsigned integers. All I know is that I don't want there to be unsigned rational numbers; that's just excessive. A rational number always has a signed numerator and an unsigned denominator.

See also:

https://www.deinprogramm.de/sperber/papers/numerical-tower.pdf