summaryrefslogtreecommitdiff
path: root/notes/250329-numbers.md
blob: 5bbfde3791d8d5c58fe37775bab5b2632a0ed5d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Number tower

_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