@@ -9,30 +9,56 @@ Protocol-Oriented Number System in Pure Swift
9
9
10
10
```` swift
11
11
import PONS // Let the fun begin!
12
+ ````
13
+
14
+ BigInt included. Enjoy unlimited!
12
15
16
+ ```` swift
13
17
let bn = BigInt (1 )<< 64 + 1 // 18446744073709551617
14
18
bn.asUInt64 // nil; bn > UIntMax.max
15
19
(bn - 2 ).asUInt64 // 18446744073709551615 == UIntMax.max
16
20
bn + bn // 36893488147419103234
17
21
bn - bn // 0
18
22
bn * bn // 340282366920938463500268095579187314689
19
23
bn / bn // 1
24
+ ````
20
25
26
+ Rational (number type) is also included.
27
+
28
+ ````
21
29
let bq = BigInt(1).over(bn) // (1/18446744073709551617)
22
30
bq + bq // (2/18446744073709551617)
23
31
bq - bq // (0/1)
24
32
bq * bq // (1/340282366920938463500268095579187314689)
25
33
bq / bq // (1/1)
26
34
bq.denominator == bn // true, of course!
27
35
bq.reciprocal.numerator == bn // so is this
36
+ ````
37
+
38
+ Complex numbers. How can we live without them?
28
39
40
+ ```` swift
29
41
let bz = bq + bq.i // ((1/18446744073709551617)+(1/18446744073709551617).i)
30
42
bz + bz // ((2/18446744073709551617)+(2/18446744073709551617).i)
31
43
bz - bz // ((0/1)+(0/1).i)
32
44
bz * bz // ((0/1)+(2/340282366920938463500268095579187314689).i)
33
45
bz / bz // ((1/1)+(0/1).i)
34
46
````
35
47
48
+ Elementary functions are supported as static functions,
49
+ By default it just converts to ` Double ` , let ` Darwin ` (or ` Glibc ` on Linux) do the work,
50
+ and convertsit back by default.
51
+
52
+ TODO: rewrite elementary functions generically!
53
+
54
+ ```` swift
55
+ Double .sqrt (-1 ) // sadly NaN
56
+ Rational< BigUInt> .sqrt (bq) // yes, works with Rational, too!
57
+ Complex.sqrt (-1 ) // happily i
58
+ Complex.exp (Double .PI .i ) // not exactly -1.0+0.0.i.
59
+ Complex.log (-1 ) // Yes, πi
60
+ ````
61
+
36
62
## USAGE
37
63
38
64
### With Playground via Workspace
0 commit comments