aboutsummaryrefslogtreecommitdiff
path: root/std/prelude/numbers.pk
diff options
context:
space:
mode:
authorJJ2024-01-02 21:49:25 +0000
committerJJ2024-01-02 21:50:47 +0000
commitfde7a1311543badd1052a757d1e2c68272be1188 (patch)
treeabe438ea65ac8d90a1848593846531b59d0e1ce3 /std/prelude/numbers.pk
parent4852f1caabcbcd5ad3dd5696bfe4bc428d653f94 (diff)
std: more fleshing out. merge std.magic back into std.prelude.
Diffstat (limited to 'std/prelude/numbers.pk')
-rw-r--r--std/prelude/numbers.pk77
1 files changed, 77 insertions, 0 deletions
diff --git a/std/prelude/numbers.pk b/std/prelude/numbers.pk
new file mode 100644
index 0000000..7857d34
--- /dev/null
+++ b/std/prelude/numbers.pk
@@ -0,0 +1,77 @@
+## std.numbers: Operations on numbers and such.
+## A stub module for documentation. Mostly compiler magic.
+# reference: https://en.wikipedia.org/wiki/IEEE_754
+
+## The default integer type. Size depends on architecture.
+pub type int
+## A signed 8-bit integer.
+pub type i8
+## A signed 16-bit integer.
+pub type i16
+## A signed 32-bit integer.
+pub type i32
+## A signed 64-bit integer.
+pub type i64
+## A signed 128-bit integer.
+pub type i128
+
+## The default unsigned integer type. Size depends on architecture.
+pub type uint
+## An unsigned 8-bit integer.
+pub type u8
+## An unsigned 16-bit integer.
+pub type u16
+## An unsigned 32-bit integer.
+pub type u32
+## An unsigned 64-bit integer.
+pub type u64
+## An unsigned 128-bit integer.
+pub type u128
+
+## A floating-point type. Takes up 64 bits by default.
+pub type float = f64
+## A 32-bit floating point type. Single precision.
+pub type f32
+## A 64-bit floating point type. Double precision.
+pub type f64
+## A 128-bit floating point type. Quadruple precision.
+pub type f128
+
+## A decimal type, according to IEEE 754. Takes up 64 bits by default.
+pub type decimal = dec64
+## A 64-bit decimal type.
+pub type dec64
+## A 128-bit decimal type.
+pub type dec128
+
+## 8-bit bytes.
+pub type byte = u8
+## 4-byte chars. These represent distinct Unicode characters.
+pub type char = distinct u32
+## An alias to `char`, to match with `str`.
+pub type chr = char
+
+## The IEEE floating point value of *Not a Number*.
+pub const NaN: f64 = 0x7FF7FFFFFFFFFFFF
+## The IEEE floating point value of positive infinity.
+pub const Inf: f64 = 0x7FF0000000000000
+## The IEEE floating point value of negative infinity.
+pub const NegInf: f64 = 0xFFF0000000000000
+
+# todo: type conversions
+
+pub func +[T](a: T, b: T): T
+pub func -[T](a: T, b: T): T
+pub func *[T](a: T, b: T): T
+pub func /[T](a: T, b: T): float
+pub func ^[T](a: T, b: T): T # todo: should be exp?
+
+pub func div[T](a: T, b: T): T
+pub func mod[T](a: T, b: T): T # fixme
+pub func rem[T](a: T, b: T): T
+
+pub func shl[T](a: T): T
+pub func shr[T](a: T): T
+
+pub func abs[T](a: T): T
+pub func neg[T](a: T): bool