diff options
269 files changed, 2097 insertions, 2048 deletions
@@ -5,6 +5,7 @@ instead of `$TOMO_PATH/share/tomo_vX.Y/installed/module_vZ.W` - Core libraries are no longer shipped with the compiler, they have moved to separate repositories. +- Renamed `Num` -> `Float64` and `Num32` -> `Float32` - Library installation has been cleaned up a bit. - List indexing now gives an optional value. - Added support for inline anonymous enums @@ -163,8 +163,8 @@ config.mk: configure.sh # Integer implementations depend on the shared header: src/stdlib/int64.o src/stdlib/int32.o src/stdlib/int16.o src/stdlib/int8.o: src/stdlib/intX.c.h src/stdlib/intX.h -# Num implementations depend on the shared header: -src/stdlib/num32.o src/stdlib/num64.o: src/stdlib/numX.c.h +# Float implementations depend on the shared header: +src/stdlib/float32.o src/stdlib/float64.o: src/stdlib/floatX.c.h src/stdlib/floatX.h # Specifically src/tomo.c needs to recompile if CHANGES.md changes: src/tomo.o: src/tomo.c src/ast.h src/environment.h src/types.h config.mk src/changes.md.h @@ -163,14 +163,14 @@ setenv("FOOBAR", "xyz") ## sleep ```tomo -sleep : func(seconds: Num -> Void) +sleep : func(seconds: Float64 -> Void) ``` Pause execution for a given number of seconds. Argument | Type | Description | Default ---------|------|-------------|--------- -seconds | `Num` | How many seconds to sleep for. | - +seconds | `Float64` | How many seconds to sleep for. | - **Return:** Nothing. @@ -342,2120 +342,2163 @@ assert [x for x in Byte(2).to(5, step=2)] == [Byte(2), Byte(4)] ``` -# Int -## Int.abs +# CString +## CString.as_text ```tomo -Int.abs : func(x: Int -> Int) +CString.as_text : func(str: CString -> Text) ``` -Calculates the absolute value of an integer. +Convert a C string to Text. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer whose absolute value is to be calculated. | - +str | `CString` | The C string. | - -**Return:** The absolute value of `x`. +**Return:** The C string as a Text. **Example:** ```tomo -assert (-10).abs() == 10 +assert CString("Hello").as_text() == "Hello" ``` -## Int.choose +## CString.join ```tomo -Int.choose : func(n: Int, k: Int -> Int) +CString.join : func(glue: CString, pieces: [CString] -> CString) ``` -Computes the binomial coefficient of the given numbers (the equivalent of `n` choose `k` in combinatorics). This is equal to `n.factorial()/(k.factorial() * (n-k).factorial())`. +Join a list of C strings together with a separator. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Int` | The number of things to choose from. | - -k | `Int` | The number of things to be chosen. | - +glue | `CString` | The C joiner used to between elements. | - +pieces | `[CString]` | A list of C strings to join. | - -**Return:** The binomial coefficient, equivalent to the number of ways to uniquely choose `k` objects from among `n` objects, ignoring order. +**Return:** A C string of the joined together bits. **Example:** ```tomo -assert (4).choose(2) == 6 +assert CString(",").join([CString("a"), CString("b")]) == CString("a,b") ``` -## Int.clamped + +# Float64 +## Float64.1_PI ```tomo -Int.clamped : func(x: Int, low: Int, high: Int -> Int) +Float64.1_PI : Float64 ``` -Returns the given number clamped between two values so that it is within that range. +The constant $\frac{1}{\pi}$. -Argument | Type | Description | Default ----------|------|-------------|--------- -x | `Int` | The integer to clamp. | - -low | `Int` | The lowest value the result can take. | - -high | `Int` | The highest value the result can take. | - +## Float64.2_PI -**Return:** The first argument clamped between the other two arguments. +```tomo +Float64.2_PI : Float64 +``` +The constant $2 \times \pi$. -**Example:** -```tomo -assert (2).clamped(5, 10) == 5 +## Float64.2_SQRTPI +```tomo +Float64.2_SQRTPI : Float64 ``` -## Int.factorial + +The constant $2 \times \sqrt{\pi}$. + +## Float64.E ```tomo -Int.factorial : func(n: Int -> Text) +Float64.E : Float64 ``` -Computes the factorial of an integer. +The base of the natural logarithm ($e$). -Argument | Type | Description | Default ----------|------|-------------|--------- -n | `Int` | The integer to compute the factorial of. | - +## Float64.INF -**Return:** The factorial of the given integer. +```tomo +Float64.INF : Float64 +``` +Positive infinity. -**Example:** -```tomo -assert (10).factorial() == 3628800 +## Float64.LN10 +```tomo +Float64.LN10 : Float64 ``` -## Int.get_bit + +The natural logarithm of 10. + +## Float64.LN2 ```tomo -Int.get_bit : func(i: Int, bit_index: Int -> Bool) +Float64.LN2 : Float64 ``` -In the binary representation of an integer, check whether a given bit index is set to 1 or not. +The natural logarithm of 2. -For fixed-size integers, the bit index must be between 1 and the number of bits in that integer (i.e. 1-64 for `Int64`). For `Int`, the bit index must be between 1 and `Int64.max`. Values outside this range will produce a runtime error. +## Float64.LOG2E -Argument | Type | Description | Default ----------|------|-------------|--------- -i | `Int` | The integer whose bits are being inspected. | - -bit_index | `Int` | The index of the bit to check (1-indexed). | - +```tomo +Float64.LOG2E : Float64 +``` -**Return:** Whether or not the given bit index is set to 1 in the binary representation of the integer. +The base 2 logarithm of $e$ +## Float64.PI -**Example:** ```tomo -assert (6).get_bit(1) == no -assert (6).get_bit(2) == yes -assert (6).get_bit(3) == yes -assert (6).get_bit(4) == no +Float64.PI : Float64 +``` +Pi ($\pi$). + +## Float64.PI_2 + +```tomo +Float64.PI_2 : Float64 ``` -## Int.hex + +$\frac{\pi}{2}$ + +## Float64.PI_4 ```tomo -Int.hex : func(i: Int, digits: Int = 0, uppercase: Bool = yes, prefix: Bool = yes -> Text) +Float64.PI_4 : Float64 ``` -Converts an integer to its hexadecimal representation. +$\frac{\pi}{4}$ -Argument | Type | Description | Default ----------|------|-------------|--------- -i | `Int` | The integer to be converted. | - -digits | `Int` | The minimum number of digits in the output string. | `0` -uppercase | `Bool` | Whether to use uppercase letters for hexadecimal digits. | `yes` -prefix | `Bool` | Whether to include a "0x" prefix. | `yes` +## Float64.SQRT1_2 -**Return:** The hexadecimal string representation of the integer. +```tomo +Float64.SQRT1_2 : Float64 +``` +$\sqrt{\frac{1}{2}}$ + +## Float64.SQRT2 -**Example:** ```tomo -assert (255).hex(digits=4, uppercase=yes, prefix=yes) == "0x00FF" +Float64.SQRT2 : Float64 +``` + +$\sqrt{2}$ +## Float64.TAU + +```tomo +Float64.TAU : Float64 ``` -## Int.is_between + +Tau ($2 \times \pi$) + +## Float64.abs ```tomo -Int.is_between : func(x: Int, low: Int, high: Int -> Bool) +Float64.abs : func(n: Float64 -> Float64) ``` -Determines if an integer is between two numbers (inclusive). +Calculates the absolute value of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer to be checked. | - -low | `Int` | The lower bound to check (inclusive). | - -high | `Int` | The upper bound to check (inclusive). | - +n | `Float64` | The number whose absolute value is to be computed. | - -**Return:** `yes` if `low <= x and x <= high`, otherwise `no` +**Return:** The absolute value of `n`. **Example:** ```tomo -assert (7).is_between(1, 10) == yes -assert (7).is_between(100, 200) == no -assert (7).is_between(1, 7) == yes +assert (-3.5).abs() == 3.5 ``` -## Int.is_prime +## Float64.acos ```tomo -Int.is_prime : func(x: Int, reps: Int = 50 -> Bool) +Float64.acos : func(x: Float64 -> Float64) ``` -Determines if an integer is a prime number. - -This function is _probabilistic_. With the default arguments, the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. +Computes the arc cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer to be checked. | - -reps | `Int` | The number of repetitions for primality tests. | `50` +x | `Float64` | The number for which the arc cosine is to be calculated. | - -**Return:** `yes` if `x` is a prime number, `no` otherwise. +**Return:** The arc cosine of `x` in radians. **Example:** ```tomo -assert (7).is_prime() == yes -assert (6).is_prime() == no +assert (0.0).acos() == 1.5708 ``` -## Int.next_prime +## Float64.acosh ```tomo -Int.next_prime : func(x: Int -> Int) +Float64.acosh : func(x: Float64 -> Float64) ``` -Finds the next prime number greater than the given integer. - -This function is _probabilistic_, but the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. +Computes the inverse hyperbolic cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer after which to find the next prime. | - +x | `Float64` | The number for which the inverse hyperbolic cosine is to be calculated. | - -**Return:** The next prime number greater than `x`. +**Return:** The inverse hyperbolic cosine of `x`. **Example:** ```tomo -assert (11).next_prime() == 13 +assert (1.0).acosh() == 0 ``` -## Int.octal +## Float64.asin ```tomo -Int.octal : func(i: Int, digits: Int = 0, prefix: Bool = yes -> Text) +Float64.asin : func(x: Float64 -> Float64) ``` -Converts an integer to its octal representation. +Computes the arc sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -i | `Int` | The integer to be converted. | - -digits | `Int` | The minimum number of digits in the output string. | `0` -prefix | `Bool` | Whether to include a "0o" prefix. | `yes` +x | `Float64` | The number for which the arc sine is to be calculated. | - -**Return:** The octal string representation of the integer. +**Return:** The arc sine of `x` in radians. **Example:** ```tomo -assert (64).octal(digits=4, prefix=yes) == "0o0100" +assert (0.5).asin() == 0.5236 ``` -## Int.onward +## Float64.asinh ```tomo -Int.onward : func(first: Int, step: Int = 1 -> Text) +Float64.asinh : func(x: Float64 -> Float64) ``` -Return an iterator that counts infinitely from the starting integer (with an optional step size). +Computes the inverse hyperbolic sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -first | `Int` | The starting integer. | - -step | `Int` | The increment step size. | `1` +x | `Float64` | The number for which the inverse hyperbolic sine is to be calculated. | - -**Return:** An iterator function that counts onward from the starting integer. +**Return:** The inverse hyperbolic sine of `x`. **Example:** ```tomo -nums : &[Int] = &[] -for i in (5).onward() -nums.insert(i) -stop if i == 10 -assert nums[] == [5, 6, 7, 8, 9, 10] +assert (0.0).asinh() == 0 ``` -## Int.parse +## Float64.atan ```tomo -Int.parse : func(text: Text, remainder: &Text? = none -> Int?) +Float64.atan : func(x: Float64 -> Float64) ``` -Converts a text representation of an integer into an integer. +Computes the arc tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -text | `Text` | The text containing the integer. | - -remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none` +x | `Float64` | The number for which the arc tangent is to be calculated. | - -**Return:** The integer represented by the text. If the given text contains a value outside of the representable range or if the entire text can't be parsed as an integer, `none` will be returned. +**Return:** The arc tangent of `x` in radians. **Example:** ```tomo -assert Int.parse("123") == 123 -assert Int.parse("0xFF") == 255 -assert Int.parse("123xyz") == none -remainder : Text -assert Int.parse("123xyz", &remainder) == 123 -assert remainder == "xyz" - -# Can't parse: -assert Int.parse("asdf") == none - -# Outside valid range: -assert Int8.parse("9999999") == none +assert (1.0).atan() == 0.7854 ``` -## Int.prev_prime +## Float64.atan2 ```tomo -Int.prev_prime : func(x: Int -> Int?) +Float64.atan2 : func(x: Float64, y: Float64 -> Float64) ``` -Finds the previous prime number less than the given integer. If there is no previous prime number (i.e. if a number less than `2` is provided), then the function will create a runtime error. - -This function is _probabilistic_, but the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. +Computes the arc tangent of the quotient of two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer before which to find the previous prime. | - +x | `Float64` | The numerator. | - +y | `Float64` | The denominator. | - -**Return:** The previous prime number less than `x`, or `none` if `x` is less than 2. +**Return:** The arc tangent of `x/y` in radians. **Example:** ```tomo -assert (11).prev_prime() == 7 +assert Float64.atan2(1, 1) == 0.7854 ``` -## Int.sqrt +## Float64.atanh ```tomo -Int.sqrt : func(x: Int -> Int) +Float64.atanh : func(x: Float64 -> Float64) ``` -Calculates the nearest square root of an integer. +Computes the inverse hyperbolic tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Int` | The integer whose square root is to be calculated. | - +x | `Float64` | The number for which the inverse hyperbolic tangent is to be calculated. | - -**Return:** The integer part of the square root of `x`. +**Return:** The inverse hyperbolic tangent of `x`. **Example:** ```tomo -assert (16).sqrt() == 4 -assert (17).sqrt() == 4 +assert (0.5).atanh() == 0.5493 ``` -## Int.to +## Float64.cbrt ```tomo -Int.to : func(first: Int, last: Int, step: Int? = none -> func(->Int?)) +Float64.cbrt : func(x: Float64 -> Float64) ``` -Returns an iterator function that iterates over the range of numbers specified. +Computes the cube root of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -first | `Int` | The starting value of the range. | - -last | `Int` | The ending value of the range. | - -step | `Int?` | An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`. | `none` +x | `Float64` | The number for which the cube root is to be calculated. | - -**Return:** An iterator function that returns each integer in the given range (inclusive). +**Return:** The cube root of `x`. **Example:** ```tomo -iter := (2).to(5) -assert iter() == 2 -assert iter() == 3 -assert iter() == 4 -assert iter() == 5 -assert iter() == none - -assert [x for x in (2).to(5)] == [2, 3, 4, 5] -assert [x for x in (5).to(2)] == [5, 4, 3, 2] -assert [x for x in (2).to(5, step=2)] == [2, 4] +assert (27.0).cbrt() == 3 ``` - -# List -## List.binary_search +## Float64.ceil ```tomo -List.binary_search : func(list: [T], by: func(x,y:&T->Int32) = T.compare -> Int) +Float64.ceil : func(x: Float64 -> Float64) ``` -Performs a binary search on a sorted list. +Rounds a number up to the nearest integer. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The sorted list to search. | - -by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The number to be rounded up. | - -**Return:** Assuming the input list is sorted according to the given comparison function, return the index where the given item would be inserted to maintain the sorted order. That is, if the item is found, return its index, otherwise return the place where it would be found if it were inserted and the list were sorted. +**Return:** The smallest integer greater than or equal to `x`. **Example:** ```tomo -assert [1, 3, 5, 7, 9].binary_search(5) == 3 -assert [1, 3, 5, 7, 9].binary_search(-999) == 1 -assert [1, 3, 5, 7, 9].binary_search(999) == 6 +assert (3.2).ceil() == 4 ``` -## List.by +## Float64.clamped ```tomo -List.by : func(list: [T], step: Int -> [T]) +Float64.clamped : func(x: Float64, low: Float64, high: Float64 -> Float64) ``` -Creates a new list with elements spaced by the specified step value. +Returns the given number clamped between two values so that it is within that range. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The original list. | - -step | `Int` | The step value for selecting elements. | - +x | `Float64` | The number to clamp. | - +low | `Float64` | The lowest value the result can take. | - +high | `Float64` | The highest value the result can take. | - -**Return:** A new list with every `step`-th element from the original list. +**Return:** The first argument clamped between the other two arguments. **Example:** ```tomo -assert [1, 2, 3, 4, 5, 6].by(2) == [1, 3, 5] +assert (2.5).clamped(5.5, 10.5) == 5.5 ``` -## List.clear +## Float64.copysign ```tomo -List.clear : func(list: @[T] -> Void) +Float64.copysign : func(x: Float64, y: Float64 -> Float64) ``` -Clears all elements from the list. +Copies the sign of one number to another. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list to be cleared. | - +x | `Float64` | The number whose magnitude will be copied. | - +y | `Float64` | The number whose sign will be copied. | - -**Return:** Nothing. +**Return:** A number with the magnitude of `x` and the sign of `y`. **Example:** ```tomo -my_list.clear() +assert (3.0).copysign(-1) == -3 ``` -## List.counts +## Float64.cos ```tomo -List.counts : func(list: [T] -> {T=Int}) +Float64.cos : func(x: Float64 -> Float64) ``` -Counts the occurrences of each element in the list. +Computes the cosine of a number (angle in radians). Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to count elements in. | - +x | `Float64` | The angle in radians. | - -**Return:** A table mapping each element to its count. +**Return:** The cosine of `x`. **Example:** ```tomo -assert [10, 20, 30, 30, 30].counts() == {10=1, 20=1, 30=3} +assert (0.0).cos() == 1 ``` -## List.find +## Float64.cosh ```tomo -List.find : func(list: [T], target: T -> Int?) +Float64.cosh : func(x: Float64 -> Float64) ``` -Finds the index of the first occurrence of an element (if any). +Computes the hyperbolic cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to search through. | - -target | `T` | The item to search for. | - +x | `Float64` | The number for which the hyperbolic cosine is to be calculated. | - -**Return:** The index of the first occurrence or `none` if not found. +**Return:** The hyperbolic cosine of `x`. **Example:** ```tomo -assert [10, 20, 30, 40, 50].find(20) == 2 -assert [10, 20, 30, 40, 50].find(9999) == none +assert (0.0).cosh() == 1 ``` -## List.from +## Float64.erf ```tomo -List.from : func(list: [T], first: Int -> [T]) +Float64.erf : func(x: Float64 -> Float64) ``` -Returns a slice of the list starting from a specified index. +Computes the error function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The original list. | - -first | `Int` | The index to start from. | - +x | `Float64` | The number for which the error function is to be calculated. | - -**Return:** A new list starting from the specified index. +**Return:** The error function of `x`. **Example:** ```tomo -assert [10, 20, 30, 40, 50].from(3) == [30, 40, 50] +assert (0.0).erf() == 0 ``` -## List.has +## Float64.erfc ```tomo -List.has : func(list: [T], target: T -> Bool) +Float64.erfc : func(x: Float64 -> Float64) ``` -Checks if the list has an element. +Computes the complementary error function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to check. | - -target | `T` | The element to check for. | - +x | `Float64` | The number for which the complementary error function is to be calculated. | - -**Return:** `yes` if the list has the element, `no` otherwise. +**Return:** The complementary error function of `x`. **Example:** ```tomo -assert [10, 20, 30].has(20) == yes +assert (0.0).erfc() == 1 ``` -## List.heap_pop +## Float64.exp ```tomo -List.heap_pop : func(list: @[T], by: func(x,y:&T->Int32) = T.compare -> T?) +Float64.exp : func(x: Float64 -> Float64) ``` -Removes and returns the top element of a heap or `none` if the list is empty. By default, this is the *minimum* value in the heap. +Computes the exponential function $e^x$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the heap. | - -by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The exponent. | - -**Return:** The removed top element of the heap or `none` if the list is empty. +**Return:** The value of $e^x$. **Example:** ```tomo -my_heap := [30, 10, 20] -my_heap.heapify() -assert my_heap.heap_pop() == 10 +assert (1.0).exp() == 2.7183 ``` -## List.heap_push +## Float64.exp2 ```tomo -List.heap_push : func(list: @[T], item: T, by = T.compare -> Void) +Float64.exp2 : func(x: Float64 -> Float64) ``` -Adds an element to the heap and maintains the heap property. By default, this is a *minimum* heap. +Computes $2^x$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the heap. | - -item | `T` | The item to be added. | - -by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The exponent. | - -**Return:** Nothing. +**Return:** The value of $2^x$. **Example:** ```tomo -my_heap.heap_push(10) +assert (3.0).exp2() == 8 ``` -## List.heapify +## Float64.expm1 ```tomo -List.heapify : func(list: @[T], by: func(x,y:&T->Int32) = T.compare -> Void) +Float64.expm1 : func(x: Float64 -> Float64) ``` -Converts a list into a heap. +Computes $e^x - 1$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list to be heapified. | - -by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The exponent. | - -**Return:** Nothing. +**Return:** The value of $e^x - 1$. **Example:** ```tomo -my_heap := [30, 10, 20] -my_heap.heapify() +assert (1.0).expm1() == 1.7183 ``` -## List.insert +## Float64.fdim ```tomo -List.insert : func(list: @[T], item: T, at: Int = 0 -> Void) +Float64.fdim : func(x: Float64, y: Float64 -> Float64) ``` -Inserts an element at a specified position in the list. - -Since indices are 1-indexed and negative indices mean "starting from the back", an index of `0` means "after the last item". +Computes the positive difference between two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list. | - -item | `T` | The item to be inserted. | - -at | `Int` | The index at which to insert the item. | `0` +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - -**Return:** Nothing. +**Return:** The positive difference $\max(0, x - y)$. **Example:** ```tomo -list := [10, 20] -list.insert(30) -assert list == [10, 20, 30] +fd -list.insert(999, at=2) -assert list == [10, 999, 20, 30] +assert (5.0).fdim(3) == 2 ``` -## List.insert_all +## Float64.floor ```tomo -List.insert_all : func(list: @[T], items: [T], at: Int = 0 -> Void) +Float64.floor : func(x: Float64 -> Float64) ``` -Inserts a list of items at a specified position in the list. - -Since indices are 1-indexed and negative indices mean "starting from the back", an index of `0` means "after the last item". +Rounds a number down to the nearest integer. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list. | - -items | `[T]` | The items to be inserted. | - -at | `Int` | The index at which to insert the item. | `0` +x | `Float64` | The number to be rounded down. | - -**Return:** Nothing. +**Return:** The largest integer less than or equal to `x`. **Example:** ```tomo -list := [10, 20] -list.insert_all([30, 40]) -assert list == [10, 20, 30, 40] - -list.insert_all([99, 100], at=2) -assert list == [10, 99, 100, 20, 30, 40] +assert (3.7).floor() == 3 ``` -## List.pop +## Float64.hypot ```tomo -List.pop : func(list: &[T], index: Int = -1 -> T?) +Float64.hypot : func(x: Float64, y: Float64 -> Float64) ``` -Removes and returns an item from the list. If the given index is present in the list, the item at that index will be removed and the list will become one element shorter. - -Since negative indices are counted from the back, the default behavior is to pop the last value. +Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `&[T]` | The list to remove an item from. | - -index | `Int` | The index from which to remove the item. | `-1` +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - -**Return:** `none` if the list is empty or the given index does not exist in the list, otherwise the item at the given index. +**Return:** The Euclidean norm of `x` and `y`. **Example:** ```tomo -list := &[10, 20, 30, 40] - -assert list.pop() == 40 -assert list[] == [10, 20, 30] - -assert list.pop(index=2) == 20 -assert list[] == [10, 30] +assert Float64.hypot(3, 4) == 5 ``` -## List.random +## Float64.is_between ```tomo -List.random : func(list: [T], random: func(min,max:Int64->Int64)? = none -> T) +Float64.is_between : func(x: Float64, low: Float64, high: Float64 -> Bool) ``` -Selects a random element from the list. +Determines if a number is between two numbers (inclusive). Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list from which to select a random element. | - -random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` +x | `Float64` | The integer to be checked. | - +low | `Float64` | The lower bound to check (inclusive). | - +high | `Float64` | The upper bound to check (inclusive). | - -**Return:** A random element from the list. +**Return:** `yes` if `low <= x and x <= high`, otherwise `no` **Example:** ```tomo -assert [10, 20, 30].random() == 20 +assert (7.5).is_between(1, 10) == yes +assert (7.5).is_between(100, 200) == no +assert (7.5).is_between(1, 7.5) == yes ``` -## List.remove_at +## Float64.isfinite ```tomo -List.remove_at : func(list: @[T], at: Int = -1, count: Int = 1 -> Void) +Float64.isfinite : func(n: Float64 -> Bool) ``` -Removes elements from the list starting at a specified index. - -Since negative indices are counted from the back, the default behavior is to remove the last item. +Checks if a number is finite. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list. | - -at | `Int` | The index at which to start removing elements. | `-1` -count | `Int` | The number of elements to remove. | `1` +n | `Float64` | The number to be checked. | - -**Return:** Nothing. +**Return:** `yes` if `n` is finite, `no` otherwise. **Example:** ```tomo -list := [10, 20, 30, 40, 50] -list.remove_at(2) -assert list == [10, 30, 40, 50] - -list.remove_at(2, count=2) -assert list == [10, 50] +assert (1.0).isfinite() == yes +assert Float64.INF.isfinite() == no ``` -## List.remove_item +## Float64.isinf ```tomo -List.remove_item : func(list: @[T], item: T, max_count: Int = -1 -> Void) +Float64.isinf : func(n: Float64 -> Bool) ``` -Removes all occurrences of a specified item from the list. - -A negative `max_count` means "remove all occurrences". +Checks if a number is infinite. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list. | - -item | `T` | The item to be removed. | - -max_count | `Int` | The maximum number of occurrences to remove. | `-1` +n | `Float64` | The number to be checked. | - -**Return:** Nothing. +**Return:** `yes` if `n` is infinite, `no` otherwise. **Example:** ```tomo -list := [10, 20, 10, 20, 30] -list.remove_item(10) -assert list == [20, 20, 30] - -list.remove_item(20, max_count=1) -assert list == [20, 30] +assert Float64.INF.isinf() == yes +assert (1.0).isinf() == no ``` -## List.reversed +## Float64.j0 ```tomo -List.reversed : func(list: [T] -> [T]) +Float64.j0 : func(x: Float64 -> Float64) ``` -Returns a reversed slice of the list. +Computes the Bessel function of the first kind of order 0. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to be reversed. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - -**Return:** A slice of the list with elements in reverse order. +**Return:** The Bessel function of the first kind of order 0 of `x`. **Example:** ```tomo -assert [10, 20, 30].reversed() == [30, 20, 10] +assert (0.0).j0() == 1 ``` -## List.sample +## Float64.j1 ```tomo -List.sample : func(list: [T], count: Int, weights: [Num]? = none, random: func(->Num)? = none -> [T]) +Float64.j1 : func(x: Float64 -> Float64) ``` -Selects a sample of elements from the list, optionally with weighted probabilities. - -Errors will be raised if any of the following conditions occurs: - The given list has no elements and `count >= 1` - `count < 0` (negative count) - The number of weights provided doesn't match the length of the list. - Any weight in the weights list is negative, infinite, or `NaN` - The sum of the given weights is zero (zero probability for every element). +Computes the Bessel function of the first kind of order 1. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to sample from. | - -count | `Int` | The number of elements to sample. | - -weights | `[Num]?` | The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. | `none` -random | `func(->Num)?` | If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) | `none` +x | `Float64` | The number for which the Bessel function is to be calculated. | - -**Return:** A list of sampled elements from the list. +**Return:** The Bessel function of the first kind of order 1 of `x`. **Example:** ```tomo -assert [10, 20, 30].sample(2, weights=[90%, 5%, 5%]) == [10, 10] +assert (0.0).j1() == 0 ``` -## List.shuffle +## Float64.log ```tomo -List.shuffle : func(list: @[T], random: func(min,max:Int64->Int64)? = none -> Void) +Float64.log : func(x: Float64 -> Float64) ``` -Shuffles the elements of the list in place. +Computes the natural logarithm (base $e$) of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list to be shuffled. | - -random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` +x | `Float64` | The number for which the natural logarithm is to be calculated. | - -**Return:** Nothing. +**Return:** The natural logarithm of `x`. **Example:** ```tomo -list.shuffle() +assert Float64.E.log() == 1 ``` -## List.shuffled +## Float64.log10 ```tomo -List.shuffled : func(list: [T], random: func(min,max:Int64->Int64)? = none -> [T]) +Float64.log10 : func(x: Float64 -> Float64) ``` -Creates a new list with elements shuffled. +Computes the base-10 logarithm of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to be shuffled. | - -random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` +x | `Float64` | The number for which the base-10 logarithm is to be calculated. | - -**Return:** A new list with shuffled elements. +**Return:** The base-10 logarithm of `x`. **Example:** ```tomo -assert [10, 20, 30, 40].shuffled() == [40, 10, 30, 20] +assert (100.0).log10() == 2 ``` -## List.slice +## Float64.log1p ```tomo -List.slice : func(list: [T], from: Int, to: Int -> [T]) +Float64.log1p : func(x: Float64 -> Float64) ``` -Returns a slice of the list spanning the given indices (inclusive). +Computes $\log(1 + x)$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The original list. | - -from | `Int` | The first index to include. | - -to | `Int` | The last index to include. | - +x | `Float64` | The number for which $\log(1 + x)$ is to be calculated. | - -**Return:** A new list spanning the given indices. Note: negative indices are counted from the back of the list, so `-1` refers to the last element, `-2` the second-to-last, and so on. +**Return:** The value of $\log(1 + x)$. **Example:** ```tomo -assert [10, 20, 30, 40, 50].slice(2, 4) == [20, 30, 40] -assert [10, 20, 30, 40, 50].slice(-3, -2) == [30, 40] +assert (1.0).log1p() == 0.6931 ``` -## List.sort +## Float64.log2 ```tomo -List.sort : func(list: @[T], by = T.compare -> Void) +Float64.log2 : func(x: Float64 -> Float64) ``` -Sorts the elements of the list in place in ascending order (small to large). +Computes the base-2 logarithm of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `@[T]` | The mutable reference to the list to be sorted. | - -by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The number for which the base-2 logarithm is to be calculated. | - -**Return:** Nothing. +**Return:** The base-2 logarithm of `x`. **Example:** ```tomo -list := [40, 10, -30, 20] -list.sort() -assert list == [-30, 10, 20, 40] - -list.sort(func(a,b:&Int): a.abs() <> b.abs()) -assert list == [10, 20, -30, 40] +assert (8.0).log2() == 3 ``` -## List.sorted +## Float64.logb ```tomo -List.sorted : func(list: [T], by = T.compare -> [T]) +Float64.logb : func(x: Float64 -> Float64) ``` -Creates a new list with elements sorted. +Computes the binary exponent (base-2 logarithm) of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to be sorted. | - -by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` +x | `Float64` | The number for which the binary exponent is to be calculated. | - -**Return:** A new list with sorted elements. +**Return:** The binary exponent of `x`. **Example:** ```tomo -assert [40, 10, -30, 20].sorted() == [-30, 10, 20, 40] -assert [40, 10, -30, 20].sorted( - func(a,b:&Int): a.abs() <> b.abs() -) == [10, 20, -30, 40] +assert (8.0).logb() == 3 ``` -## List.to +## Float64.mix ```tomo -List.to : func(list: [T], last: Int -> [T]) +Float64.mix : func(amount: Float64, x: Float64, y: Float64 -> Float64) ``` -Returns a slice of the list from the start of the original list up to a specified index (inclusive). +Interpolates between two numbers based on a given amount. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The original list. | - -last | `Int` | The index up to which elements should be included. | - +amount | `Float64` | The interpolation factor (between `0` and `1`). | - +x | `Float64` | The starting number. | - +y | `Float64` | The ending number. | - -**Return:** A new list containing elements from the start up to the specified index. +**Return:** The interpolated number between `x` and `y` based on `amount`. **Example:** ```tomo -assert [10, 20, 30, 40, 50].to(3) == [10, 20, 30] -assert [10, 20, 30, 40, 50].to(-2) == [10, 20, 30, 40] +assert (0.5).mix(10, 20) == 15 +assert (0.25).mix(10, 20) == 12.5 ``` -## List.unique +## Float64.near ```tomo -List.unique : func(list: [T] -> {T}) +Float64.near : func(x: Float64, y: Float64, ratio: Float64 = 1e-9, min_epsilon: Float64 = 1e-9 -> Bool) ``` -Returns a set of the unique elements of the list. +Checks if two numbers are approximately equal within specified tolerances. If two numbers are within an absolute difference or the ratio between the two is small enough, they are considered near each other. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to process. | - +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - +ratio | `Float64` | The relative tolerance. Default is `1e-9`. | `1e-9` +min_epsilon | `Float64` | The absolute tolerance. Default is `1e-9`. | `1e-9` -**Return:** A set of the unique elements from the list. +**Return:** `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise. **Example:** ```tomo -assert [10, 20, 10, 10, 30].unique() == {10, 20, 30} +assert (1.0).near(1.000000001) == yes +assert (100.0).near(110, ratio=0.1) == yes +assert (5.0).near(5.1, min_epsilon=0.1) == yes ``` -## List.where +## Float64.nextafter ```tomo -List.where : func(list: [T], predicate: func(item:&T -> Bool) -> Int) +Float64.nextafter : func(x: Float64, y: Float64 -> Float64) ``` -Find the index of the first item that matches a predicate function (if any). +Computes the next representable value after a given number towards a specified direction. Argument | Type | Description | Default ---------|------|-------------|--------- -list | `[T]` | The list to search through. | - -predicate | `func(item:&T -> Bool)` | A function that returns `yes` if the item's index should be returned or `no` if it should not. | - +x | `Float64` | The starting number. | - +y | `Float64` | The direction towards which to find the next representable value. | - -**Return:** Returns the index of the first item where the predicate is true or `none` if no item matches. +**Return:** The next representable value after `x` in the direction of `y`. **Example:** ```tomo -assert [4, 5, 6].where(func(i:&Int): i.is_prime()) == 5 -assert [4, 6, 8].find(func(i:&Int): i.is_prime()) == none +assert (1.0).nextafter(1.1) == 1.0000000000000002 ``` - -# Num -## Num.1_PI +## Float64.parse ```tomo -Num.1_PI : Num +Float64.parse : func(text: Text, remainder: &Text? = none -> Float64?) ``` -The constant $\frac{1}{\pi}$. - -## Num.2_PI +Converts a text representation of a number into a floating-point number. -```tomo -Num.2_PI : Num -``` +Argument | Type | Description | Default +---------|------|-------------|--------- +text | `Text` | The text containing the number. | - +remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none` -The constant $2 \times \pi$. +**Return:** The number represented by the text or `none` if the entire text can't be parsed as a number. -## Num.2_SQRTPI +**Example:** ```tomo -Num.2_SQRTPI : Num -``` - -The constant $2 \times \sqrt{\pi}$. +assert Float64.parse("3.14") == 3.14 +assert Float64.parse("1e3") == 1000 +assert Float64.parse("1.5junk") == none +remainder : Text +assert Float64.parse("1.5junk", &remainder) == 1.5 +assert remainder == "junk" -## Num.E +``` +## Float64.percent ```tomo -Num.E : Num +Float64.percent : func(n: Float64, precision: Float64 = 0.01 -> Text) ``` -The base of the natural logarithm ($e$). - -## Num.INF +Convert a number into a percentage text with a percent sign. -```tomo -Num.INF : Num -``` +Argument | Type | Description | Default +---------|------|-------------|--------- +n | `Float64` | The number to be converted to a percent. | - +precision | `Float64` | Round the percentage to this precision level. | `0.01` -Positive infinity. +**Return:** A text representation of the number as a percentage with a percent sign. -## Num.LN10 +**Example:** ```tomo -Num.LN10 : Num -``` - -The natural logarithm of 10. +assert (0.5).percent() == "50%" +assert (1./3.).percent(2) == "33.33%" +assert (1./3.).percent(2, precision=0.0001) == "33.3333%" +assert (1./3.).percent(2, precision=10.) == "30%" -## Num.LN2 +``` +## Float64.rint ```tomo -Num.LN2 : Num +Float64.rint : func(x: Float64 -> Float64) ``` -The natural logarithm of 2. +Rounds a number to the nearest integer, with ties rounded to the nearest even integer. -## Num.LOG2E +Argument | Type | Description | Default +---------|------|-------------|--------- +x | `Float64` | The number to be rounded. | - -```tomo -Num.LOG2E : Num -``` +**Return:** The nearest integer value of `x`. -The base 2 logarithm of $e$ -## Num.PI +**Example:** +```tomo +assert (3.5).rint() == 4 +assert (2.5).rint() == 2 + +``` +## Float64.round ```tomo -Num.PI : Num +Float64.round : func(x: Float64 -> Float64) ``` -Pi ($\pi$). +Rounds a number to the nearest whole number integer. -## Num.PI_2 +Argument | Type | Description | Default +---------|------|-------------|--------- +x | `Float64` | The number to be rounded. | - -```tomo -Num.PI_2 : Num -``` +**Return:** The nearest integer value of `x`. -$\frac{\pi}{2}$ -## Num.PI_4 +**Example:** +```tomo +assert (2.3).round() == 2 +assert (2.7).round() == 3 + +``` +## Float64.significand ```tomo -Num.PI_4 : Num +Float64.significand : func(x: Float64 -> Float64) ``` -$\frac{\pi}{4}$ +Extracts the significand (or mantissa) of a number. -## Num.SQRT1_2 +Argument | Type | Description | Default +---------|------|-------------|--------- +x | `Float64` | The number from which to extract the significand. | - -```tomo -Num.SQRT1_2 : Num -``` +**Return:** The significand of `x`. -$\sqrt{\frac{1}{2}}$ -## Num.SQRT2 +**Example:** +```tomo +assert (1234.567).significand() == 0.1234567 + +``` +## Float64.sin ```tomo -Num.SQRT2 : Num +Float64.sin : func(x: Float64 -> Float64) ``` -$\sqrt{2}$ +Computes the sine of a number (angle in radians). -## Num.TAU +Argument | Type | Description | Default +---------|------|-------------|--------- +x | `Float64` | The angle in radians. | - -```tomo -Num.TAU : Num -``` +**Return:** The sine of `x`. -Tau ($2 \times \pi$) -## Num.abs +**Example:** +```tomo +assert (0.0).sin() == 0 + +``` +## Float64.sinh ```tomo -Num.abs : func(n: Num -> Num) +Float64.sinh : func(x: Float64 -> Float64) ``` -Calculates the absolute value of a number. +Computes the hyperbolic sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number whose absolute value is to be computed. | - +x | `Float64` | The number for which the hyperbolic sine is to be calculated. | - -**Return:** The absolute value of `n`. +**Return:** The hyperbolic sine of `x`. **Example:** ```tomo -assert (-3.5).abs() == 3.5 +assert (0.0).sinh() == 0 ``` -## Num.acos +## Float64.sqrt ```tomo -Num.acos : func(x: Num -> Num) +Float64.sqrt : func(x: Float64 -> Float64) ``` -Computes the arc cosine of a number. +Computes the square root of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc cosine is to be calculated. | - +x | `Float64` | The number for which the square root is to be calculated. | - -**Return:** The arc cosine of `x` in radians. +**Return:** The square root of `x`. **Example:** ```tomo -assert (0.0).acos() == 1.5708 +assert (16.0).sqrt() == 4 ``` -## Num.acosh +## Float64.tan ```tomo -Num.acosh : func(x: Num -> Num) +Float64.tan : func(x: Float64 -> Float64) ``` -Computes the inverse hyperbolic cosine of a number. +Computes the tangent of a number (angle in radians). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic cosine is to be calculated. | - +x | `Float64` | The angle in radians. | - -**Return:** The inverse hyperbolic cosine of `x`. +**Return:** The tangent of `x`. **Example:** ```tomo -assert (1.0).acosh() == 0 +assert (0.0).tan() == 0 ``` -## Num.asin +## Float64.tanh ```tomo -Num.asin : func(x: Num -> Num) +Float64.tanh : func(x: Float64 -> Float64) ``` -Computes the arc sine of a number. +Computes the hyperbolic tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc sine is to be calculated. | - +x | `Float64` | The number for which the hyperbolic tangent is to be calculated. | - -**Return:** The arc sine of `x` in radians. +**Return:** The hyperbolic tangent of `x`. **Example:** ```tomo -assert (0.5).asin() == 0.5236 +assert (0.0).tanh() == 0 ``` -## Num.asinh +## Float64.tgamma ```tomo -Num.asinh : func(x: Num -> Num) +Float64.tgamma : func(x: Float64 -> Float64) ``` -Computes the inverse hyperbolic sine of a number. +Computes the gamma function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic sine is to be calculated. | - +x | `Float64` | The number for which the gamma function is to be calculated. | - -**Return:** The inverse hyperbolic sine of `x`. +**Return:** The gamma function of `x`. **Example:** ```tomo -assert (0.0).asinh() == 0 +assert (1.0).tgamma() == 1 ``` -## Num.atan +## Float64.trunc ```tomo -Num.atan : func(x: Num -> Num) +Float64.trunc : func(x: Float64 -> Float64) ``` -Computes the arc tangent of a number. +Truncates a number to the nearest integer towards zero. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc tangent is to be calculated. | - +x | `Float64` | The number to be truncated. | - -**Return:** The arc tangent of `x` in radians. +**Return:** The integer part of `x` towards zero. **Example:** ```tomo -assert (1.0).atan() == 0.7854 +assert (3.7).trunc() == 3 +assert (-3.7).trunc() == -3 ``` -## Num.atan2 +## Float64.with_precision ```tomo -Num.atan2 : func(x: Num, y: Num -> Num) +Float64.with_precision : func(n: Float64, precision: Float64 -> Float64) ``` -Computes the arc tangent of the quotient of two numbers. +Round a number to the given precision level (specified as `10`, `.1`, `.001` etc). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The numerator. | - -y | `Num` | The denominator. | - +n | `Float64` | The number to be rounded to a given precision. | - +precision | `Float64` | The precision to which the number should be rounded. | - -**Return:** The arc tangent of `x/y` in radians. +**Return:** The number, rounded to the given precision level. **Example:** ```tomo -assert Num.atan2(1, 1) == 0.7854 +assert (0.1234567).with_precision(0.01) == 0.12 +assert (123456.).with_precision(100) == 123500 +assert (1234567.).with_precision(5) == 1234565 ``` -## Num.atanh +## Float64.y0 ```tomo -Num.atanh : func(x: Num -> Num) +Float64.y0 : func(x: Float64 -> Float64) ``` -Computes the inverse hyperbolic tangent of a number. +Computes the Bessel function of the second kind of order 0. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic tangent is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - -**Return:** The inverse hyperbolic tangent of `x`. +**Return:** The Bessel function of the second kind of order 0 of `x`. **Example:** ```tomo -assert (0.5).atanh() == 0.5493 +assert (1.0).y0() == -0.7652 ``` -## Num.cbrt +## Float64.y1 ```tomo -Num.cbrt : func(x: Num -> Num) +Float64.y1 : func(x: Float64 -> Float64) ``` -Computes the cube root of a number. +Computes the Bessel function of the second kind of order 1. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the cube root is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - -**Return:** The cube root of `x`. +**Return:** The Bessel function of the second kind of order 1 of `x`. **Example:** ```tomo -assert (27.0).cbrt() == 3 +assert (1.0).y1() == 0.4401 ``` -## Num.ceil + +# Int +## Int.abs ```tomo -Num.ceil : func(x: Num -> Num) +Int.abs : func(x: Int -> Int) ``` -Rounds a number up to the nearest integer. +Calculates the absolute value of an integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded up. | - +x | `Int` | The integer whose absolute value is to be calculated. | - -**Return:** The smallest integer greater than or equal to `x`. +**Return:** The absolute value of `x`. **Example:** ```tomo -assert (3.2).ceil() == 4 +assert (-10).abs() == 10 ``` -## Num.clamped +## Int.choose ```tomo -Num.clamped : func(x: Num, low: Num, high: Num -> Num) +Int.choose : func(n: Int, k: Int -> Int) ``` -Returns the given number clamped between two values so that it is within that range. +Computes the binomial coefficient of the given numbers (the equivalent of `n` choose `k` in combinatorics). This is equal to `n.factorial()/(k.factorial() * (n-k).factorial())`. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to clamp. | - -low | `Num` | The lowest value the result can take. | - -high | `Num` | The highest value the result can take. | - +n | `Int` | The number of things to choose from. | - +k | `Int` | The number of things to be chosen. | - -**Return:** The first argument clamped between the other two arguments. +**Return:** The binomial coefficient, equivalent to the number of ways to uniquely choose `k` objects from among `n` objects, ignoring order. **Example:** ```tomo -assert (2.5).clamped(5.5, 10.5) == 5.5 +assert (4).choose(2) == 6 ``` -## Num.copysign +## Int.clamped ```tomo -Num.copysign : func(x: Num, y: Num -> Num) +Int.clamped : func(x: Int, low: Int, high: Int -> Int) ``` -Copies the sign of one number to another. +Returns the given number clamped between two values so that it is within that range. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number whose magnitude will be copied. | - -y | `Num` | The number whose sign will be copied. | - +x | `Int` | The integer to clamp. | - +low | `Int` | The lowest value the result can take. | - +high | `Int` | The highest value the result can take. | - -**Return:** A number with the magnitude of `x` and the sign of `y`. +**Return:** The first argument clamped between the other two arguments. **Example:** ```tomo -assert (3.0).copysign(-1) == -3 +assert (2).clamped(5, 10) == 5 ``` -## Num.cos +## Int.factorial ```tomo -Num.cos : func(x: Num -> Num) +Int.factorial : func(n: Int -> Text) ``` -Computes the cosine of a number (angle in radians). +Computes the factorial of an integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +n | `Int` | The integer to compute the factorial of. | - -**Return:** The cosine of `x`. +**Return:** The factorial of the given integer. **Example:** ```tomo -assert (0.0).cos() == 1 +assert (10).factorial() == 3628800 ``` -## Num.cosh +## Int.get_bit ```tomo -Num.cosh : func(x: Num -> Num) +Int.get_bit : func(i: Int, bit_index: Int -> Bool) ``` -Computes the hyperbolic cosine of a number. +In the binary representation of an integer, check whether a given bit index is set to 1 or not. + +For fixed-size integers, the bit index must be between 1 and the number of bits in that integer (i.e. 1-64 for `Int64`). For `Int`, the bit index must be between 1 and `Int64.max`. Values outside this range will produce a runtime error. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic cosine is to be calculated. | - +i | `Int` | The integer whose bits are being inspected. | - +bit_index | `Int` | The index of the bit to check (1-indexed). | - -**Return:** The hyperbolic cosine of `x`. +**Return:** Whether or not the given bit index is set to 1 in the binary representation of the integer. **Example:** ```tomo -assert (0.0).cosh() == 1 +assert (6).get_bit(1) == no +assert (6).get_bit(2) == yes +assert (6).get_bit(3) == yes +assert (6).get_bit(4) == no ``` -## Num.erf +## Int.hex ```tomo -Num.erf : func(x: Num -> Num) +Int.hex : func(i: Int, digits: Int = 0, uppercase: Bool = yes, prefix: Bool = yes -> Text) ``` -Computes the error function of a number. +Converts an integer to its hexadecimal representation. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the error function is to be calculated. | - +i | `Int` | The integer to be converted. | - +digits | `Int` | The minimum number of digits in the output string. | `0` +uppercase | `Bool` | Whether to use uppercase letters for hexadecimal digits. | `yes` +prefix | `Bool` | Whether to include a "0x" prefix. | `yes` -**Return:** The error function of `x`. +**Return:** The hexadecimal string representation of the integer. **Example:** ```tomo -assert (0.0).erf() == 0 +assert (255).hex(digits=4, uppercase=yes, prefix=yes) == "0x00FF" ``` -## Num.erfc +## Int.is_between ```tomo -Num.erfc : func(x: Num -> Num) +Int.is_between : func(x: Int, low: Int, high: Int -> Bool) ``` -Computes the complementary error function of a number. +Determines if an integer is between two numbers (inclusive). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the complementary error function is to be calculated. | - +x | `Int` | The integer to be checked. | - +low | `Int` | The lower bound to check (inclusive). | - +high | `Int` | The upper bound to check (inclusive). | - -**Return:** The complementary error function of `x`. +**Return:** `yes` if `low <= x and x <= high`, otherwise `no` **Example:** ```tomo -assert (0.0).erfc() == 1 +assert (7).is_between(1, 10) == yes +assert (7).is_between(100, 200) == no +assert (7).is_between(1, 7) == yes ``` -## Num.exp +## Int.is_prime ```tomo -Num.exp : func(x: Num -> Num) +Int.is_prime : func(x: Int, reps: Int = 50 -> Bool) ``` -Computes the exponential function $e^x$ for a number. +Determines if an integer is a prime number. + +This function is _probabilistic_. With the default arguments, the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +x | `Int` | The integer to be checked. | - +reps | `Int` | The number of repetitions for primality tests. | `50` -**Return:** The value of $e^x$. +**Return:** `yes` if `x` is a prime number, `no` otherwise. **Example:** ```tomo -assert (1.0).exp() == 2.7183 +assert (7).is_prime() == yes +assert (6).is_prime() == no ``` -## Num.exp2 +## Int.next_prime ```tomo -Num.exp2 : func(x: Num -> Num) +Int.next_prime : func(x: Int -> Int) ``` -Computes $2^x$ for a number. +Finds the next prime number greater than the given integer. + +This function is _probabilistic_, but the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +x | `Int` | The integer after which to find the next prime. | - -**Return:** The value of $2^x$. +**Return:** The next prime number greater than `x`. **Example:** ```tomo -assert (3.0).exp2() == 8 +assert (11).next_prime() == 13 ``` -## Num.expm1 +## Int.octal ```tomo -Num.expm1 : func(x: Num -> Num) +Int.octal : func(i: Int, digits: Int = 0, prefix: Bool = yes -> Text) ``` -Computes $e^x - 1$ for a number. +Converts an integer to its octal representation. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +i | `Int` | The integer to be converted. | - +digits | `Int` | The minimum number of digits in the output string. | `0` +prefix | `Bool` | Whether to include a "0o" prefix. | `yes` -**Return:** The value of $e^x - 1$. +**Return:** The octal string representation of the integer. **Example:** ```tomo -assert (1.0).expm1() == 1.7183 +assert (64).octal(digits=4, prefix=yes) == "0o0100" ``` -## Num.fdim +## Int.onward ```tomo -Num.fdim : func(x: Num, y: Num -> Num) +Int.onward : func(first: Int, step: Int = 1 -> Text) ``` -Computes the positive difference between two numbers. +Return an iterator that counts infinitely from the starting integer (with an optional step size). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - +first | `Int` | The starting integer. | - +step | `Int` | The increment step size. | `1` -**Return:** The positive difference $\max(0, x - y)$. +**Return:** An iterator function that counts onward from the starting integer. **Example:** ```tomo -fd - -assert (5.0).fdim(3) == 2 +nums : &[Int] = &[] +for i in (5).onward() +nums.insert(i) +stop if i == 10 +assert nums[] == [5, 6, 7, 8, 9, 10] ``` -## Num.floor +## Int.parse ```tomo -Num.floor : func(x: Num -> Num) +Int.parse : func(text: Text, remainder: &Text? = none -> Int?) ``` -Rounds a number down to the nearest integer. +Converts a text representation of an integer into an integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded down. | - +text | `Text` | The text containing the integer. | - +remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none` -**Return:** The largest integer less than or equal to `x`. +**Return:** The integer represented by the text. If the given text contains a value outside of the representable range or if the entire text can't be parsed as an integer, `none` will be returned. **Example:** ```tomo -assert (3.7).floor() == 3 +assert Int.parse("123") == 123 +assert Int.parse("0xFF") == 255 +assert Int.parse("123xyz") == none +remainder : Text +assert Int.parse("123xyz", &remainder) == 123 +assert remainder == "xyz" + +# Can't parse: +assert Int.parse("asdf") == none + +# Outside valid range: +assert Int8.parse("9999999") == none ``` -## Num.hypot +## Int.prev_prime ```tomo -Num.hypot : func(x: Num, y: Num -> Num) +Int.prev_prime : func(x: Int -> Int?) ``` -Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers. +Finds the previous prime number less than the given integer. If there is no previous prime number (i.e. if a number less than `2` is provided), then the function will create a runtime error. + +This function is _probabilistic_, but the chances of getting an incorrect answer are astronomically small (on the order of 10^(-30)). See [the GNU MP docs](https://gmplib.org/manual/Number-Theoretic-Functions#index-mpz_005fprobab_005fprime_005fp) for more details. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - +x | `Int` | The integer before which to find the previous prime. | - -**Return:** The Euclidean norm of `x` and `y`. +**Return:** The previous prime number less than `x`, or `none` if `x` is less than 2. **Example:** ```tomo -assert Num.hypot(3, 4) == 5 +assert (11).prev_prime() == 7 ``` -## Num.is_between +## Int.sqrt ```tomo -Num.is_between : func(x: Num, low: Num, high: Num -> Bool) +Int.sqrt : func(x: Int -> Int) ``` -Determines if a number is between two numbers (inclusive). +Calculates the nearest square root of an integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The integer to be checked. | - -low | `Num` | The lower bound to check (inclusive). | - -high | `Num` | The upper bound to check (inclusive). | - +x | `Int` | The integer whose square root is to be calculated. | - -**Return:** `yes` if `low <= x and x <= high`, otherwise `no` +**Return:** The integer part of the square root of `x`. **Example:** ```tomo -assert (7.5).is_between(1, 10) == yes -assert (7.5).is_between(100, 200) == no -assert (7.5).is_between(1, 7.5) == yes +assert (16).sqrt() == 4 +assert (17).sqrt() == 4 ``` -## Num.isfinite +## Int.to ```tomo -Num.isfinite : func(n: Num -> Bool) +Int.to : func(first: Int, last: Int, step: Int? = none -> func(->Int?)) ``` -Checks if a number is finite. +Returns an iterator function that iterates over the range of numbers specified. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be checked. | - +first | `Int` | The starting value of the range. | - +last | `Int` | The ending value of the range. | - +step | `Int?` | An optional step size to use. If unspecified or `none`, the step will be inferred to be `+1` if `last >= first`, otherwise `-1`. | `none` -**Return:** `yes` if `n` is finite, `no` otherwise. +**Return:** An iterator function that returns each integer in the given range (inclusive). **Example:** ```tomo -assert (1.0).isfinite() == yes -assert Num.INF.isfinite() == no +iter := (2).to(5) +assert iter() == 2 +assert iter() == 3 +assert iter() == 4 +assert iter() == 5 +assert iter() == none + +assert [x for x in (2).to(5)] == [2, 3, 4, 5] +assert [x for x in (5).to(2)] == [5, 4, 3, 2] +assert [x for x in (2).to(5, step=2)] == [2, 4] ``` -## Num.isinf + +# List +## List.binary_search ```tomo -Num.isinf : func(n: Num -> Bool) +List.binary_search : func(list: [T], by: func(x,y:&T->Int32) = T.compare -> Int) ``` -Checks if a number is infinite. +Performs a binary search on a sorted list. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be checked. | - +list | `[T]` | The sorted list to search. | - +by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** `yes` if `n` is infinite, `no` otherwise. +**Return:** Assuming the input list is sorted according to the given comparison function, return the index where the given item would be inserted to maintain the sorted order. That is, if the item is found, return its index, otherwise return the place where it would be found if it were inserted and the list were sorted. **Example:** ```tomo -assert Num.INF.isinf() == yes -assert (1.0).isinf() == no +assert [1, 3, 5, 7, 9].binary_search(5) == 3 +assert [1, 3, 5, 7, 9].binary_search(-999) == 1 +assert [1, 3, 5, 7, 9].binary_search(999) == 6 ``` -## Num.j0 +## List.by ```tomo -Num.j0 : func(x: Num -> Num) +List.by : func(list: [T], step: Int -> [T]) ``` -Computes the Bessel function of the first kind of order 0. +Creates a new list with elements spaced by the specified step value. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +list | `[T]` | The original list. | - +step | `Int` | The step value for selecting elements. | - -**Return:** The Bessel function of the first kind of order 0 of `x`. +**Return:** A new list with every `step`-th element from the original list. **Example:** ```tomo -assert (0.0).j0() == 1 +assert [1, 2, 3, 4, 5, 6].by(2) == [1, 3, 5] ``` -## Num.j1 +## List.clear ```tomo -Num.j1 : func(x: Num -> Num) +List.clear : func(list: @[T] -> Void) ``` -Computes the Bessel function of the first kind of order 1. +Clears all elements from the list. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +list | `@[T]` | The mutable reference to the list to be cleared. | - -**Return:** The Bessel function of the first kind of order 1 of `x`. +**Return:** Nothing. **Example:** ```tomo -assert (0.0).j1() == 0 +my_list.clear() ``` -## Num.log +## List.counts ```tomo -Num.log : func(x: Num -> Num) +List.counts : func(list: [T] -> {T=Int}) ``` -Computes the natural logarithm (base $e$) of a number. +Counts the occurrences of each element in the list. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the natural logarithm is to be calculated. | - +list | `[T]` | The list to count elements in. | - -**Return:** The natural logarithm of `x`. +**Return:** A table mapping each element to its count. **Example:** ```tomo -assert Num.E.log() == 1 +assert [10, 20, 30, 30, 30].counts() == {10=1, 20=1, 30=3} ``` -## Num.log10 +## List.find ```tomo -Num.log10 : func(x: Num -> Num) +List.find : func(list: [T], target: T -> Int?) ``` -Computes the base-10 logarithm of a number. +Finds the index of the first occurrence of an element (if any). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the base-10 logarithm is to be calculated. | - +list | `[T]` | The list to search through. | - +target | `T` | The item to search for. | - -**Return:** The base-10 logarithm of `x`. +**Return:** The index of the first occurrence or `none` if not found. **Example:** ```tomo -assert (100.0).log10() == 2 +assert [10, 20, 30, 40, 50].find(20) == 2 +assert [10, 20, 30, 40, 50].find(9999) == none ``` -## Num.log1p +## List.from ```tomo -Num.log1p : func(x: Num -> Num) +List.from : func(list: [T], first: Int -> [T]) ``` -Computes $\log(1 + x)$ for a number. +Returns a slice of the list starting from a specified index. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which $\log(1 + x)$ is to be calculated. | - +list | `[T]` | The original list. | - +first | `Int` | The index to start from. | - -**Return:** The value of $\log(1 + x)$. +**Return:** A new list starting from the specified index. **Example:** ```tomo -assert (1.0).log1p() == 0.6931 +assert [10, 20, 30, 40, 50].from(3) == [30, 40, 50] ``` -## Num.log2 +## List.has ```tomo -Num.log2 : func(x: Num -> Num) +List.has : func(list: [T], target: T -> Bool) ``` -Computes the base-2 logarithm of a number. +Checks if the list has an element. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the base-2 logarithm is to be calculated. | - +list | `[T]` | The list to check. | - +target | `T` | The element to check for. | - -**Return:** The base-2 logarithm of `x`. +**Return:** `yes` if the list has the element, `no` otherwise. **Example:** ```tomo -assert (8.0).log2() == 3 +assert [10, 20, 30].has(20) == yes ``` -## Num.logb +## List.heap_pop ```tomo -Num.logb : func(x: Num -> Num) +List.heap_pop : func(list: @[T], by: func(x,y:&T->Int32) = T.compare -> T?) ``` -Computes the binary exponent (base-2 logarithm) of a number. +Removes and returns the top element of a heap or `none` if the list is empty. By default, this is the *minimum* value in the heap. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the binary exponent is to be calculated. | - +list | `@[T]` | The mutable reference to the heap. | - +by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** The binary exponent of `x`. +**Return:** The removed top element of the heap or `none` if the list is empty. **Example:** ```tomo -assert (8.0).logb() == 3 +my_heap := [30, 10, 20] +my_heap.heapify() +assert my_heap.heap_pop() == 10 ``` -## Num.mix +## List.heap_push ```tomo -Num.mix : func(amount: Num, x: Num, y: Num -> Num) +List.heap_push : func(list: @[T], item: T, by = T.compare -> Void) ``` -Interpolates between two numbers based on a given amount. +Adds an element to the heap and maintains the heap property. By default, this is a *minimum* heap. Argument | Type | Description | Default ---------|------|-------------|--------- -amount | `Num` | The interpolation factor (between `0` and `1`). | - -x | `Num` | The starting number. | - -y | `Num` | The ending number. | - +list | `@[T]` | The mutable reference to the heap. | - +item | `T` | The item to be added. | - +by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** The interpolated number between `x` and `y` based on `amount`. +**Return:** Nothing. **Example:** ```tomo -assert (0.5).mix(10, 20) == 15 -assert (0.25).mix(10, 20) == 12.5 +my_heap.heap_push(10) ``` -## Num.near +## List.heapify ```tomo -Num.near : func(x: Num, y: Num, ratio: Num = 1e-9, min_epsilon: Num = 1e-9 -> Bool) +List.heapify : func(list: @[T], by: func(x,y:&T->Int32) = T.compare -> Void) ``` -Checks if two numbers are approximately equal within specified tolerances. If two numbers are within an absolute difference or the ratio between the two is small enough, they are considered near each other. +Converts a list into a heap. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - -ratio | `Num` | The relative tolerance. Default is `1e-9`. | `1e-9` -min_epsilon | `Num` | The absolute tolerance. Default is `1e-9`. | `1e-9` +list | `@[T]` | The mutable reference to the list to be heapified. | - +by | `func(x,y:&T->Int32)` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise. +**Return:** Nothing. **Example:** ```tomo -assert (1.0).near(1.000000001) == yes -assert (100.0).near(110, ratio=0.1) == yes -assert (5.0).near(5.1, min_epsilon=0.1) == yes +my_heap := [30, 10, 20] +my_heap.heapify() ``` -## Num.nextafter +## List.insert ```tomo -Num.nextafter : func(x: Num, y: Num -> Num) +List.insert : func(list: @[T], item: T, at: Int = 0 -> Void) ``` -Computes the next representable value after a given number towards a specified direction. +Inserts an element at a specified position in the list. + +Since indices are 1-indexed and negative indices mean "starting from the back", an index of `0` means "after the last item". Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The starting number. | - -y | `Num` | The direction towards which to find the next representable value. | - +list | `@[T]` | The mutable reference to the list. | - +item | `T` | The item to be inserted. | - +at | `Int` | The index at which to insert the item. | `0` -**Return:** The next representable value after `x` in the direction of `y`. +**Return:** Nothing. **Example:** ```tomo -assert (1.0).nextafter(1.1) == 1.0000000000000002 +list := [10, 20] +list.insert(30) +assert list == [10, 20, 30] + +list.insert(999, at=2) +assert list == [10, 999, 20, 30] ``` -## Num.parse +## List.insert_all ```tomo -Num.parse : func(text: Text, remainder: &Text? = none -> Num?) +List.insert_all : func(list: @[T], items: [T], at: Int = 0 -> Void) ``` -Converts a text representation of a number into a floating-point number. +Inserts a list of items at a specified position in the list. + +Since indices are 1-indexed and negative indices mean "starting from the back", an index of `0` means "after the last item". Argument | Type | Description | Default ---------|------|-------------|--------- -text | `Text` | The text containing the number. | - -remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none` +list | `@[T]` | The mutable reference to the list. | - +items | `[T]` | The items to be inserted. | - +at | `Int` | The index at which to insert the item. | `0` -**Return:** The number represented by the text or `none` if the entire text can't be parsed as a number. +**Return:** Nothing. **Example:** ```tomo -assert Num.parse("3.14") == 3.14 -assert Num.parse("1e3") == 1000 -assert Num.parse("1.5junk") == none -remainder : Text -assert Num.parse("1.5junk", &remainder) == 1.5 -assert remainder == "junk" +list := [10, 20] +list.insert_all([30, 40]) +assert list == [10, 20, 30, 40] + +list.insert_all([99, 100], at=2) +assert list == [10, 99, 100, 20, 30, 40] ``` -## Num.percent +## List.pop ```tomo -Num.percent : func(n: Num, precision: Num = 0.01 -> Text) +List.pop : func(list: &[T], index: Int = -1 -> T?) ``` -Convert a number into a percentage text with a percent sign. +Removes and returns an item from the list. If the given index is present in the list, the item at that index will be removed and the list will become one element shorter. + +Since negative indices are counted from the back, the default behavior is to pop the last value. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be converted to a percent. | - -precision | `Num` | Round the percentage to this precision level. | `0.01` +list | `&[T]` | The list to remove an item from. | - +index | `Int` | The index from which to remove the item. | `-1` -**Return:** A text representation of the number as a percentage with a percent sign. +**Return:** `none` if the list is empty or the given index does not exist in the list, otherwise the item at the given index. **Example:** ```tomo -assert (0.5).percent() == "50%" -assert (1./3.).percent(2) == "33.33%" -assert (1./3.).percent(2, precision=0.0001) == "33.3333%" -assert (1./3.).percent(2, precision=10.) == "30%" +list := &[10, 20, 30, 40] + +assert list.pop() == 40 +assert list[] == [10, 20, 30] + +assert list.pop(index=2) == 20 +assert list[] == [10, 30] ``` -## Num.rint +## List.random ```tomo -Num.rint : func(x: Num -> Num) +List.random : func(list: [T], random: func(min,max:Int64->Int64)? = none -> T) ``` -Rounds a number to the nearest integer, with ties rounded to the nearest even integer. +Selects a random element from the list. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded. | - +list | `[T]` | The list from which to select a random element. | - +random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` -**Return:** The nearest integer value of `x`. +**Return:** A random element from the list. **Example:** ```tomo -assert (3.5).rint() == 4 -assert (2.5).rint() == 2 +assert [10, 20, 30].random() == 20 ``` -## Num.round +## List.remove_at ```tomo -Num.round : func(x: Num -> Num) +List.remove_at : func(list: @[T], at: Int = -1, count: Int = 1 -> Void) ``` -Rounds a number to the nearest whole number integer. +Removes elements from the list starting at a specified index. + +Since negative indices are counted from the back, the default behavior is to remove the last item. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded. | - +list | `@[T]` | The mutable reference to the list. | - +at | `Int` | The index at which to start removing elements. | `-1` +count | `Int` | The number of elements to remove. | `1` -**Return:** The nearest integer value of `x`. +**Return:** Nothing. **Example:** ```tomo -assert (2.3).round() == 2 -assert (2.7).round() == 3 +list := [10, 20, 30, 40, 50] +list.remove_at(2) +assert list == [10, 30, 40, 50] + +list.remove_at(2, count=2) +assert list == [10, 50] ``` -## Num.significand +## List.remove_item ```tomo -Num.significand : func(x: Num -> Num) +List.remove_item : func(list: @[T], item: T, max_count: Int = -1 -> Void) ``` -Extracts the significand (or mantissa) of a number. +Removes all occurrences of a specified item from the list. + +A negative `max_count` means "remove all occurrences". Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number from which to extract the significand. | - +list | `@[T]` | The mutable reference to the list. | - +item | `T` | The item to be removed. | - +max_count | `Int` | The maximum number of occurrences to remove. | `-1` -**Return:** The significand of `x`. +**Return:** Nothing. **Example:** ```tomo -assert (1234.567).significand() == 0.1234567 +list := [10, 20, 10, 20, 30] +list.remove_item(10) +assert list == [20, 20, 30] + +list.remove_item(20, max_count=1) +assert list == [20, 30] ``` -## Num.sin +## List.reversed ```tomo -Num.sin : func(x: Num -> Num) +List.reversed : func(list: [T] -> [T]) ``` -Computes the sine of a number (angle in radians). +Returns a reversed slice of the list. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +list | `[T]` | The list to be reversed. | - -**Return:** The sine of `x`. +**Return:** A slice of the list with elements in reverse order. **Example:** ```tomo -assert (0.0).sin() == 0 +assert [10, 20, 30].reversed() == [30, 20, 10] ``` -## Num.sinh +## List.sample ```tomo -Num.sinh : func(x: Num -> Num) +List.sample : func(list: [T], count: Int, weights: [Float64]? = none, random: func(->Float64)? = none -> [T]) ``` -Computes the hyperbolic sine of a number. +Selects a sample of elements from the list, optionally with weighted probabilities. + +Errors will be raised if any of the following conditions occurs: - The given list has no elements and `count >= 1` - `count < 0` (negative count) - The number of weights provided doesn't match the length of the list. - Any weight in the weights list is negative, infinite, or `NaN` - The sum of the given weights is zero (zero probability for every element). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic sine is to be calculated. | - +list | `[T]` | The list to sample from. | - +count | `Int` | The number of elements to sample. | - +weights | `[Float64]?` | The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. | `none` +random | `func(->Float64)?` | If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) | `none` -**Return:** The hyperbolic sine of `x`. +**Return:** A list of sampled elements from the list. **Example:** ```tomo -assert (0.0).sinh() == 0 +assert [10, 20, 30].sample(2, weights=[90%, 5%, 5%]) == [10, 10] ``` -## Num.sqrt +## List.shuffle ```tomo -Num.sqrt : func(x: Num -> Num) +List.shuffle : func(list: @[T], random: func(min,max:Int64->Int64)? = none -> Void) ``` -Computes the square root of a number. +Shuffles the elements of the list in place. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the square root is to be calculated. | - +list | `@[T]` | The mutable reference to the list to be shuffled. | - +random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` -**Return:** The square root of `x`. +**Return:** Nothing. **Example:** ```tomo -assert (16.0).sqrt() == 4 +list.shuffle() ``` -## Num.tan +## List.shuffled ```tomo -Num.tan : func(x: Num -> Num) +List.shuffled : func(list: [T], random: func(min,max:Int64->Int64)? = none -> [T]) ``` -Computes the tangent of a number (angle in radians). +Creates a new list with elements shuffled. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +list | `[T]` | The list to be shuffled. | - +random | `func(min,max:Int64->Int64)?` | If provided, this function will be used to get a random index in the list. Returned values must be between `min` and `max` (inclusive). (Used for deterministic pseudorandom number generation) | `none` -**Return:** The tangent of `x`. +**Return:** A new list with shuffled elements. **Example:** ```tomo -assert (0.0).tan() == 0 +assert [10, 20, 30, 40].shuffled() == [40, 10, 30, 20] ``` -## Num.tanh +## List.slice ```tomo -Num.tanh : func(x: Num -> Num) +List.slice : func(list: [T], from: Int, to: Int -> [T]) ``` -Computes the hyperbolic tangent of a number. +Returns a slice of the list spanning the given indices (inclusive). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic tangent is to be calculated. | - +list | `[T]` | The original list. | - +from | `Int` | The first index to include. | - +to | `Int` | The last index to include. | - -**Return:** The hyperbolic tangent of `x`. +**Return:** A new list spanning the given indices. Note: negative indices are counted from the back of the list, so `-1` refers to the last element, `-2` the second-to-last, and so on. **Example:** ```tomo -assert (0.0).tanh() == 0 +assert [10, 20, 30, 40, 50].slice(2, 4) == [20, 30, 40] +assert [10, 20, 30, 40, 50].slice(-3, -2) == [30, 40] ``` -## Num.tgamma +## List.sort ```tomo -Num.tgamma : func(x: Num -> Num) +List.sort : func(list: @[T], by = T.compare -> Void) ``` -Computes the gamma function of a number. +Sorts the elements of the list in place in ascending order (small to large). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the gamma function is to be calculated. | - +list | `@[T]` | The mutable reference to the list to be sorted. | - +by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** The gamma function of `x`. +**Return:** Nothing. **Example:** ```tomo -assert (1.0).tgamma() == 1 +list := [40, 10, -30, 20] +list.sort() +assert list == [-30, 10, 20, 40] + +list.sort(func(a,b:&Int): a.abs() <> b.abs()) +assert list == [10, 20, -30, 40] ``` -## Num.trunc +## List.sorted ```tomo -Num.trunc : func(x: Num -> Num) +List.sorted : func(list: [T], by = T.compare -> [T]) ``` -Truncates a number to the nearest integer towards zero. +Creates a new list with elements sorted. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be truncated. | - +list | `[T]` | The list to be sorted. | - +by | `` | The comparison function used to determine order. If not specified, the default comparison function for the item type will be used. | `T.compare` -**Return:** The integer part of `x` towards zero. +**Return:** A new list with sorted elements. **Example:** ```tomo -assert (3.7).trunc() == 3 -assert (-3.7).trunc() == -3 +assert [40, 10, -30, 20].sorted() == [-30, 10, 20, 40] +assert [40, 10, -30, 20].sorted( + func(a,b:&Int): a.abs() <> b.abs() +) == [10, 20, -30, 40] ``` -## Num.with_precision +## List.to ```tomo -Num.with_precision : func(n: Num, precision: Num -> Num) +List.to : func(list: [T], last: Int -> [T]) ``` -Round a number to the given precision level (specified as `10`, `.1`, `.001` etc). +Returns a slice of the list from the start of the original list up to a specified index (inclusive). Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be rounded to a given precision. | - -precision | `Num` | The precision to which the number should be rounded. | - +list | `[T]` | The original list. | - +last | `Int` | The index up to which elements should be included. | - -**Return:** The number, rounded to the given precision level. +**Return:** A new list containing elements from the start up to the specified index. **Example:** ```tomo -assert (0.1234567).with_precision(0.01) == 0.12 -assert (123456.).with_precision(100) == 123500 -assert (1234567.).with_precision(5) == 1234565 +assert [10, 20, 30, 40, 50].to(3) == [10, 20, 30] +assert [10, 20, 30, 40, 50].to(-2) == [10, 20, 30, 40] ``` -## Num.y0 +## List.unique ```tomo -Num.y0 : func(x: Num -> Num) +List.unique : func(list: [T] -> {T}) ``` -Computes the Bessel function of the second kind of order 0. +Returns a set of the unique elements of the list. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +list | `[T]` | The list to process. | - -**Return:** The Bessel function of the second kind of order 0 of `x`. +**Return:** A set of the unique elements from the list. **Example:** ```tomo -assert (1.0).y0() == -0.7652 +assert [10, 20, 10, 10, 30].unique() == {10, 20, 30} ``` -## Num.y1 +## List.where ```tomo -Num.y1 : func(x: Num -> Num) +List.where : func(list: [T], predicate: func(item:&T -> Bool) -> Int) ``` -Computes the Bessel function of the second kind of order 1. +Find the index of the first item that matches a predicate function (if any). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +list | `[T]` | The list to search through. | - +predicate | `func(item:&T -> Bool)` | A function that returns `yes` if the item's index should be returned or `no` if it should not. | - -**Return:** The Bessel function of the second kind of order 1 of `x`. +**Return:** Returns the index of the first item where the predicate is true or `none` if no item matches. **Example:** ```tomo -assert (1.0).y1() == 0.4401 +assert [4, 5, 6].where(func(i:&Int): i.is_prime()) == 5 +assert [4, 6, 8].find(func(i:&Int): i.is_prime()) == none ``` diff --git a/api/builtins.md b/api/builtins.md index 0b06a41b..dfe62306 100644 --- a/api/builtins.md +++ b/api/builtins.md @@ -163,14 +163,14 @@ setenv("FOOBAR", "xyz") ## sleep ```tomo -sleep : func(seconds: Num -> Void) +sleep : func(seconds: Float64 -> Void) ``` Pause execution for a given number of seconds. Argument | Type | Description | Default ---------|------|-------------|--------- -seconds | `Num` | How many seconds to sleep for. | - +seconds | `Float64` | How many seconds to sleep for. | - **Return:** Nothing. diff --git a/api/builtins.yaml b/api/builtins.yaml index 2eae5340..cbbac5ff 100644 --- a/api/builtins.yaml +++ b/api/builtins.yaml @@ -147,7 +147,7 @@ sleep: Nothing. args: seconds: - type: 'Num' + type: 'Float64' description: > How many seconds to sleep for. example: | diff --git a/api/nums.md b/api/floats.md index dac5967f..8d1777e8 100644 --- a/api/nums.md +++ b/api/floats.md @@ -2,130 +2,130 @@ # Builtins -# Num -## Num.1_PI +# Float64 +## Float64.1_PI ```tomo -Num.1_PI : Num +Float64.1_PI : Float64 ``` The constant $\frac{1}{\pi}$. -## Num.2_PI +## Float64.2_PI ```tomo -Num.2_PI : Num +Float64.2_PI : Float64 ``` The constant $2 \times \pi$. -## Num.2_SQRTPI +## Float64.2_SQRTPI ```tomo -Num.2_SQRTPI : Num +Float64.2_SQRTPI : Float64 ``` The constant $2 \times \sqrt{\pi}$. -## Num.E +## Float64.E ```tomo -Num.E : Num +Float64.E : Float64 ``` The base of the natural logarithm ($e$). -## Num.INF +## Float64.INF ```tomo -Num.INF : Num +Float64.INF : Float64 ``` Positive infinity. -## Num.LN10 +## Float64.LN10 ```tomo -Num.LN10 : Num +Float64.LN10 : Float64 ``` The natural logarithm of 10. -## Num.LN2 +## Float64.LN2 ```tomo -Num.LN2 : Num +Float64.LN2 : Float64 ``` The natural logarithm of 2. -## Num.LOG2E +## Float64.LOG2E ```tomo -Num.LOG2E : Num +Float64.LOG2E : Float64 ``` The base 2 logarithm of $e$ -## Num.PI +## Float64.PI ```tomo -Num.PI : Num +Float64.PI : Float64 ``` Pi ($\pi$). -## Num.PI_2 +## Float64.PI_2 ```tomo -Num.PI_2 : Num +Float64.PI_2 : Float64 ``` $\frac{\pi}{2}$ -## Num.PI_4 +## Float64.PI_4 ```tomo -Num.PI_4 : Num +Float64.PI_4 : Float64 ``` $\frac{\pi}{4}$ -## Num.SQRT1_2 +## Float64.SQRT1_2 ```tomo -Num.SQRT1_2 : Num +Float64.SQRT1_2 : Float64 ``` $\sqrt{\frac{1}{2}}$ -## Num.SQRT2 +## Float64.SQRT2 ```tomo -Num.SQRT2 : Num +Float64.SQRT2 : Float64 ``` $\sqrt{2}$ -## Num.TAU +## Float64.TAU ```tomo -Num.TAU : Num +Float64.TAU : Float64 ``` Tau ($2 \times \pi$) -## Num.abs +## Float64.abs ```tomo -Num.abs : func(n: Num -> Num) +Float64.abs : func(n: Float64 -> Float64) ``` Calculates the absolute value of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number whose absolute value is to be computed. | - +n | `Float64` | The number whose absolute value is to be computed. | - **Return:** The absolute value of `n`. @@ -135,17 +135,17 @@ n | `Num` | The number whose absolute value is to be computed. | - assert (-3.5).abs() == 3.5 ``` -## Num.acos +## Float64.acos ```tomo -Num.acos : func(x: Num -> Num) +Float64.acos : func(x: Float64 -> Float64) ``` Computes the arc cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc cosine is to be calculated. | - +x | `Float64` | The number for which the arc cosine is to be calculated. | - **Return:** The arc cosine of `x` in radians. @@ -155,17 +155,17 @@ x | `Num` | The number for which the arc cosine is to be calculated. | - assert (0.0).acos() == 1.5708 ``` -## Num.acosh +## Float64.acosh ```tomo -Num.acosh : func(x: Num -> Num) +Float64.acosh : func(x: Float64 -> Float64) ``` Computes the inverse hyperbolic cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic cosine is to be calculated. | - +x | `Float64` | The number for which the inverse hyperbolic cosine is to be calculated. | - **Return:** The inverse hyperbolic cosine of `x`. @@ -175,17 +175,17 @@ x | `Num` | The number for which the inverse hyperbolic cosine is to be calculat assert (1.0).acosh() == 0 ``` -## Num.asin +## Float64.asin ```tomo -Num.asin : func(x: Num -> Num) +Float64.asin : func(x: Float64 -> Float64) ``` Computes the arc sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc sine is to be calculated. | - +x | `Float64` | The number for which the arc sine is to be calculated. | - **Return:** The arc sine of `x` in radians. @@ -195,17 +195,17 @@ x | `Num` | The number for which the arc sine is to be calculated. | - assert (0.5).asin() == 0.5236 ``` -## Num.asinh +## Float64.asinh ```tomo -Num.asinh : func(x: Num -> Num) +Float64.asinh : func(x: Float64 -> Float64) ``` Computes the inverse hyperbolic sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic sine is to be calculated. | - +x | `Float64` | The number for which the inverse hyperbolic sine is to be calculated. | - **Return:** The inverse hyperbolic sine of `x`. @@ -215,17 +215,17 @@ x | `Num` | The number for which the inverse hyperbolic sine is to be calculated assert (0.0).asinh() == 0 ``` -## Num.atan +## Float64.atan ```tomo -Num.atan : func(x: Num -> Num) +Float64.atan : func(x: Float64 -> Float64) ``` Computes the arc tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the arc tangent is to be calculated. | - +x | `Float64` | The number for which the arc tangent is to be calculated. | - **Return:** The arc tangent of `x` in radians. @@ -235,38 +235,38 @@ x | `Num` | The number for which the arc tangent is to be calculated. | - assert (1.0).atan() == 0.7854 ``` -## Num.atan2 +## Float64.atan2 ```tomo -Num.atan2 : func(x: Num, y: Num -> Num) +Float64.atan2 : func(x: Float64, y: Float64 -> Float64) ``` Computes the arc tangent of the quotient of two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The numerator. | - -y | `Num` | The denominator. | - +x | `Float64` | The numerator. | - +y | `Float64` | The denominator. | - **Return:** The arc tangent of `x/y` in radians. **Example:** ```tomo -assert Num.atan2(1, 1) == 0.7854 +assert Float64.atan2(1, 1) == 0.7854 ``` -## Num.atanh +## Float64.atanh ```tomo -Num.atanh : func(x: Num -> Num) +Float64.atanh : func(x: Float64 -> Float64) ``` Computes the inverse hyperbolic tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the inverse hyperbolic tangent is to be calculated. | - +x | `Float64` | The number for which the inverse hyperbolic tangent is to be calculated. | - **Return:** The inverse hyperbolic tangent of `x`. @@ -276,17 +276,17 @@ x | `Num` | The number for which the inverse hyperbolic tangent is to be calcula assert (0.5).atanh() == 0.5493 ``` -## Num.cbrt +## Float64.cbrt ```tomo -Num.cbrt : func(x: Num -> Num) +Float64.cbrt : func(x: Float64 -> Float64) ``` Computes the cube root of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the cube root is to be calculated. | - +x | `Float64` | The number for which the cube root is to be calculated. | - **Return:** The cube root of `x`. @@ -296,17 +296,17 @@ x | `Num` | The number for which the cube root is to be calculated. | - assert (27.0).cbrt() == 3 ``` -## Num.ceil +## Float64.ceil ```tomo -Num.ceil : func(x: Num -> Num) +Float64.ceil : func(x: Float64 -> Float64) ``` Rounds a number up to the nearest integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded up. | - +x | `Float64` | The number to be rounded up. | - **Return:** The smallest integer greater than or equal to `x`. @@ -316,19 +316,19 @@ x | `Num` | The number to be rounded up. | - assert (3.2).ceil() == 4 ``` -## Num.clamped +## Float64.clamped ```tomo -Num.clamped : func(x: Num, low: Num, high: Num -> Num) +Float64.clamped : func(x: Float64, low: Float64, high: Float64 -> Float64) ``` Returns the given number clamped between two values so that it is within that range. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to clamp. | - -low | `Num` | The lowest value the result can take. | - -high | `Num` | The highest value the result can take. | - +x | `Float64` | The number to clamp. | - +low | `Float64` | The lowest value the result can take. | - +high | `Float64` | The highest value the result can take. | - **Return:** The first argument clamped between the other two arguments. @@ -338,18 +338,18 @@ high | `Num` | The highest value the result can take. | - assert (2.5).clamped(5.5, 10.5) == 5.5 ``` -## Num.copysign +## Float64.copysign ```tomo -Num.copysign : func(x: Num, y: Num -> Num) +Float64.copysign : func(x: Float64, y: Float64 -> Float64) ``` Copies the sign of one number to another. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number whose magnitude will be copied. | - -y | `Num` | The number whose sign will be copied. | - +x | `Float64` | The number whose magnitude will be copied. | - +y | `Float64` | The number whose sign will be copied. | - **Return:** A number with the magnitude of `x` and the sign of `y`. @@ -359,17 +359,17 @@ y | `Num` | The number whose sign will be copied. | - assert (3.0).copysign(-1) == -3 ``` -## Num.cos +## Float64.cos ```tomo -Num.cos : func(x: Num -> Num) +Float64.cos : func(x: Float64 -> Float64) ``` Computes the cosine of a number (angle in radians). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +x | `Float64` | The angle in radians. | - **Return:** The cosine of `x`. @@ -379,17 +379,17 @@ x | `Num` | The angle in radians. | - assert (0.0).cos() == 1 ``` -## Num.cosh +## Float64.cosh ```tomo -Num.cosh : func(x: Num -> Num) +Float64.cosh : func(x: Float64 -> Float64) ``` Computes the hyperbolic cosine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic cosine is to be calculated. | - +x | `Float64` | The number for which the hyperbolic cosine is to be calculated. | - **Return:** The hyperbolic cosine of `x`. @@ -399,17 +399,17 @@ x | `Num` | The number for which the hyperbolic cosine is to be calculated. | - assert (0.0).cosh() == 1 ``` -## Num.erf +## Float64.erf ```tomo -Num.erf : func(x: Num -> Num) +Float64.erf : func(x: Float64 -> Float64) ``` Computes the error function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the error function is to be calculated. | - +x | `Float64` | The number for which the error function is to be calculated. | - **Return:** The error function of `x`. @@ -419,17 +419,17 @@ x | `Num` | The number for which the error function is to be calculated. | - assert (0.0).erf() == 0 ``` -## Num.erfc +## Float64.erfc ```tomo -Num.erfc : func(x: Num -> Num) +Float64.erfc : func(x: Float64 -> Float64) ``` Computes the complementary error function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the complementary error function is to be calculated. | - +x | `Float64` | The number for which the complementary error function is to be calculated. | - **Return:** The complementary error function of `x`. @@ -439,17 +439,17 @@ x | `Num` | The number for which the complementary error function is to be calcu assert (0.0).erfc() == 1 ``` -## Num.exp +## Float64.exp ```tomo -Num.exp : func(x: Num -> Num) +Float64.exp : func(x: Float64 -> Float64) ``` Computes the exponential function $e^x$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +x | `Float64` | The exponent. | - **Return:** The value of $e^x$. @@ -459,17 +459,17 @@ x | `Num` | The exponent. | - assert (1.0).exp() == 2.7183 ``` -## Num.exp2 +## Float64.exp2 ```tomo -Num.exp2 : func(x: Num -> Num) +Float64.exp2 : func(x: Float64 -> Float64) ``` Computes $2^x$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +x | `Float64` | The exponent. | - **Return:** The value of $2^x$. @@ -479,17 +479,17 @@ x | `Num` | The exponent. | - assert (3.0).exp2() == 8 ``` -## Num.expm1 +## Float64.expm1 ```tomo -Num.expm1 : func(x: Num -> Num) +Float64.expm1 : func(x: Float64 -> Float64) ``` Computes $e^x - 1$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The exponent. | - +x | `Float64` | The exponent. | - **Return:** The value of $e^x - 1$. @@ -499,18 +499,18 @@ x | `Num` | The exponent. | - assert (1.0).expm1() == 1.7183 ``` -## Num.fdim +## Float64.fdim ```tomo -Num.fdim : func(x: Num, y: Num -> Num) +Float64.fdim : func(x: Float64, y: Float64 -> Float64) ``` Computes the positive difference between two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - **Return:** The positive difference $\max(0, x - y)$. @@ -522,17 +522,17 @@ fd assert (5.0).fdim(3) == 2 ``` -## Num.floor +## Float64.floor ```tomo -Num.floor : func(x: Num -> Num) +Float64.floor : func(x: Float64 -> Float64) ``` Rounds a number down to the nearest integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded down. | - +x | `Float64` | The number to be rounded down. | - **Return:** The largest integer less than or equal to `x`. @@ -542,40 +542,40 @@ x | `Num` | The number to be rounded down. | - assert (3.7).floor() == 3 ``` -## Num.hypot +## Float64.hypot ```tomo -Num.hypot : func(x: Num, y: Num -> Num) +Float64.hypot : func(x: Float64, y: Float64 -> Float64) ``` Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - **Return:** The Euclidean norm of `x` and `y`. **Example:** ```tomo -assert Num.hypot(3, 4) == 5 +assert Float64.hypot(3, 4) == 5 ``` -## Num.is_between +## Float64.is_between ```tomo -Num.is_between : func(x: Num, low: Num, high: Num -> Bool) +Float64.is_between : func(x: Float64, low: Float64, high: Float64 -> Bool) ``` Determines if a number is between two numbers (inclusive). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The integer to be checked. | - -low | `Num` | The lower bound to check (inclusive). | - -high | `Num` | The upper bound to check (inclusive). | - +x | `Float64` | The integer to be checked. | - +low | `Float64` | The lower bound to check (inclusive). | - +high | `Float64` | The upper bound to check (inclusive). | - **Return:** `yes` if `low <= x and x <= high`, otherwise `no` @@ -587,17 +587,17 @@ assert (7.5).is_between(100, 200) == no assert (7.5).is_between(1, 7.5) == yes ``` -## Num.isfinite +## Float64.isfinite ```tomo -Num.isfinite : func(n: Num -> Bool) +Float64.isfinite : func(n: Float64 -> Bool) ``` Checks if a number is finite. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be checked. | - +n | `Float64` | The number to be checked. | - **Return:** `yes` if `n` is finite, `no` otherwise. @@ -605,41 +605,41 @@ n | `Num` | The number to be checked. | - **Example:** ```tomo assert (1.0).isfinite() == yes -assert Num.INF.isfinite() == no +assert Float64.INF.isfinite() == no ``` -## Num.isinf +## Float64.isinf ```tomo -Num.isinf : func(n: Num -> Bool) +Float64.isinf : func(n: Float64 -> Bool) ``` Checks if a number is infinite. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be checked. | - +n | `Float64` | The number to be checked. | - **Return:** `yes` if `n` is infinite, `no` otherwise. **Example:** ```tomo -assert Num.INF.isinf() == yes +assert Float64.INF.isinf() == yes assert (1.0).isinf() == no ``` -## Num.j0 +## Float64.j0 ```tomo -Num.j0 : func(x: Num -> Num) +Float64.j0 : func(x: Float64 -> Float64) ``` Computes the Bessel function of the first kind of order 0. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - **Return:** The Bessel function of the first kind of order 0 of `x`. @@ -649,17 +649,17 @@ x | `Num` | The number for which the Bessel function is to be calculated. | - assert (0.0).j0() == 1 ``` -## Num.j1 +## Float64.j1 ```tomo -Num.j1 : func(x: Num -> Num) +Float64.j1 : func(x: Float64 -> Float64) ``` Computes the Bessel function of the first kind of order 1. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - **Return:** The Bessel function of the first kind of order 1 of `x`. @@ -669,37 +669,37 @@ x | `Num` | The number for which the Bessel function is to be calculated. | - assert (0.0).j1() == 0 ``` -## Num.log +## Float64.log ```tomo -Num.log : func(x: Num -> Num) +Float64.log : func(x: Float64 -> Float64) ``` Computes the natural logarithm (base $e$) of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the natural logarithm is to be calculated. | - +x | `Float64` | The number for which the natural logarithm is to be calculated. | - **Return:** The natural logarithm of `x`. **Example:** ```tomo -assert Num.E.log() == 1 +assert Float64.E.log() == 1 ``` -## Num.log10 +## Float64.log10 ```tomo -Num.log10 : func(x: Num -> Num) +Float64.log10 : func(x: Float64 -> Float64) ``` Computes the base-10 logarithm of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the base-10 logarithm is to be calculated. | - +x | `Float64` | The number for which the base-10 logarithm is to be calculated. | - **Return:** The base-10 logarithm of `x`. @@ -709,17 +709,17 @@ x | `Num` | The number for which the base-10 logarithm is to be calculated. | - assert (100.0).log10() == 2 ``` -## Num.log1p +## Float64.log1p ```tomo -Num.log1p : func(x: Num -> Num) +Float64.log1p : func(x: Float64 -> Float64) ``` Computes $\log(1 + x)$ for a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which $\log(1 + x)$ is to be calculated. | - +x | `Float64` | The number for which $\log(1 + x)$ is to be calculated. | - **Return:** The value of $\log(1 + x)$. @@ -729,17 +729,17 @@ x | `Num` | The number for which $\log(1 + x)$ is to be calculated. | - assert (1.0).log1p() == 0.6931 ``` -## Num.log2 +## Float64.log2 ```tomo -Num.log2 : func(x: Num -> Num) +Float64.log2 : func(x: Float64 -> Float64) ``` Computes the base-2 logarithm of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the base-2 logarithm is to be calculated. | - +x | `Float64` | The number for which the base-2 logarithm is to be calculated. | - **Return:** The base-2 logarithm of `x`. @@ -749,17 +749,17 @@ x | `Num` | The number for which the base-2 logarithm is to be calculated. | - assert (8.0).log2() == 3 ``` -## Num.logb +## Float64.logb ```tomo -Num.logb : func(x: Num -> Num) +Float64.logb : func(x: Float64 -> Float64) ``` Computes the binary exponent (base-2 logarithm) of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the binary exponent is to be calculated. | - +x | `Float64` | The number for which the binary exponent is to be calculated. | - **Return:** The binary exponent of `x`. @@ -769,19 +769,19 @@ x | `Num` | The number for which the binary exponent is to be calculated. | - assert (8.0).logb() == 3 ``` -## Num.mix +## Float64.mix ```tomo -Num.mix : func(amount: Num, x: Num, y: Num -> Num) +Float64.mix : func(amount: Float64, x: Float64, y: Float64 -> Float64) ``` Interpolates between two numbers based on a given amount. Argument | Type | Description | Default ---------|------|-------------|--------- -amount | `Num` | The interpolation factor (between `0` and `1`). | - -x | `Num` | The starting number. | - -y | `Num` | The ending number. | - +amount | `Float64` | The interpolation factor (between `0` and `1`). | - +x | `Float64` | The starting number. | - +y | `Float64` | The ending number. | - **Return:** The interpolated number between `x` and `y` based on `amount`. @@ -792,20 +792,20 @@ assert (0.5).mix(10, 20) == 15 assert (0.25).mix(10, 20) == 12.5 ``` -## Num.near +## Float64.near ```tomo -Num.near : func(x: Num, y: Num, ratio: Num = 1e-9, min_epsilon: Num = 1e-9 -> Bool) +Float64.near : func(x: Float64, y: Float64, ratio: Float64 = 1e-9, min_epsilon: Float64 = 1e-9 -> Bool) ``` Checks if two numbers are approximately equal within specified tolerances. If two numbers are within an absolute difference or the ratio between the two is small enough, they are considered near each other. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The first number. | - -y | `Num` | The second number. | - -ratio | `Num` | The relative tolerance. Default is `1e-9`. | `1e-9` -min_epsilon | `Num` | The absolute tolerance. Default is `1e-9`. | `1e-9` +x | `Float64` | The first number. | - +y | `Float64` | The second number. | - +ratio | `Float64` | The relative tolerance. Default is `1e-9`. | `1e-9` +min_epsilon | `Float64` | The absolute tolerance. Default is `1e-9`. | `1e-9` **Return:** `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise. @@ -817,18 +817,18 @@ assert (100.0).near(110, ratio=0.1) == yes assert (5.0).near(5.1, min_epsilon=0.1) == yes ``` -## Num.nextafter +## Float64.nextafter ```tomo -Num.nextafter : func(x: Num, y: Num -> Num) +Float64.nextafter : func(x: Float64, y: Float64 -> Float64) ``` Computes the next representable value after a given number towards a specified direction. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The starting number. | - -y | `Num` | The direction towards which to find the next representable value. | - +x | `Float64` | The starting number. | - +y | `Float64` | The direction towards which to find the next representable value. | - **Return:** The next representable value after `x` in the direction of `y`. @@ -838,10 +838,10 @@ y | `Num` | The direction towards which to find the next representable value. | assert (1.0).nextafter(1.1) == 1.0000000000000002 ``` -## Num.parse +## Float64.parse ```tomo -Num.parse : func(text: Text, remainder: &Text? = none -> Num?) +Float64.parse : func(text: Text, remainder: &Text? = none -> Float64?) ``` Converts a text representation of a number into a floating-point number. @@ -856,26 +856,26 @@ remainder | `&Text?` | If non-none, this argument will be set to the remainder o **Example:** ```tomo -assert Num.parse("3.14") == 3.14 -assert Num.parse("1e3") == 1000 -assert Num.parse("1.5junk") == none +assert Float64.parse("3.14") == 3.14 +assert Float64.parse("1e3") == 1000 +assert Float64.parse("1.5junk") == none remainder : Text -assert Num.parse("1.5junk", &remainder) == 1.5 +assert Float64.parse("1.5junk", &remainder) == 1.5 assert remainder == "junk" ``` -## Num.percent +## Float64.percent ```tomo -Num.percent : func(n: Num, precision: Num = 0.01 -> Text) +Float64.percent : func(n: Float64, precision: Float64 = 0.01 -> Text) ``` Convert a number into a percentage text with a percent sign. Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be converted to a percent. | - -precision | `Num` | Round the percentage to this precision level. | `0.01` +n | `Float64` | The number to be converted to a percent. | - +precision | `Float64` | Round the percentage to this precision level. | `0.01` **Return:** A text representation of the number as a percentage with a percent sign. @@ -888,17 +888,17 @@ assert (1./3.).percent(2, precision=0.0001) == "33.3333%" assert (1./3.).percent(2, precision=10.) == "30%" ``` -## Num.rint +## Float64.rint ```tomo -Num.rint : func(x: Num -> Num) +Float64.rint : func(x: Float64 -> Float64) ``` Rounds a number to the nearest integer, with ties rounded to the nearest even integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded. | - +x | `Float64` | The number to be rounded. | - **Return:** The nearest integer value of `x`. @@ -909,17 +909,17 @@ assert (3.5).rint() == 4 assert (2.5).rint() == 2 ``` -## Num.round +## Float64.round ```tomo -Num.round : func(x: Num -> Num) +Float64.round : func(x: Float64 -> Float64) ``` Rounds a number to the nearest whole number integer. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be rounded. | - +x | `Float64` | The number to be rounded. | - **Return:** The nearest integer value of `x`. @@ -930,17 +930,17 @@ assert (2.3).round() == 2 assert (2.7).round() == 3 ``` -## Num.significand +## Float64.significand ```tomo -Num.significand : func(x: Num -> Num) +Float64.significand : func(x: Float64 -> Float64) ``` Extracts the significand (or mantissa) of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number from which to extract the significand. | - +x | `Float64` | The number from which to extract the significand. | - **Return:** The significand of `x`. @@ -950,17 +950,17 @@ x | `Num` | The number from which to extract the significand. | - assert (1234.567).significand() == 0.1234567 ``` -## Num.sin +## Float64.sin ```tomo -Num.sin : func(x: Num -> Num) +Float64.sin : func(x: Float64 -> Float64) ``` Computes the sine of a number (angle in radians). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +x | `Float64` | The angle in radians. | - **Return:** The sine of `x`. @@ -970,17 +970,17 @@ x | `Num` | The angle in radians. | - assert (0.0).sin() == 0 ``` -## Num.sinh +## Float64.sinh ```tomo -Num.sinh : func(x: Num -> Num) +Float64.sinh : func(x: Float64 -> Float64) ``` Computes the hyperbolic sine of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic sine is to be calculated. | - +x | `Float64` | The number for which the hyperbolic sine is to be calculated. | - **Return:** The hyperbolic sine of `x`. @@ -990,17 +990,17 @@ x | `Num` | The number for which the hyperbolic sine is to be calculated. | - assert (0.0).sinh() == 0 ``` -## Num.sqrt +## Float64.sqrt ```tomo -Num.sqrt : func(x: Num -> Num) +Float64.sqrt : func(x: Float64 -> Float64) ``` Computes the square root of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the square root is to be calculated. | - +x | `Float64` | The number for which the square root is to be calculated. | - **Return:** The square root of `x`. @@ -1010,17 +1010,17 @@ x | `Num` | The number for which the square root is to be calculated. | - assert (16.0).sqrt() == 4 ``` -## Num.tan +## Float64.tan ```tomo -Num.tan : func(x: Num -> Num) +Float64.tan : func(x: Float64 -> Float64) ``` Computes the tangent of a number (angle in radians). Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The angle in radians. | - +x | `Float64` | The angle in radians. | - **Return:** The tangent of `x`. @@ -1030,17 +1030,17 @@ x | `Num` | The angle in radians. | - assert (0.0).tan() == 0 ``` -## Num.tanh +## Float64.tanh ```tomo -Num.tanh : func(x: Num -> Num) +Float64.tanh : func(x: Float64 -> Float64) ``` Computes the hyperbolic tangent of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the hyperbolic tangent is to be calculated. | - +x | `Float64` | The number for which the hyperbolic tangent is to be calculated. | - **Return:** The hyperbolic tangent of `x`. @@ -1050,17 +1050,17 @@ x | `Num` | The number for which the hyperbolic tangent is to be calculated. | assert (0.0).tanh() == 0 ``` -## Num.tgamma +## Float64.tgamma ```tomo -Num.tgamma : func(x: Num -> Num) +Float64.tgamma : func(x: Float64 -> Float64) ``` Computes the gamma function of a number. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the gamma function is to be calculated. | - +x | `Float64` | The number for which the gamma function is to be calculated. | - **Return:** The gamma function of `x`. @@ -1070,17 +1070,17 @@ x | `Num` | The number for which the gamma function is to be calculated. | - assert (1.0).tgamma() == 1 ``` -## Num.trunc +## Float64.trunc ```tomo -Num.trunc : func(x: Num -> Num) +Float64.trunc : func(x: Float64 -> Float64) ``` Truncates a number to the nearest integer towards zero. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number to be truncated. | - +x | `Float64` | The number to be truncated. | - **Return:** The integer part of `x` towards zero. @@ -1091,18 +1091,18 @@ assert (3.7).trunc() == 3 assert (-3.7).trunc() == -3 ``` -## Num.with_precision +## Float64.with_precision ```tomo -Num.with_precision : func(n: Num, precision: Num -> Num) +Float64.with_precision : func(n: Float64, precision: Float64 -> Float64) ``` Round a number to the given precision level (specified as `10`, `.1`, `.001` etc). Argument | Type | Description | Default ---------|------|-------------|--------- -n | `Num` | The number to be rounded to a given precision. | - -precision | `Num` | The precision to which the number should be rounded. | - +n | `Float64` | The number to be rounded to a given precision. | - +precision | `Float64` | The precision to which the number should be rounded. | - **Return:** The number, rounded to the given precision level. @@ -1114,17 +1114,17 @@ assert (123456.).with_precision(100) == 123500 assert (1234567.).with_precision(5) == 1234565 ``` -## Num.y0 +## Float64.y0 ```tomo -Num.y0 : func(x: Num -> Num) +Float64.y0 : func(x: Float64 -> Float64) ``` Computes the Bessel function of the second kind of order 0. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - **Return:** The Bessel function of the second kind of order 0 of `x`. @@ -1134,17 +1134,17 @@ x | `Num` | The number for which the Bessel function is to be calculated. | - assert (1.0).y0() == -0.7652 ``` -## Num.y1 +## Float64.y1 ```tomo -Num.y1 : func(x: Num -> Num) +Float64.y1 : func(x: Float64 -> Float64) ``` Computes the Bessel function of the second kind of order 1. Argument | Type | Description | Default ---------|------|-------------|--------- -x | `Num` | The number for which the Bessel function is to be calculated. | - +x | `Float64` | The number for which the Bessel function is to be calculated. | - **Return:** The Bessel function of the second kind of order 1 of `x`. diff --git a/api/nums.yaml b/api/floats.yaml index 4561bb91..64ec6719 100644 --- a/api/nums.yaml +++ b/api/floats.yaml @@ -1,339 +1,339 @@ -Num.abs: +Float64.abs: short: absolute value description: > Calculates the absolute value of a number. return: - type: 'Num' + type: 'Float64' description: > The absolute value of `n`. args: n: - type: 'Num' + type: 'Float64' description: > The number whose absolute value is to be computed. example: | assert (-3.5).abs() == 3.5 -Num.acos: +Float64.acos: short: arc cosine description: > Computes the arc cosine of a number. return: - type: 'Num' + type: 'Float64' description: > The arc cosine of `x` in radians. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the arc cosine is to be calculated. example: | assert (0.0).acos() == 1.5708 -Num.acosh: +Float64.acosh: short: arc hyperbolic cosine description: > Computes the inverse hyperbolic cosine of a number. return: - type: 'Num' + type: 'Float64' description: > The inverse hyperbolic cosine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the inverse hyperbolic cosine is to be calculated. example: | assert (1.0).acosh() == 0 -Num.asin: +Float64.asin: short: arc sine description: > Computes the arc sine of a number. return: - type: 'Num' + type: 'Float64' description: > The arc sine of `x` in radians. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the arc sine is to be calculated. example: | assert (0.5).asin() == 0.5236 -Num.asinh: +Float64.asinh: short: arc hyperbolic sine description: > Computes the inverse hyperbolic sine of a number. return: - type: 'Num' + type: 'Float64' description: > The inverse hyperbolic sine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the inverse hyperbolic sine is to be calculated. example: | assert (0.0).asinh() == 0 -Num.atan: +Float64.atan: short: arc tangent description: > Computes the arc tangent of a number. return: - type: 'Num' + type: 'Float64' description: > The arc tangent of `x` in radians. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the arc tangent is to be calculated. example: | assert (1.0).atan() == 0.7854 -Num.atan2: +Float64.atan2: short: arc tangent from 2 variables description: > Computes the arc tangent of the quotient of two numbers. return: - type: 'Num' + type: 'Float64' description: > The arc tangent of `x/y` in radians. args: x: - type: 'Num' + type: 'Float64' description: > The numerator. y: - type: 'Num' + type: 'Float64' description: > The denominator. example: | - assert Num.atan2(1, 1) == 0.7854 + assert Float64.atan2(1, 1) == 0.7854 -Num.atanh: +Float64.atanh: short: arc hyperbolic tangent. description: > Computes the inverse hyperbolic tangent of a number. return: - type: 'Num' + type: 'Float64' description: > The inverse hyperbolic tangent of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the inverse hyperbolic tangent is to be calculated. example: | assert (0.5).atanh() == 0.5493 -Num.cbrt: +Float64.cbrt: short: cube root description: > Computes the cube root of a number. return: - type: 'Num' + type: 'Float64' description: > The cube root of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the cube root is to be calculated. example: | assert (27.0).cbrt() == 3 -Num.ceil: +Float64.ceil: short: ceiling function description: > Rounds a number up to the nearest integer. return: - type: 'Num' + type: 'Float64' description: > The smallest integer greater than or equal to `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number to be rounded up. example: | assert (3.2).ceil() == 4 -Num.clamped: +Float64.clamped: short: clamp a number description: > Returns the given number clamped between two values so that it is within that range. return: - type: 'Num' + type: 'Float64' description: > The first argument clamped between the other two arguments. args: x: - type: 'Num' + type: 'Float64' description: > The number to clamp. low: - type: 'Num' + type: 'Float64' description: > The lowest value the result can take. high: - type: 'Num' + type: 'Float64' description: > The highest value the result can take. example: | assert (2.5).clamped(5.5, 10.5) == 5.5 -Num.copysign: +Float64.copysign: short: copy a number's sign description: > Copies the sign of one number to another. return: - type: 'Num' + type: 'Float64' description: > A number with the magnitude of `x` and the sign of `y`. args: x: - type: 'Num' + type: 'Float64' description: > The number whose magnitude will be copied. y: - type: 'Num' + type: 'Float64' description: > The number whose sign will be copied. example: | assert (3.0).copysign(-1) == -3 -Num.cos: +Float64.cos: short: cosine description: > Computes the cosine of a number (angle in radians). return: - type: 'Num' + type: 'Float64' description: > The cosine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The angle in radians. example: | assert (0.0).cos() == 1 -Num.cosh: +Float64.cosh: short: hyperbolic cosine description: > Computes the hyperbolic cosine of a number. return: - type: 'Num' + type: 'Float64' description: > The hyperbolic cosine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the hyperbolic cosine is to be calculated. example: | assert (0.0).cosh() == 1 -Num.erf: +Float64.erf: short: error function description: > Computes the error function of a number. return: - type: 'Num' + type: 'Float64' description: > The error function of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the error function is to be calculated. example: | assert (0.0).erf() == 0 -Num.erfc: +Float64.erfc: short: complimentary error function description: > Computes the complementary error function of a number. return: - type: 'Num' + type: 'Float64' description: > The complementary error function of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the complementary error function is to be calculated. example: | assert (0.0).erfc() == 1 -Num.exp: +Float64.exp: short: base-e exponentiation description: > Computes the exponential function $e^x$ for a number. return: - type: 'Num' + type: 'Float64' description: > The value of $e^x$. args: x: - type: 'Num' + type: 'Float64' description: > The exponent. example: | assert (1.0).exp() == 2.7183 -Num.exp2: +Float64.exp2: short: base-2 exponentiation description: > Computes $2^x$ for a number. return: - type: 'Num' + type: 'Float64' description: > The value of $2^x$. args: x: - type: 'Num' + type: 'Float64' description: > The exponent. example: | assert (3.0).exp2() == 8 -Num.expm1: +Float64.expm1: short: base-e exponential minus 1 description: > Computes $e^x - 1$ for a number. return: - type: 'Num' + type: 'Float64' description: > The value of $e^x - 1$. args: x: - type: 'Num' + type: 'Float64' description: > The exponent. example: | assert (1.0).expm1() == 1.7183 -Num.fdim: +Float64.fdim: short: positive difference description: > Computes the positive difference between two numbers. return: - type: 'Num' + type: 'Float64' description: > The positive difference $\max(0, x - y)$. args: x: - type: 'Num' + type: 'Float64' description: > The first number. y: - type: 'Num' + type: 'Float64' description: > The second number. example: | @@ -341,43 +341,43 @@ Num.fdim: assert (5.0).fdim(3) == 2 -Num.floor: +Float64.floor: short: floor function description: > Rounds a number down to the nearest integer. return: - type: 'Num' + type: 'Float64' description: > The largest integer less than or equal to `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number to be rounded down. example: | assert (3.7).floor() == 3 -Num.hypot: +Float64.hypot: short: Euclidean distance function description: > Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers. return: - type: 'Num' + type: 'Float64' description: > The Euclidean norm of `x` and `y`. args: x: - type: 'Num' + type: 'Float64' description: > The first number. y: - type: 'Num' + type: 'Float64' description: > The second number. example: | - assert Num.hypot(3, 4) == 5 + assert Float64.hypot(3, 4) == 5 -Num.isfinite: +Float64.isfinite: short: check for finite number description: > Checks if a number is finite. @@ -387,14 +387,14 @@ Num.isfinite: `yes` if `n` is finite, `no` otherwise. args: n: - type: 'Num' + type: 'Float64' description: > The number to be checked. example: | assert (1.0).isfinite() == yes - assert Num.INF.isfinite() == no + assert Float64.INF.isfinite() == no -Num.is_between: +Float64.is_between: short: check if a number is in a range description: > Determines if a number is between two numbers (inclusive). @@ -404,15 +404,15 @@ Num.is_between: `yes` if `low <= x and x <= high`, otherwise `no` args: x: - type: 'Num' + type: 'Float64' description: > The integer to be checked. low: - type: 'Num' + type: 'Float64' description: > The lower bound to check (inclusive). high: - type: 'Num' + type: 'Float64' description: > The upper bound to check (inclusive). example: | @@ -420,7 +420,7 @@ Num.is_between: assert (7.5).is_between(100, 200) == no assert (7.5).is_between(1, 7.5) == yes -Num.isinf: +Float64.isinf: short: check for infinite number description: > Checks if a number is infinite. @@ -430,151 +430,151 @@ Num.isinf: `yes` if `n` is infinite, `no` otherwise. args: n: - type: 'Num' + type: 'Float64' description: > The number to be checked. example: | - assert Num.INF.isinf() == yes + assert Float64.INF.isinf() == yes assert (1.0).isinf() == no -Num.j0: +Float64.j0: short: Bessel function description: > Computes the Bessel function of the first kind of order 0. return: - type: 'Num' + type: 'Float64' description: > The Bessel function of the first kind of order 0 of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the Bessel function is to be calculated. example: | assert (0.0).j0() == 1 -Num.j1: +Float64.j1: short: Bessel function description: > Computes the Bessel function of the first kind of order 1. return: - type: 'Num' + type: 'Float64' description: > The Bessel function of the first kind of order 1 of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the Bessel function is to be calculated. example: | assert (0.0).j1() == 0 -Num.log: +Float64.log: short: natural logarithm description: > Computes the natural logarithm (base $e$) of a number. return: - type: 'Num' + type: 'Float64' description: > The natural logarithm of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the natural logarithm is to be calculated. example: | - assert Num.E.log() == 1 + assert Float64.E.log() == 1 -Num.log10: +Float64.log10: short: logarithm base-10 description: > Computes the base-10 logarithm of a number. return: - type: 'Num' + type: 'Float64' description: > The base-10 logarithm of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the base-10 logarithm is to be calculated. example: | assert (100.0).log10() == 2 -Num.log1p: +Float64.log1p: short: logarithm of 1 plus x description: > Computes $\log(1 + x)$ for a number. return: - type: 'Num' + type: 'Float64' description: > The value of $\log(1 + x)$. args: x: - type: 'Num' + type: 'Float64' description: > The number for which $\log(1 + x)$ is to be calculated. example: | assert (1.0).log1p() == 0.6931 -Num.log2: +Float64.log2: short: logarithm base-2 description: > Computes the base-2 logarithm of a number. return: - type: 'Num' + type: 'Float64' description: > The base-2 logarithm of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the base-2 logarithm is to be calculated. example: | assert (8.0).log2() == 3 -Num.logb: +Float64.logb: short: exponent of a floating point value description: > Computes the binary exponent (base-2 logarithm) of a number. return: - type: 'Num' + type: 'Float64' description: > The binary exponent of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the binary exponent is to be calculated. example: | assert (8.0).logb() == 3 -Num.mix: +Float64.mix: short: mix two numbers by an amount description: > Interpolates between two numbers based on a given amount. return: - type: 'Num' + type: 'Float64' description: > The interpolated number between `x` and `y` based on `amount`. args: amount: - type: 'Num' + type: 'Float64' description: > The interpolation factor (between `0` and `1`). x: - type: 'Num' + type: 'Float64' description: > The starting number. y: - type: 'Num' + type: 'Float64' description: > The ending number. example: | assert (0.5).mix(10, 20) == 15 assert (0.25).mix(10, 20) == 12.5 -Num.near: +Float64.near: short: check if two numbers are near each other description: > Checks if two numbers are approximately equal within specified tolerances. If @@ -586,20 +586,20 @@ Num.near: `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise. args: x: - type: 'Num' + type: 'Float64' description: > The first number. y: - type: 'Num' + type: 'Float64' description: > The second number. ratio: - type: 'Num' + type: 'Float64' default: '1e-9' description: > The relative tolerance. Default is `1e-9`. min_epsilon: - type: 'Num' + type: 'Float64' default: '1e-9' description: > The absolute tolerance. Default is `1e-9`. @@ -608,32 +608,32 @@ Num.near: assert (100.0).near(110, ratio=0.1) == yes assert (5.0).near(5.1, min_epsilon=0.1) == yes -Num.nextafter: +Float64.nextafter: short: next floating point number description: > Computes the next representable value after a given number towards a specified direction. return: - type: 'Num' + type: 'Float64' description: > The next representable value after `x` in the direction of `y`. args: x: - type: 'Num' + type: 'Float64' description: > The starting number. y: - type: 'Num' + type: 'Float64' description: > The direction towards which to find the next representable value. example: | assert (1.0).nextafter(1.1) == 1.0000000000000002 -Num.parse: +Float64.parse: short: convert text to number description: > Converts a text representation of a number into a floating-point number. return: - type: 'Num?' + type: 'Float64?' description: > The number represented by the text or `none` if the entire text can't be parsed as a number. @@ -649,14 +649,14 @@ Num.parse: If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. example: | - assert Num.parse("3.14") == 3.14 - assert Num.parse("1e3") == 1000 - assert Num.parse("1.5junk") == none + assert Float64.parse("3.14") == 3.14 + assert Float64.parse("1e3") == 1000 + assert Float64.parse("1.5junk") == none remainder : Text - assert Num.parse("1.5junk", &remainder) == 1.5 + assert Float64.parse("1.5junk", &remainder) == 1.5 assert remainder == "junk" -Num.percent: +Float64.percent: short: format as a percentage description: > Convert a number into a percentage text with a percent sign. @@ -666,11 +666,11 @@ Num.percent: A text representation of the number as a percentage with a percent sign. args: n: - type: 'Num' + type: 'Float64' description: > The number to be converted to a percent. precision: - type: 'Num' + type: 'Float64' default: '0.01' description: > Round the percentage to this precision level. @@ -680,21 +680,21 @@ Num.percent: assert (1./3.).percent(2, precision=0.0001) == "33.3333%" assert (1./3.).percent(2, precision=10.) == "30%" -Num.with_precision: +Float64.with_precision: short: round to a given precision description: > Round a number to the given precision level (specified as `10`, `.1`, `.001` etc). return: - type: 'Num' + type: 'Float64' description: > The number, rounded to the given precision level. args: n: - type: 'Num' + type: 'Float64' description: > The number to be rounded to a given precision. precision: - type: 'Num' + type: 'Float64' description: > The precision to which the number should be rounded. example: | @@ -702,269 +702,269 @@ Num.with_precision: assert (123456.).with_precision(100) == 123500 assert (1234567.).with_precision(5) == 1234565 -Num.rint: +Float64.rint: short: round to nearest integer description: > Rounds a number to the nearest integer, with ties rounded to the nearest even integer. return: - type: 'Num' + type: 'Float64' description: > The nearest integer value of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number to be rounded. example: | assert (3.5).rint() == 4 assert (2.5).rint() == 2 -Num.round: +Float64.round: short: round to nearest integer description: > Rounds a number to the nearest whole number integer. return: - type: 'Num' + type: 'Float64' description: > The nearest integer value of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number to be rounded. example: | assert (2.3).round() == 2 assert (2.7).round() == 3 -Num.significand: +Float64.significand: short: get mantissa description: > Extracts the significand (or mantissa) of a number. return: - type: 'Num' + type: 'Float64' description: > The significand of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number from which to extract the significand. example: | assert (1234.567).significand() == 0.1234567 -Num.sin: +Float64.sin: short: sine description: > Computes the sine of a number (angle in radians). return: - type: 'Num' + type: 'Float64' description: > The sine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The angle in radians. example: | assert (0.0).sin() == 0 -Num.sinh: +Float64.sinh: short: hyperbolic sine description: > Computes the hyperbolic sine of a number. return: - type: 'Num' + type: 'Float64' description: > The hyperbolic sine of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the hyperbolic sine is to be calculated. example: | assert (0.0).sinh() == 0 -Num.sqrt: +Float64.sqrt: short: square root description: > Computes the square root of a number. return: - type: 'Num' + type: 'Float64' description: > The square root of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the square root is to be calculated. example: | assert (16.0).sqrt() == 4 -Num.tan: +Float64.tan: short: tangent description: > Computes the tangent of a number (angle in radians). return: - type: 'Num' + type: 'Float64' description: > The tangent of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The angle in radians. example: | assert (0.0).tan() == 0 -Num.tanh: +Float64.tanh: short: hyperbolic tangent description: > Computes the hyperbolic tangent of a number. return: - type: 'Num' + type: 'Float64' description: > The hyperbolic tangent of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the hyperbolic tangent is to be calculated. example: | assert (0.0).tanh() == 0 -Num.tgamma: +Float64.tgamma: short: "true gamma function" description: > Computes the gamma function of a number. return: - type: 'Num' + type: 'Float64' description: > The gamma function of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the gamma function is to be calculated. example: | assert (1.0).tgamma() == 1 -Num.trunc: +Float64.trunc: short: truncate a number description: > Truncates a number to the nearest integer towards zero. return: - type: 'Num' + type: 'Float64' description: > The integer part of `x` towards zero. args: x: - type: 'Num' + type: 'Float64' description: > The number to be truncated. example: | assert (3.7).trunc() == 3 assert (-3.7).trunc() == -3 -Num.y0: +Float64.y0: short: Bessel function description: > Computes the Bessel function of the second kind of order 0. return: - type: 'Num' + type: 'Float64' description: > The Bessel function of the second kind of order 0 of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the Bessel function is to be calculated. example: | assert (1.0).y0() == -0.7652 -Num.y1: +Float64.y1: short: Bessel function description: > Computes the Bessel function of the second kind of order 1. return: - type: 'Num' + type: 'Float64' description: > The Bessel function of the second kind of order 1 of `x`. args: x: - type: 'Num' + type: 'Float64' description: > The number for which the Bessel function is to be calculated. example: | assert (1.0).y1() == 0.4401 -Num.1_PI: +Float64.1_PI: short: 1/pi - type: Num + type: Float64 description: > The constant $\frac{1}{\pi}$. -Num.2_PI: +Float64.2_PI: short: 2*pi - type: Num + type: Float64 description: > The constant $2 \times \pi$. -Num.2_SQRTPI: +Float64.2_SQRTPI: short: 2*sqrt(pi) - type: Num + type: Float64 description: > The constant $2 \times \sqrt{\pi}$. -Num.E: +Float64.E: short: Euler's constant - type: Num + type: Float64 description: > The base of the natural logarithm ($e$). -Num.INF: +Float64.INF: short: infinity - type: Num + type: Float64 description: > Positive infinity. -Num.LN10: +Float64.LN10: short: log(10) - type: Num + type: Float64 description: > The natural logarithm of 10. -Num.LN2: +Float64.LN2: short: log(2) - type: Num + type: Float64 description: > The natural logarithm of 2. -Num.LOG2E: +Float64.LOG2E: short: log_2(e) - type: Num + type: Float64 description: > The base 2 logarithm of $e$ -Num.PI: +Float64.PI: short: pi - type: Num + type: Float64 description: > Pi ($\pi$). -Num.PI_2: +Float64.PI_2: short: pi/2 - type: Num + type: Float64 description: > $\frac{\pi}{2}$ -Num.PI_4: +Float64.PI_4: short: pi/4 - type: Num + type: Float64 description: > $\frac{\pi}{4}$ -Num.SQRT1_2: +Float64.SQRT1_2: short: sqrt(1/2) - type: Num + type: Float64 description: > $\sqrt{\frac{1}{2}}$ -Num.SQRT2: +Float64.SQRT2: short: sqrt(2) - type: Num + type: Float64 description: > $\sqrt{2}$ -Num.TAU: +Float64.TAU: short: 2*pi - type: Num + type: Float64 description: > Tau ($2 \times \pi$) diff --git a/api/lists.md b/api/lists.md index 1c741989..4d184830 100644 --- a/api/lists.md +++ b/api/lists.md @@ -407,7 +407,7 @@ assert [10, 20, 30].reversed() == [30, 20, 10] ## List.sample ```tomo -List.sample : func(list: [T], count: Int, weights: [Num]? = none, random: func(->Num)? = none -> [T]) +List.sample : func(list: [T], count: Int, weights: [Float64]? = none, random: func(->Float64)? = none -> [T]) ``` Selects a sample of elements from the list, optionally with weighted probabilities. @@ -418,8 +418,8 @@ Argument | Type | Description | Default ---------|------|-------------|--------- list | `[T]` | The list to sample from. | - count | `Int` | The number of elements to sample. | - -weights | `[Num]?` | The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. | `none` -random | `func(->Num)?` | If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) | `none` +weights | `[Float64]?` | The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. | `none` +random | `func(->Float64)?` | If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) | `none` **Return:** A list of sampled elements from the list. diff --git a/api/lists.yaml b/api/lists.yaml index 5a2bc2a1..ef526a9d 100644 --- a/api/lists.yaml +++ b/api/lists.yaml @@ -442,7 +442,7 @@ List.sample: description: > The number of elements to sample. weights: - type: '[Num]?' + type: '[Float64]?' default: 'none' description: > The probability weights for each element in the list. These @@ -450,7 +450,7 @@ List.sample: weights. If no weights are given, elements will be sampled with uniform probability. random: - type: 'func(->Num)?' + type: 'func(->Float64)?' default: 'none' description: > If provided, this function will be used to get random values for diff --git a/docs/functions.md b/docs/functions.md index 72279c11..b325ee9a 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -47,7 +47,7 @@ and are bound to arguments first, followed by binding positional arguments to any unbound arguments, in order: ```tomo -func foo(x:Int, y:Text, z:Num) +func foo(x:Int, y:Text, z:Float64) return "x=$x y=$y z=$z" >> foo(x=1, y="hi", z=2.5) diff --git a/docs/nums.md b/docs/nums.md index 1bd9b52d..911144ef 100644 --- a/docs/nums.md +++ b/docs/nums.md @@ -1,7 +1,7 @@ # Nums -Tomo has two floating point number types: `Num` (64-bit, AKA `double`) and -`Num32` (32-bit, AKA `float`). Num literals can have a decimal point (e.g. +Tomo has two floating point number types: `Float64` (64-bit, AKA `double`) and +`Float32` (32-bit, AKA `float`). Float64 literals can have a decimal point (e.g. `5.`), a scientific notation suffix (e.g. `1e8`) or a percent sign. Numbers that end in a percent sign are divided by 100 at compile time (i.e. `5% == 0.05`). Numbers can also use the `deg` suffix to represent degrees, which @@ -10,7 +10,7 @@ are converted to radians at compile time (i.e. `180deg == Nums.PI`). Nums support the standard math operations (`x+y`, `x-y`, `x*y`, `x/y`) as well as powers/exponentiation (`x^y`) and modulus (`x mod y` and `x mod1 y`). -32-bit numbers can be constructed using the type name: `Num32(123.456)`. +32-bit numbers can be constructed using the type name: `Float32(123.456)`. ## NaN @@ -26,11 +26,11 @@ differentiate between possibly-NaN values and definitely-not-NaN values. Tomo has a separate concept for expressing the lack of a defined value: optional types. Consequently, Tomo has merged these two concepts, so `NaN` is -called `none` and has the type `Num?` or `Num32?`. In this way, it's no +called `none` and has the type `Float64?` or `Float32?`. In this way, it's no different from optional integers or optional lists. This means that if a -variable has type `Num`, it is guaranteed to not hold a NaN value. This also +variable has type `Float64`, it is guaranteed to not hold a NaN value. This also means that operations which may produce NaN values have a result type of -`Num?`. For example, division can take two non-NaN values and return a result +`Float64?`. For example, division can take two non-NaN values and return a result that is NaN (zero divided by zero). Similarly, multiplication can produce NaN values (zero times infinity), and many math functions like `sqrt()` can return NaN for some inputs. @@ -42,36 +42,36 @@ required to be non-none. Here are a few examples: ```tomo >> x := 0.0 -= 0 : Num += 0 : Float64 y := 1.0 # Division might produce none: >> x / y -= 0 : Num? += 0 : Float64? >> x / x -= none : Num? += none : Float64? # Optional types and none values propagate: >> x/y + 1 + 2 -= 3 : Num? += 3 : Float64? >> x/x + 1 + 2 -= none : Num? += none : Float64? # Optional Nums can be handled explicitly using `or` and `!`: >> x/x or -123 -= -123 : Num += -123 : Float64 # This would raise a runtime error if `x` and `y` were zero: >> (x/y)! -= 0 : Num += 0 : Float64 # Assigning to a non-optional variable will do an implicit check for none and # raise a runtime error if the value is none, essentially the same as an # implicit `!`: x = x/y -func doop(x:Num -> Num) +func doop(x:Float64 -> Float64) # If a function's return type is non-optional and an optional value is # used in a return statement, an implicit none check will be inserted and # will error if the value is none: @@ -80,7 +80,7 @@ func doop(x:Num -> Num) # Function arguments are also implicitly checked for none if the given value # is optional and the function needs a non-optional value: >> doop(x/y) -= 0 : Num += 0 : Float64 ``` Hopefully the end result of this system is one where users can take advantage diff --git a/docs/optionals.md b/docs/optionals.md index 131daf19..6f2e3d5e 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -120,7 +120,7 @@ negative length for lists. However, for fixed-size integers (`Int64`, `Int32`, `Int16`, and `Int8`), bytes, and structs, an additional byte is required for out-of-band information about whether the value is none or not. -Floating point numbers (`Num` and `Num32`) use `NaN` to represent none, so +Floating point numbers (`Float64` and `Float32`) use `NaN` to represent none, so optional nums should be careful to avoid using `NaN` as a non-none value. This option was chosen to minimize the memory overhead of optional nums and because `NaN` literally means "not a number". diff --git a/examples/learnxiny.tm b/examples/learnxiny.tm index a03db6c9..746e11a1 100644 --- a/examples/learnxiny.tm +++ b/examples/learnxiny.tm @@ -200,7 +200,7 @@ func demo_keyword_args() func takes_many_types( boolean:Bool, integer:Int, - floating_point_number:Num, + floating_point_number:Float64, text_aka_string:Text, list_of_ints:[Int], table_of_text_to_bools:{Text=Bool}, @@ -258,18 +258,18 @@ func demo_structs() # indicates which type it is, and any data you want to associate with it. enum Shape( Point, - Circle(radius:Num), - Rectangle(width:Num, height:Num), + Circle(radius:Float64), + Rectangle(width:Float64, height:Float64), ) # Just like with structs, you define methods and constants inside a level # of indentation: - func get_area(self:Shape->Num) + func get_area(self:Shape->Float64) # In order to work with an enum, it's most often handy to use a 'when' # statement to get the internal values: when self is Point return 0 is Circle(r) - return Num.PI * r^2 + return Float64.PI * r^2 is Rectangle(w, h) return w * h # 'when' statements are checked for exhaustiveness, so the compiler diff --git a/man/man3/tomo-Bool.parse.3 b/man/man3/tomo-Bool.parse.3 index 8fe9f2dd..516d499f 100644 --- a/man/man3/tomo-Bool.parse.3 +++ b/man/man3/tomo-Bool.parse.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Bool.parse 3 2025-09-21 "Tomo man-pages" +.TH Bool.parse 3 2025-11-09 "Tomo man-pages" .SH NAME Bool.parse \- parse into boolean .SH LIBRARY diff --git a/man/man3/tomo-Byte.get_bit.3 b/man/man3/tomo-Byte.get_bit.3 index b815e9d4..0007b5ad 100644 --- a/man/man3/tomo-Byte.get_bit.3 +++ b/man/man3/tomo-Byte.get_bit.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.get_bit 3 2025-09-21 "Tomo man-pages" +.TH Byte.get_bit 3 2025-11-09 "Tomo man-pages" .SH NAME Byte.get_bit \- check whether a bit is set .SH LIBRARY diff --git a/man/man3/tomo-Byte.hex.3 b/man/man3/tomo-Byte.hex.3 index c09ba5c1..ab35f5bb 100644 --- a/man/man3/tomo-Byte.hex.3 +++ b/man/man3/tomo-Byte.hex.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.hex 3 2025-09-21 "Tomo man-pages" +.TH Byte.hex 3 2025-11-09 "Tomo man-pages" .SH NAME Byte.hex \- convert to hexidecimal .SH LIBRARY diff --git a/man/man3/tomo-Byte.is_between.3 b/man/man3/tomo-Byte.is_between.3 index 042747ac..3fae008f 100644 --- a/man/man3/tomo-Byte.is_between.3 +++ b/man/man3/tomo-Byte.is_between.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.is_between 3 2025-09-21 "Tomo man-pages" +.TH Byte.is_between 3 2025-11-09 "Tomo man-pages" .SH NAME Byte.is_between \- test if inside a range .SH LIBRARY diff --git a/man/man3/tomo-Byte.parse.3 b/man/man3/tomo-Byte.parse.3 index 57dbaee2..cb7fb2e0 100644 --- a/man/man3/tomo-Byte.parse.3 +++ b/man/man3/tomo-Byte.parse.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.parse 3 2025-09-21 "Tomo man-pages" +.TH Byte.parse 3 2025-11-09 "Tomo man-pages" .SH NAME Byte.parse \- convert text to a byte .SH LIBRARY diff --git a/man/man3/tomo-Byte.to.3 b/man/man3/tomo-Byte.to.3 index 15774ba7..d98e25dd 100644 --- a/man/man3/tomo-Byte.to.3 +++ b/man/man3/tomo-Byte.to.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Byte.to 3 2025-10-11 "Tomo man-pages" +.TH Byte.to 3 2025-11-09 "Tomo man-pages" .SH NAME Byte.to \- iterate over a range of bytes .SH LIBRARY diff --git a/man/man3/tomo-CString.as_text.3 b/man/man3/tomo-CString.as_text.3 index 463a6f98..0332c166 100644 --- a/man/man3/tomo-CString.as_text.3 +++ b/man/man3/tomo-CString.as_text.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH CString.as_text 3 2025-10-18 "Tomo man-pages" +.TH CString.as_text 3 2025-11-09 "Tomo man-pages" .SH NAME CString.as_text \- convert a C string to Text .SH LIBRARY diff --git a/man/man3/tomo-CString.join.3 b/man/man3/tomo-CString.join.3 index 27e74495..70eb3d72 100644 --- a/man/man3/tomo-CString.join.3 +++ b/man/man3/tomo-CString.join.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH CString.join 3 2025-10-18 "Tomo man-pages" +.TH CString.join 3 2025-11-09 "Tomo man-pages" .SH NAME CString.join \- join a list of C strings .SH LIBRARY diff --git a/man/man3/tomo-Num.1_PI.3 b/man/man3/tomo-Float64.1_PI.3 index ad91d33b..c5b57ecf 100644 --- a/man/man3/tomo-Num.1_PI.3 +++ b/man/man3/tomo-Float64.1_PI.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.1_PI 3 2025-04-30 "Tomo man-pages" +.TH Float64.1_PI 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.1_PI \- 1/pi +Float64.1_PI \- 1/pi .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.1_PI\ :\ Num +.BI Float64.1_PI\ :\ Float64 .fi .SH DESCRIPTION The constant $\frac{1}{\pi}$. diff --git a/man/man3/tomo-Num.2_PI.3 b/man/man3/tomo-Float64.2_PI.3 index 3e7db63b..7bc0e51d 100644 --- a/man/man3/tomo-Num.2_PI.3 +++ b/man/man3/tomo-Float64.2_PI.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.2_PI 3 2025-04-30 "Tomo man-pages" +.TH Float64.2_PI 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.2_PI \- 2*pi +Float64.2_PI \- 2*pi .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.2_PI\ :\ Num +.BI Float64.2_PI\ :\ Float64 .fi .SH DESCRIPTION The constant $2 \times \pi$. diff --git a/man/man3/tomo-Num.2_SQRTPI.3 b/man/man3/tomo-Float64.2_SQRTPI.3 index 15a19bc2..e54e565f 100644 --- a/man/man3/tomo-Num.2_SQRTPI.3 +++ b/man/man3/tomo-Float64.2_SQRTPI.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.2_SQRTPI 3 2025-04-30 "Tomo man-pages" +.TH Float64.2_SQRTPI 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.2_SQRTPI \- 2*sqrt(pi) +Float64.2_SQRTPI \- 2*sqrt(pi) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.2_SQRTPI\ :\ Num +.BI Float64.2_SQRTPI\ :\ Float64 .fi .SH DESCRIPTION The constant $2 \times \sqrt{\pi}$. diff --git a/man/man3/tomo-Num.E.3 b/man/man3/tomo-Float64.E.3 index 227c3a78..14a6d240 100644 --- a/man/man3/tomo-Num.E.3 +++ b/man/man3/tomo-Float64.E.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.E 3 2025-04-30 "Tomo man-pages" +.TH Float64.E 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.E \- Euler's constant +Float64.E \- Euler's constant .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.E\ :\ Num +.BI Float64.E\ :\ Float64 .fi .SH DESCRIPTION The base of the natural logarithm ($e$). diff --git a/man/man3/tomo-Num.INF.3 b/man/man3/tomo-Float64.INF.3 index 6b7560e8..93db39ae 100644 --- a/man/man3/tomo-Num.INF.3 +++ b/man/man3/tomo-Float64.INF.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.INF 3 2025-04-30 "Tomo man-pages" +.TH Float64.INF 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.INF \- infinity +Float64.INF \- infinity .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.INF\ :\ Num +.BI Float64.INF\ :\ Float64 .fi .SH DESCRIPTION Positive infinity. diff --git a/man/man3/tomo-Num.LN10.3 b/man/man3/tomo-Float64.LN10.3 index 00383a60..08716f05 100644 --- a/man/man3/tomo-Num.LN10.3 +++ b/man/man3/tomo-Float64.LN10.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.LN10 3 2025-04-30 "Tomo man-pages" +.TH Float64.LN10 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.LN10 \- log(10) +Float64.LN10 \- log(10) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.LN10\ :\ Num +.BI Float64.LN10\ :\ Float64 .fi .SH DESCRIPTION The natural logarithm of 10. diff --git a/man/man3/tomo-Num.LN2.3 b/man/man3/tomo-Float64.LN2.3 index 6e3d3df6..48efd9ec 100644 --- a/man/man3/tomo-Num.LN2.3 +++ b/man/man3/tomo-Float64.LN2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.LN2 3 2025-04-30 "Tomo man-pages" +.TH Float64.LN2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.LN2 \- log(2) +Float64.LN2 \- log(2) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.LN2\ :\ Num +.BI Float64.LN2\ :\ Float64 .fi .SH DESCRIPTION The natural logarithm of 2. diff --git a/man/man3/tomo-Num.LOG2E.3 b/man/man3/tomo-Float64.LOG2E.3 index b729be0c..26745247 100644 --- a/man/man3/tomo-Num.LOG2E.3 +++ b/man/man3/tomo-Float64.LOG2E.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.LOG2E 3 2025-04-30 "Tomo man-pages" +.TH Float64.LOG2E 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.LOG2E \- log_2(e) +Float64.LOG2E \- log_2(e) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.LOG2E\ :\ Num +.BI Float64.LOG2E\ :\ Float64 .fi .SH DESCRIPTION The base 2 logarithm of $e$ diff --git a/man/man3/tomo-Num.PI.3 b/man/man3/tomo-Float64.PI.3 index 61d4a0f8..98fe1468 100644 --- a/man/man3/tomo-Num.PI.3 +++ b/man/man3/tomo-Float64.PI.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.PI 3 2025-04-30 "Tomo man-pages" +.TH Float64.PI 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.PI \- pi +Float64.PI \- pi .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.PI\ :\ Num +.BI Float64.PI\ :\ Float64 .fi .SH DESCRIPTION Pi ($\pi$). diff --git a/man/man3/tomo-Num.PI_2.3 b/man/man3/tomo-Float64.PI_2.3 index 93e7f4ca..3dafbcb4 100644 --- a/man/man3/tomo-Num.PI_2.3 +++ b/man/man3/tomo-Float64.PI_2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.PI_2 3 2025-04-30 "Tomo man-pages" +.TH Float64.PI_2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.PI_2 \- pi/2 +Float64.PI_2 \- pi/2 .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.PI_2\ :\ Num +.BI Float64.PI_2\ :\ Float64 .fi .SH DESCRIPTION $\frac{\pi}{2}$ diff --git a/man/man3/tomo-Num.PI_4.3 b/man/man3/tomo-Float64.PI_4.3 index c6796704..bcf3ab78 100644 --- a/man/man3/tomo-Num.PI_4.3 +++ b/man/man3/tomo-Float64.PI_4.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.PI_4 3 2025-04-30 "Tomo man-pages" +.TH Float64.PI_4 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.PI_4 \- pi/4 +Float64.PI_4 \- pi/4 .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.PI_4\ :\ Num +.BI Float64.PI_4\ :\ Float64 .fi .SH DESCRIPTION $\frac{\pi}{4}$ diff --git a/man/man3/tomo-Num.SQRT1_2.3 b/man/man3/tomo-Float64.SQRT1_2.3 index 0feac353..e40c68b4 100644 --- a/man/man3/tomo-Num.SQRT1_2.3 +++ b/man/man3/tomo-Float64.SQRT1_2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.SQRT1_2 3 2025-04-30 "Tomo man-pages" +.TH Float64.SQRT1_2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.SQRT1_2 \- sqrt(1/2) +Float64.SQRT1_2 \- sqrt(1/2) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.SQRT1_2\ :\ Num +.BI Float64.SQRT1_2\ :\ Float64 .fi .SH DESCRIPTION $\sqrt{\frac{1}{2}}$ diff --git a/man/man3/tomo-Num.SQRT2.3 b/man/man3/tomo-Float64.SQRT2.3 index 75bd86bf..775a1a34 100644 --- a/man/man3/tomo-Num.SQRT2.3 +++ b/man/man3/tomo-Float64.SQRT2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.SQRT2 3 2025-04-30 "Tomo man-pages" +.TH Float64.SQRT2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.SQRT2 \- sqrt(2) +Float64.SQRT2 \- sqrt(2) .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.SQRT2\ :\ Num +.BI Float64.SQRT2\ :\ Float64 .fi .SH DESCRIPTION $\sqrt{2}$ diff --git a/man/man3/tomo-Num.TAU.3 b/man/man3/tomo-Float64.TAU.3 index 2abc33d2..bf351d7f 100644 --- a/man/man3/tomo-Num.TAU.3 +++ b/man/man3/tomo-Float64.TAU.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.TAU 3 2025-04-30 "Tomo man-pages" +.TH Float64.TAU 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.TAU \- 2*pi +Float64.TAU \- 2*pi .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.TAU\ :\ Num +.BI Float64.TAU\ :\ Float64 .fi .SH DESCRIPTION Tau ($2 \times \pi$) diff --git a/man/man3/tomo-Num.abs.3 b/man/man3/tomo-Float64.abs.3 index 425d43cb..754fa488 100644 --- a/man/man3/tomo-Num.abs.3 +++ b/man/man3/tomo-Float64.abs.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.abs 3 2025-09-21 "Tomo man-pages" +.TH Float64.abs 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.abs \- absolute value +Float64.abs \- absolute value .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.abs\ :\ func(n:\ Num\ ->\ Num) +.BI Float64.abs\ :\ func(n:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Calculates the absolute value of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -n Num The number whose absolute value is to be computed. - +n Float64 The number whose absolute value is to be computed. - .TE .SH RETURN The absolute value of `n`. diff --git a/man/man3/tomo-Num.acos.3 b/man/man3/tomo-Float64.acos.3 index 819c43d3..d8bd0434 100644 --- a/man/man3/tomo-Num.acos.3 +++ b/man/man3/tomo-Float64.acos.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.acos 3 2025-09-21 "Tomo man-pages" +.TH Float64.acos 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.acos \- arc cosine +Float64.acos \- arc cosine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.acos\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.acos\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the arc cosine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the arc cosine is to be calculated. - +x Float64 The number for which the arc cosine is to be calculated. - .TE .SH RETURN The arc cosine of `x` in radians. diff --git a/man/man3/tomo-Num.acosh.3 b/man/man3/tomo-Float64.acosh.3 index 0899fff8..37bb19d2 100644 --- a/man/man3/tomo-Num.acosh.3 +++ b/man/man3/tomo-Float64.acosh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.acosh 3 2025-09-21 "Tomo man-pages" +.TH Float64.acosh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.acosh \- arc hyperbolic cosine +Float64.acosh \- arc hyperbolic cosine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.acosh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.acosh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the inverse hyperbolic cosine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the inverse hyperbolic cosine is to be calculated. - +x Float64 The number for which the inverse hyperbolic cosine is to be calculated. - .TE .SH RETURN The inverse hyperbolic cosine of `x`. diff --git a/man/man3/tomo-Num.asin.3 b/man/man3/tomo-Float64.asin.3 index 529a974c..f56fec93 100644 --- a/man/man3/tomo-Num.asin.3 +++ b/man/man3/tomo-Float64.asin.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.asin 3 2025-09-21 "Tomo man-pages" +.TH Float64.asin 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.asin \- arc sine +Float64.asin \- arc sine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.asin\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.asin\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the arc sine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the arc sine is to be calculated. - +x Float64 The number for which the arc sine is to be calculated. - .TE .SH RETURN The arc sine of `x` in radians. diff --git a/man/man3/tomo-Num.asinh.3 b/man/man3/tomo-Float64.asinh.3 index da88b719..9ba2329b 100644 --- a/man/man3/tomo-Num.asinh.3 +++ b/man/man3/tomo-Float64.asinh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.asinh 3 2025-09-21 "Tomo man-pages" +.TH Float64.asinh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.asinh \- arc hyperbolic sine +Float64.asinh \- arc hyperbolic sine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.asinh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.asinh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the inverse hyperbolic sine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the inverse hyperbolic sine is to be calculated. - +x Float64 The number for which the inverse hyperbolic sine is to be calculated. - .TE .SH RETURN The inverse hyperbolic sine of `x`. diff --git a/man/man3/tomo-Num.atan.3 b/man/man3/tomo-Float64.atan.3 index 808338d4..adceaddf 100644 --- a/man/man3/tomo-Num.atan.3 +++ b/man/man3/tomo-Float64.atan.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.atan 3 2025-09-21 "Tomo man-pages" +.TH Float64.atan 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.atan \- arc tangent +Float64.atan \- arc tangent .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.atan\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.atan\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the arc tangent of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the arc tangent is to be calculated. - +x Float64 The number for which the arc tangent is to be calculated. - .TE .SH RETURN The arc tangent of `x` in radians. diff --git a/man/man3/tomo-Num.atan2.3 b/man/man3/tomo-Float64.atan2.3 index ee2400aa..b9bfbeb8 100644 --- a/man/man3/tomo-Num.atan2.3 +++ b/man/man3/tomo-Float64.atan2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.atan2 3 2025-09-21 "Tomo man-pages" +.TH Float64.atan2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.atan2 \- arc tangent from 2 variables +Float64.atan2 \- arc tangent from 2 variables .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.atan2\ :\ func(x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.atan2\ :\ func(x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the arc tangent of the quotient of two numbers. @@ -22,13 +22,13 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The numerator. - -y Num The denominator. - +x Float64 The numerator. - +y Float64 The denominator. - .TE .SH RETURN The arc tangent of `x/y` in radians. .SH EXAMPLES .EX -assert Num.atan2(1, 1) == 0.7854 +assert Float64.atan2(1, 1) == 0.7854 .EE diff --git a/man/man3/tomo-Num.atanh.3 b/man/man3/tomo-Float64.atanh.3 index c7c30692..f67dc23f 100644 --- a/man/man3/tomo-Num.atanh.3 +++ b/man/man3/tomo-Float64.atanh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.atanh 3 2025-09-21 "Tomo man-pages" +.TH Float64.atanh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.atanh \- arc hyperbolic tangent. +Float64.atanh \- arc hyperbolic tangent. .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.atanh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.atanh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the inverse hyperbolic tangent of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the inverse hyperbolic tangent is to be calculated. - +x Float64 The number for which the inverse hyperbolic tangent is to be calculated. - .TE .SH RETURN The inverse hyperbolic tangent of `x`. diff --git a/man/man3/tomo-Num.cbrt.3 b/man/man3/tomo-Float64.cbrt.3 index 15e0ee9e..1cac7bc4 100644 --- a/man/man3/tomo-Num.cbrt.3 +++ b/man/man3/tomo-Float64.cbrt.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.cbrt 3 2025-09-21 "Tomo man-pages" +.TH Float64.cbrt 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.cbrt \- cube root +Float64.cbrt \- cube root .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.cbrt\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.cbrt\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the cube root of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the cube root is to be calculated. - +x Float64 The number for which the cube root is to be calculated. - .TE .SH RETURN The cube root of `x`. diff --git a/man/man3/tomo-Num.ceil.3 b/man/man3/tomo-Float64.ceil.3 index c0aac8a9..630e31a5 100644 --- a/man/man3/tomo-Num.ceil.3 +++ b/man/man3/tomo-Float64.ceil.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.ceil 3 2025-09-21 "Tomo man-pages" +.TH Float64.ceil 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.ceil \- ceiling function +Float64.ceil \- ceiling function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.ceil\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.ceil\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Rounds a number up to the nearest integer. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to be rounded up. - +x Float64 The number to be rounded up. - .TE .SH RETURN The smallest integer greater than or equal to `x`. diff --git a/man/man3/tomo-Num.clamped.3 b/man/man3/tomo-Float64.clamped.3 index 3ed48344..eba40be4 100644 --- a/man/man3/tomo-Num.clamped.3 +++ b/man/man3/tomo-Float64.clamped.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.clamped 3 2025-09-21 "Tomo man-pages" +.TH Float64.clamped 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.clamped \- clamp a number +Float64.clamped \- clamp a number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.clamped\ :\ func(x:\ Num,\ low:\ Num,\ high:\ Num\ ->\ Num) +.BI Float64.clamped\ :\ func(x:\ Float64,\ low:\ Float64,\ high:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Returns the given number clamped between two values so that it is within that range. @@ -22,9 +22,9 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to clamp. - -low Num The lowest value the result can take. - -high Num The highest value the result can take. - +x Float64 The number to clamp. - +low Float64 The lowest value the result can take. - +high Float64 The highest value the result can take. - .TE .SH RETURN The first argument clamped between the other two arguments. diff --git a/man/man3/tomo-Num.copysign.3 b/man/man3/tomo-Float64.copysign.3 index 9230754c..7100192d 100644 --- a/man/man3/tomo-Num.copysign.3 +++ b/man/man3/tomo-Float64.copysign.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.copysign 3 2025-09-21 "Tomo man-pages" +.TH Float64.copysign 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.copysign \- copy a number's sign +Float64.copysign \- copy a number's sign .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.copysign\ :\ func(x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.copysign\ :\ func(x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Copies the sign of one number to another. @@ -22,8 +22,8 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number whose magnitude will be copied. - -y Num The number whose sign will be copied. - +x Float64 The number whose magnitude will be copied. - +y Float64 The number whose sign will be copied. - .TE .SH RETURN A number with the magnitude of `x` and the sign of `y`. diff --git a/man/man3/tomo-Num.cos.3 b/man/man3/tomo-Float64.cos.3 index 6071c022..9b9ada05 100644 --- a/man/man3/tomo-Num.cos.3 +++ b/man/man3/tomo-Float64.cos.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.cos 3 2025-09-21 "Tomo man-pages" +.TH Float64.cos 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.cos \- cosine +Float64.cos \- cosine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.cos\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.cos\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the cosine of a number (angle in radians). @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The angle in radians. - +x Float64 The angle in radians. - .TE .SH RETURN The cosine of `x`. diff --git a/man/man3/tomo-Num.cosh.3 b/man/man3/tomo-Float64.cosh.3 index 843ec369..273171f0 100644 --- a/man/man3/tomo-Num.cosh.3 +++ b/man/man3/tomo-Float64.cosh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.cosh 3 2025-09-21 "Tomo man-pages" +.TH Float64.cosh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.cosh \- hyperbolic cosine +Float64.cosh \- hyperbolic cosine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.cosh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.cosh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the hyperbolic cosine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the hyperbolic cosine is to be calculated. - +x Float64 The number for which the hyperbolic cosine is to be calculated. - .TE .SH RETURN The hyperbolic cosine of `x`. diff --git a/man/man3/tomo-Num.erf.3 b/man/man3/tomo-Float64.erf.3 index aec6194f..59a9e842 100644 --- a/man/man3/tomo-Num.erf.3 +++ b/man/man3/tomo-Float64.erf.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.erf 3 2025-09-21 "Tomo man-pages" +.TH Float64.erf 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.erf \- error function +Float64.erf \- error function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.erf\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.erf\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the error function of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the error function is to be calculated. - +x Float64 The number for which the error function is to be calculated. - .TE .SH RETURN The error function of `x`. diff --git a/man/man3/tomo-Num.erfc.3 b/man/man3/tomo-Float64.erfc.3 index 27dcb44a..214d3477 100644 --- a/man/man3/tomo-Num.erfc.3 +++ b/man/man3/tomo-Float64.erfc.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.erfc 3 2025-09-21 "Tomo man-pages" +.TH Float64.erfc 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.erfc \- complimentary error function +Float64.erfc \- complimentary error function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.erfc\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.erfc\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the complementary error function of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the complementary error function is to be calculated. - +x Float64 The number for which the complementary error function is to be calculated. - .TE .SH RETURN The complementary error function of `x`. diff --git a/man/man3/tomo-Num.exp.3 b/man/man3/tomo-Float64.exp.3 index 4778a76d..945d8284 100644 --- a/man/man3/tomo-Num.exp.3 +++ b/man/man3/tomo-Float64.exp.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.exp 3 2025-09-21 "Tomo man-pages" +.TH Float64.exp 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.exp \- base-e exponentiation +Float64.exp \- base-e exponentiation .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.exp\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.exp\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the exponential function $e^x$ for a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The exponent. - +x Float64 The exponent. - .TE .SH RETURN The value of $e^x$. diff --git a/man/man3/tomo-Num.exp2.3 b/man/man3/tomo-Float64.exp2.3 index 1d997802..f6ab754a 100644 --- a/man/man3/tomo-Num.exp2.3 +++ b/man/man3/tomo-Float64.exp2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.exp2 3 2025-09-21 "Tomo man-pages" +.TH Float64.exp2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.exp2 \- base-2 exponentiation +Float64.exp2 \- base-2 exponentiation .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.exp2\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.exp2\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes $2^x$ for a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The exponent. - +x Float64 The exponent. - .TE .SH RETURN The value of $2^x$. diff --git a/man/man3/tomo-Num.expm1.3 b/man/man3/tomo-Float64.expm1.3 index 956bb3ac..c92e4c23 100644 --- a/man/man3/tomo-Num.expm1.3 +++ b/man/man3/tomo-Float64.expm1.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.expm1 3 2025-09-21 "Tomo man-pages" +.TH Float64.expm1 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.expm1 \- base-e exponential minus 1 +Float64.expm1 \- base-e exponential minus 1 .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.expm1\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.expm1\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes $e^x - 1$ for a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The exponent. - +x Float64 The exponent. - .TE .SH RETURN The value of $e^x - 1$. diff --git a/man/man3/tomo-Num.fdim.3 b/man/man3/tomo-Float64.fdim.3 index 2498fc7b..f7326d9a 100644 --- a/man/man3/tomo-Num.fdim.3 +++ b/man/man3/tomo-Float64.fdim.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.fdim 3 2025-09-21 "Tomo man-pages" +.TH Float64.fdim 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.fdim \- positive difference +Float64.fdim \- positive difference .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.fdim\ :\ func(x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.fdim\ :\ func(x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the positive difference between two numbers. @@ -22,8 +22,8 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The first number. - -y Num The second number. - +x Float64 The first number. - +y Float64 The second number. - .TE .SH RETURN The positive difference $\max(0, x - y)$. diff --git a/man/man3/tomo-Num.floor.3 b/man/man3/tomo-Float64.floor.3 index 2107a1f0..42a79dec 100644 --- a/man/man3/tomo-Num.floor.3 +++ b/man/man3/tomo-Float64.floor.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.floor 3 2025-09-21 "Tomo man-pages" +.TH Float64.floor 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.floor \- floor function +Float64.floor \- floor function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.floor\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.floor\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Rounds a number down to the nearest integer. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to be rounded down. - +x Float64 The number to be rounded down. - .TE .SH RETURN The largest integer less than or equal to `x`. diff --git a/man/man3/tomo-Num.hypot.3 b/man/man3/tomo-Float64.hypot.3 index 3c2e0913..19c197c6 100644 --- a/man/man3/tomo-Num.hypot.3 +++ b/man/man3/tomo-Float64.hypot.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.hypot 3 2025-09-21 "Tomo man-pages" +.TH Float64.hypot 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.hypot \- Euclidean distance function +Float64.hypot \- Euclidean distance function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.hypot\ :\ func(x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.hypot\ :\ func(x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the Euclidean norm, $\sqrt{x^2 + y^2}$, of two numbers. @@ -22,13 +22,13 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The first number. - -y Num The second number. - +x Float64 The first number. - +y Float64 The second number. - .TE .SH RETURN The Euclidean norm of `x` and `y`. .SH EXAMPLES .EX -assert Num.hypot(3, 4) == 5 +assert Float64.hypot(3, 4) == 5 .EE diff --git a/man/man3/tomo-Num.is_between.3 b/man/man3/tomo-Float64.is_between.3 index 7077b397..9889299e 100644 --- a/man/man3/tomo-Num.is_between.3 +++ b/man/man3/tomo-Float64.is_between.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.is_between 3 2025-09-21 "Tomo man-pages" +.TH Float64.is_between 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.is_between \- check if a number is in a range +Float64.is_between \- check if a number is in a range .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.is_between\ :\ func(x:\ Num,\ low:\ Num,\ high:\ Num\ ->\ Bool) +.BI Float64.is_between\ :\ func(x:\ Float64,\ low:\ Float64,\ high:\ Float64\ ->\ Bool) .fi .SH DESCRIPTION Determines if a number is between two numbers (inclusive). @@ -22,9 +22,9 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The integer to be checked. - -low Num The lower bound to check (inclusive). - -high Num The upper bound to check (inclusive). - +x Float64 The integer to be checked. - +low Float64 The lower bound to check (inclusive). - +high Float64 The upper bound to check (inclusive). - .TE .SH RETURN `yes` if `low <= x and x <= high`, otherwise `no` diff --git a/man/man3/tomo-Num.isfinite.3 b/man/man3/tomo-Float64.isfinite.3 index 99fdd913..b72268f5 100644 --- a/man/man3/tomo-Num.isfinite.3 +++ b/man/man3/tomo-Float64.isfinite.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.isfinite 3 2025-09-21 "Tomo man-pages" +.TH Float64.isfinite 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.isfinite \- check for finite number +Float64.isfinite \- check for finite number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.isfinite\ :\ func(n:\ Num\ ->\ Bool) +.BI Float64.isfinite\ :\ func(n:\ Float64\ ->\ Bool) .fi .SH DESCRIPTION Checks if a number is finite. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -n Num The number to be checked. - +n Float64 The number to be checked. - .TE .SH RETURN `yes` if `n` is finite, `no` otherwise. @@ -30,5 +30,5 @@ n Num The number to be checked. - .SH EXAMPLES .EX assert (1.0).isfinite() == yes -assert Num.INF.isfinite() == no +assert Float64.INF.isfinite() == no .EE diff --git a/man/man3/tomo-Num.isinf.3 b/man/man3/tomo-Float64.isinf.3 index f8587d7a..6701fdc0 100644 --- a/man/man3/tomo-Num.isinf.3 +++ b/man/man3/tomo-Float64.isinf.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.isinf 3 2025-09-21 "Tomo man-pages" +.TH Float64.isinf 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.isinf \- check for infinite number +Float64.isinf \- check for infinite number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.isinf\ :\ func(n:\ Num\ ->\ Bool) +.BI Float64.isinf\ :\ func(n:\ Float64\ ->\ Bool) .fi .SH DESCRIPTION Checks if a number is infinite. @@ -22,13 +22,13 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -n Num The number to be checked. - +n Float64 The number to be checked. - .TE .SH RETURN `yes` if `n` is infinite, `no` otherwise. .SH EXAMPLES .EX -assert Num.INF.isinf() == yes +assert Float64.INF.isinf() == yes assert (1.0).isinf() == no .EE diff --git a/man/man3/tomo-Num.j0.3 b/man/man3/tomo-Float64.j0.3 index 1ad0ed38..97ada7c7 100644 --- a/man/man3/tomo-Num.j0.3 +++ b/man/man3/tomo-Float64.j0.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.j0 3 2025-09-21 "Tomo man-pages" +.TH Float64.j0 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.j0 \- Bessel function +Float64.j0 \- Bessel function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.j0\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.j0\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the Bessel function of the first kind of order 0. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the Bessel function is to be calculated. - +x Float64 The number for which the Bessel function is to be calculated. - .TE .SH RETURN The Bessel function of the first kind of order 0 of `x`. diff --git a/man/man3/tomo-Num.j1.3 b/man/man3/tomo-Float64.j1.3 index 7f3fda5a..f5cf816e 100644 --- a/man/man3/tomo-Num.j1.3 +++ b/man/man3/tomo-Float64.j1.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.j1 3 2025-09-21 "Tomo man-pages" +.TH Float64.j1 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.j1 \- Bessel function +Float64.j1 \- Bessel function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.j1\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.j1\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the Bessel function of the first kind of order 1. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the Bessel function is to be calculated. - +x Float64 The number for which the Bessel function is to be calculated. - .TE .SH RETURN The Bessel function of the first kind of order 1 of `x`. diff --git a/man/man3/tomo-Num.log.3 b/man/man3/tomo-Float64.log.3 index 5cfd660c..7808ddf9 100644 --- a/man/man3/tomo-Num.log.3 +++ b/man/man3/tomo-Float64.log.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.log 3 2025-09-21 "Tomo man-pages" +.TH Float64.log 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.log \- natural logarithm +Float64.log \- natural logarithm .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.log\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.log\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the natural logarithm (base $e$) of a number. @@ -22,12 +22,12 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the natural logarithm is to be calculated. - +x Float64 The number for which the natural logarithm is to be calculated. - .TE .SH RETURN The natural logarithm of `x`. .SH EXAMPLES .EX -assert Num.E.log() == 1 +assert Float64.E.log() == 1 .EE diff --git a/man/man3/tomo-Num.log10.3 b/man/man3/tomo-Float64.log10.3 index 87000cb9..37d63100 100644 --- a/man/man3/tomo-Num.log10.3 +++ b/man/man3/tomo-Float64.log10.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.log10 3 2025-09-21 "Tomo man-pages" +.TH Float64.log10 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.log10 \- logarithm base-10 +Float64.log10 \- logarithm base-10 .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.log10\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.log10\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the base-10 logarithm of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the base-10 logarithm is to be calculated. - +x Float64 The number for which the base-10 logarithm is to be calculated. - .TE .SH RETURN The base-10 logarithm of `x`. diff --git a/man/man3/tomo-Num.log1p.3 b/man/man3/tomo-Float64.log1p.3 index dcf4a253..0cbec8f7 100644 --- a/man/man3/tomo-Num.log1p.3 +++ b/man/man3/tomo-Float64.log1p.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.log1p 3 2025-09-21 "Tomo man-pages" +.TH Float64.log1p 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.log1p \- logarithm of 1 plus x +Float64.log1p \- logarithm of 1 plus x .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.log1p\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.log1p\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes $\log(1 + x)$ for a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which $\log(1 + x)$ is to be calculated. - +x Float64 The number for which $\log(1 + x)$ is to be calculated. - .TE .SH RETURN The value of $\log(1 + x)$. diff --git a/man/man3/tomo-Num.log2.3 b/man/man3/tomo-Float64.log2.3 index 3e162d15..c6934d7b 100644 --- a/man/man3/tomo-Num.log2.3 +++ b/man/man3/tomo-Float64.log2.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.log2 3 2025-09-21 "Tomo man-pages" +.TH Float64.log2 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.log2 \- logarithm base-2 +Float64.log2 \- logarithm base-2 .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.log2\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.log2\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the base-2 logarithm of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the base-2 logarithm is to be calculated. - +x Float64 The number for which the base-2 logarithm is to be calculated. - .TE .SH RETURN The base-2 logarithm of `x`. diff --git a/man/man3/tomo-Num.logb.3 b/man/man3/tomo-Float64.logb.3 index 519e6042..ec165aac 100644 --- a/man/man3/tomo-Num.logb.3 +++ b/man/man3/tomo-Float64.logb.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.logb 3 2025-09-21 "Tomo man-pages" +.TH Float64.logb 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.logb \- exponent of a floating point value +Float64.logb \- exponent of a floating point value .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.logb\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.logb\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the binary exponent (base-2 logarithm) of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the binary exponent is to be calculated. - +x Float64 The number for which the binary exponent is to be calculated. - .TE .SH RETURN The binary exponent of `x`. diff --git a/man/man3/tomo-Num.mix.3 b/man/man3/tomo-Float64.mix.3 index f06462eb..24ed92d4 100644 --- a/man/man3/tomo-Num.mix.3 +++ b/man/man3/tomo-Float64.mix.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.mix 3 2025-09-21 "Tomo man-pages" +.TH Float64.mix 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.mix \- mix two numbers by an amount +Float64.mix \- mix two numbers by an amount .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.mix\ :\ func(amount:\ Num,\ x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.mix\ :\ func(amount:\ Float64,\ x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Interpolates between two numbers based on a given amount. @@ -22,9 +22,9 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -amount Num The interpolation factor (between `0` and `1`). - -x Num The starting number. - -y Num The ending number. - +amount Float64 The interpolation factor (between `0` and `1`). - +x Float64 The starting number. - +y Float64 The ending number. - .TE .SH RETURN The interpolated number between `x` and `y` based on `amount`. diff --git a/man/man3/tomo-Num.near.3 b/man/man3/tomo-Float64.near.3 index ef1b80ce..85a1bad4 100644 --- a/man/man3/tomo-Num.near.3 +++ b/man/man3/tomo-Float64.near.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.near 3 2025-09-21 "Tomo man-pages" +.TH Float64.near 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.near \- check if two numbers are near each other +Float64.near \- check if two numbers are near each other .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.near\ :\ func(x:\ Num,\ y:\ Num,\ ratio:\ Num\ =\ 1e-9,\ min_epsilon:\ Num\ =\ 1e-9\ ->\ Bool) +.BI Float64.near\ :\ func(x:\ Float64,\ y:\ Float64,\ ratio:\ Float64\ =\ 1e-9,\ min_epsilon:\ Float64\ =\ 1e-9\ ->\ Bool) .fi .SH DESCRIPTION Checks if two numbers are approximately equal within specified tolerances. If two numbers are within an absolute difference or the ratio between the two is small enough, they are considered near each other. @@ -22,10 +22,10 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The first number. - -y Num The second number. - -ratio Num The relative tolerance. Default is `1e-9`. 1e-9 -min_epsilon Num The absolute tolerance. Default is `1e-9`. 1e-9 +x Float64 The first number. - +y Float64 The second number. - +ratio Float64 The relative tolerance. Default is `1e-9`. 1e-9 +min_epsilon Float64 The absolute tolerance. Default is `1e-9`. 1e-9 .TE .SH RETURN `yes` if `x` and `y` are approximately equal within the specified tolerances, `no` otherwise. diff --git a/man/man3/tomo-Num.nextafter.3 b/man/man3/tomo-Float64.nextafter.3 index 1cc51818..4d931ca4 100644 --- a/man/man3/tomo-Num.nextafter.3 +++ b/man/man3/tomo-Float64.nextafter.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.nextafter 3 2025-09-21 "Tomo man-pages" +.TH Float64.nextafter 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.nextafter \- next floating point number +Float64.nextafter \- next floating point number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.nextafter\ :\ func(x:\ Num,\ y:\ Num\ ->\ Num) +.BI Float64.nextafter\ :\ func(x:\ Float64,\ y:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the next representable value after a given number towards a specified direction. @@ -22,8 +22,8 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The starting number. - -y Num The direction towards which to find the next representable value. - +x Float64 The starting number. - +y Float64 The direction towards which to find the next representable value. - .TE .SH RETURN The next representable value after `x` in the direction of `y`. diff --git a/man/man3/tomo-Num.parse.3 b/man/man3/tomo-Float64.parse.3 index d224e4e8..6829f53c 100644 --- a/man/man3/tomo-Num.parse.3 +++ b/man/man3/tomo-Float64.parse.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.parse 3 2025-09-21 "Tomo man-pages" +.TH Float64.parse 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.parse \- convert text to number +Float64.parse \- convert text to number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.parse\ :\ func(text:\ Text,\ remainder:\ &Text?\ =\ none\ ->\ Num?) +.BI Float64.parse\ :\ func(text:\ Text,\ remainder:\ &Text?\ =\ none\ ->\ Float64?) .fi .SH DESCRIPTION Converts a text representation of a number into a floating-point number. @@ -30,10 +30,10 @@ The number represented by the text or `none` if the entire text can't be parsed .SH EXAMPLES .EX -assert Num.parse("3.14") == 3.14 -assert Num.parse("1e3") == 1000 -assert Num.parse("1.5junk") == none +assert Float64.parse("3.14") == 3.14 +assert Float64.parse("1e3") == 1000 +assert Float64.parse("1.5junk") == none remainder : Text -assert Num.parse("1.5junk", &remainder) == 1.5 +assert Float64.parse("1.5junk", &remainder) == 1.5 assert remainder == "junk" .EE diff --git a/man/man3/tomo-Num.percent.3 b/man/man3/tomo-Float64.percent.3 index 5c41845e..4a8e3c34 100644 --- a/man/man3/tomo-Num.percent.3 +++ b/man/man3/tomo-Float64.percent.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.percent 3 2025-09-21 "Tomo man-pages" +.TH Float64.percent 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.percent \- format as a percentage +Float64.percent \- format as a percentage .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.percent\ :\ func(n:\ Num,\ precision:\ Num\ =\ 0.01\ ->\ Text) +.BI Float64.percent\ :\ func(n:\ Float64,\ precision:\ Float64\ =\ 0.01\ ->\ Text) .fi .SH DESCRIPTION Convert a number into a percentage text with a percent sign. @@ -22,8 +22,8 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -n Num The number to be converted to a percent. - -precision Num Round the percentage to this precision level. 0.01 +n Float64 The number to be converted to a percent. - +precision Float64 Round the percentage to this precision level. 0.01 .TE .SH RETURN A text representation of the number as a percentage with a percent sign. diff --git a/man/man3/tomo-Num.rint.3 b/man/man3/tomo-Float64.rint.3 index ca1f9bfa..8226d646 100644 --- a/man/man3/tomo-Num.rint.3 +++ b/man/man3/tomo-Float64.rint.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.rint 3 2025-09-21 "Tomo man-pages" +.TH Float64.rint 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.rint \- round to nearest integer +Float64.rint \- round to nearest integer .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.rint\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.rint\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Rounds a number to the nearest integer, with ties rounded to the nearest even integer. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to be rounded. - +x Float64 The number to be rounded. - .TE .SH RETURN The nearest integer value of `x`. diff --git a/man/man3/tomo-Num.round.3 b/man/man3/tomo-Float64.round.3 index 18075d34..872e2527 100644 --- a/man/man3/tomo-Num.round.3 +++ b/man/man3/tomo-Float64.round.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.round 3 2025-09-21 "Tomo man-pages" +.TH Float64.round 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.round \- round to nearest integer +Float64.round \- round to nearest integer .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.round\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.round\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Rounds a number to the nearest whole number integer. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to be rounded. - +x Float64 The number to be rounded. - .TE .SH RETURN The nearest integer value of `x`. diff --git a/man/man3/tomo-Num.significand.3 b/man/man3/tomo-Float64.significand.3 index 8cf9102c..ce49cb1c 100644 --- a/man/man3/tomo-Num.significand.3 +++ b/man/man3/tomo-Float64.significand.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.significand 3 2025-09-21 "Tomo man-pages" +.TH Float64.significand 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.significand \- get mantissa +Float64.significand \- get mantissa .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.significand\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.significand\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Extracts the significand (or mantissa) of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number from which to extract the significand. - +x Float64 The number from which to extract the significand. - .TE .SH RETURN The significand of `x`. diff --git a/man/man3/tomo-Num.sin.3 b/man/man3/tomo-Float64.sin.3 index 1d67353f..0f71ecf4 100644 --- a/man/man3/tomo-Num.sin.3 +++ b/man/man3/tomo-Float64.sin.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.sin 3 2025-09-21 "Tomo man-pages" +.TH Float64.sin 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.sin \- sine +Float64.sin \- sine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.sin\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.sin\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the sine of a number (angle in radians). @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The angle in radians. - +x Float64 The angle in radians. - .TE .SH RETURN The sine of `x`. diff --git a/man/man3/tomo-Num.sinh.3 b/man/man3/tomo-Float64.sinh.3 index c154356f..3bc477e8 100644 --- a/man/man3/tomo-Num.sinh.3 +++ b/man/man3/tomo-Float64.sinh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.sinh 3 2025-09-21 "Tomo man-pages" +.TH Float64.sinh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.sinh \- hyperbolic sine +Float64.sinh \- hyperbolic sine .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.sinh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.sinh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the hyperbolic sine of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the hyperbolic sine is to be calculated. - +x Float64 The number for which the hyperbolic sine is to be calculated. - .TE .SH RETURN The hyperbolic sine of `x`. diff --git a/man/man3/tomo-Num.sqrt.3 b/man/man3/tomo-Float64.sqrt.3 index 82cba25e..eb857cf1 100644 --- a/man/man3/tomo-Num.sqrt.3 +++ b/man/man3/tomo-Float64.sqrt.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.sqrt 3 2025-09-21 "Tomo man-pages" +.TH Float64.sqrt 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.sqrt \- square root +Float64.sqrt \- square root .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.sqrt\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.sqrt\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the square root of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the square root is to be calculated. - +x Float64 The number for which the square root is to be calculated. - .TE .SH RETURN The square root of `x`. diff --git a/man/man3/tomo-Num.tan.3 b/man/man3/tomo-Float64.tan.3 index 3e66ebb7..e0ba363a 100644 --- a/man/man3/tomo-Num.tan.3 +++ b/man/man3/tomo-Float64.tan.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.tan 3 2025-09-21 "Tomo man-pages" +.TH Float64.tan 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.tan \- tangent +Float64.tan \- tangent .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.tan\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.tan\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the tangent of a number (angle in radians). @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The angle in radians. - +x Float64 The angle in radians. - .TE .SH RETURN The tangent of `x`. diff --git a/man/man3/tomo-Num.tanh.3 b/man/man3/tomo-Float64.tanh.3 index 86c97449..fc71ca7a 100644 --- a/man/man3/tomo-Num.tanh.3 +++ b/man/man3/tomo-Float64.tanh.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.tanh 3 2025-09-21 "Tomo man-pages" +.TH Float64.tanh 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.tanh \- hyperbolic tangent +Float64.tanh \- hyperbolic tangent .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.tanh\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.tanh\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the hyperbolic tangent of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the hyperbolic tangent is to be calculated. - +x Float64 The number for which the hyperbolic tangent is to be calculated. - .TE .SH RETURN The hyperbolic tangent of `x`. diff --git a/man/man3/tomo-Num.tgamma.3 b/man/man3/tomo-Float64.tgamma.3 index c2cfb0f1..f0132bed 100644 --- a/man/man3/tomo-Num.tgamma.3 +++ b/man/man3/tomo-Float64.tgamma.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.tgamma 3 2025-09-21 "Tomo man-pages" +.TH Float64.tgamma 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.tgamma \- true gamma function +Float64.tgamma \- true gamma function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.tgamma\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.tgamma\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the gamma function of a number. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the gamma function is to be calculated. - +x Float64 The number for which the gamma function is to be calculated. - .TE .SH RETURN The gamma function of `x`. diff --git a/man/man3/tomo-Num.trunc.3 b/man/man3/tomo-Float64.trunc.3 index e32b0949..eb43275d 100644 --- a/man/man3/tomo-Num.trunc.3 +++ b/man/man3/tomo-Float64.trunc.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.trunc 3 2025-09-21 "Tomo man-pages" +.TH Float64.trunc 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.trunc \- truncate a number +Float64.trunc \- truncate a number .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.trunc\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.trunc\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Truncates a number to the nearest integer towards zero. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number to be truncated. - +x Float64 The number to be truncated. - .TE .SH RETURN The integer part of `x` towards zero. diff --git a/man/man3/tomo-Num.with_precision.3 b/man/man3/tomo-Float64.with_precision.3 index 66b5c0e9..2699e0a6 100644 --- a/man/man3/tomo-Num.with_precision.3 +++ b/man/man3/tomo-Float64.with_precision.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.with_precision 3 2025-09-21 "Tomo man-pages" +.TH Float64.with_precision 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.with_precision \- round to a given precision +Float64.with_precision \- round to a given precision .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.with_precision\ :\ func(n:\ Num,\ precision:\ Num\ ->\ Num) +.BI Float64.with_precision\ :\ func(n:\ Float64,\ precision:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Round a number to the given precision level (specified as `10`, `.1`, `.001` etc). @@ -22,8 +22,8 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -n Num The number to be rounded to a given precision. - -precision Num The precision to which the number should be rounded. - +n Float64 The number to be rounded to a given precision. - +precision Float64 The precision to which the number should be rounded. - .TE .SH RETURN The number, rounded to the given precision level. diff --git a/man/man3/tomo-Num.y0.3 b/man/man3/tomo-Float64.y0.3 index 0645c252..95d67c3b 100644 --- a/man/man3/tomo-Num.y0.3 +++ b/man/man3/tomo-Float64.y0.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.y0 3 2025-09-21 "Tomo man-pages" +.TH Float64.y0 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.y0 \- Bessel function +Float64.y0 \- Bessel function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.y0\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.y0\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the Bessel function of the second kind of order 0. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the Bessel function is to be calculated. - +x Float64 The number for which the Bessel function is to be calculated. - .TE .SH RETURN The Bessel function of the second kind of order 0 of `x`. diff --git a/man/man3/tomo-Num.y1.3 b/man/man3/tomo-Float64.y1.3 index ef572874..2c5bce05 100644 --- a/man/man3/tomo-Num.y1.3 +++ b/man/man3/tomo-Float64.y1.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Num.y1 3 2025-09-21 "Tomo man-pages" +.TH Float64.y1 3 2025-11-09 "Tomo man-pages" .SH NAME -Num.y1 \- Bessel function +Float64.y1 \- Bessel function .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI Num.y1\ :\ func(x:\ Num\ ->\ Num) +.BI Float64.y1\ :\ func(x:\ Float64\ ->\ Float64) .fi .SH DESCRIPTION Computes the Bessel function of the second kind of order 1. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -x Num The number for which the Bessel function is to be calculated. - +x Float64 The number for which the Bessel function is to be calculated. - .TE .SH RETURN The Bessel function of the second kind of order 1 of `x`. diff --git a/man/man3/tomo-Int.abs.3 b/man/man3/tomo-Int.abs.3 index d5f212cd..714cb8df 100644 --- a/man/man3/tomo-Int.abs.3 +++ b/man/man3/tomo-Int.abs.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.abs 3 2025-09-21 "Tomo man-pages" +.TH Int.abs 3 2025-11-09 "Tomo man-pages" .SH NAME Int.abs \- absolute value .SH LIBRARY diff --git a/man/man3/tomo-Int.choose.3 b/man/man3/tomo-Int.choose.3 index 5d178732..c18a8d54 100644 --- a/man/man3/tomo-Int.choose.3 +++ b/man/man3/tomo-Int.choose.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.choose 3 2025-09-21 "Tomo man-pages" +.TH Int.choose 3 2025-11-09 "Tomo man-pages" .SH NAME Int.choose \- binomial coefficient .SH LIBRARY diff --git a/man/man3/tomo-Int.clamped.3 b/man/man3/tomo-Int.clamped.3 index fbfe9fa8..c72f5e1c 100644 --- a/man/man3/tomo-Int.clamped.3 +++ b/man/man3/tomo-Int.clamped.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.clamped 3 2025-09-21 "Tomo man-pages" +.TH Int.clamped 3 2025-11-09 "Tomo man-pages" .SH NAME Int.clamped \- clamp an integer .SH LIBRARY diff --git a/man/man3/tomo-Int.factorial.3 b/man/man3/tomo-Int.factorial.3 index 34efbfa2..396b1f8f 100644 --- a/man/man3/tomo-Int.factorial.3 +++ b/man/man3/tomo-Int.factorial.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.factorial 3 2025-09-21 "Tomo man-pages" +.TH Int.factorial 3 2025-11-09 "Tomo man-pages" .SH NAME Int.factorial \- factorial .SH LIBRARY diff --git a/man/man3/tomo-Int.get_bit.3 b/man/man3/tomo-Int.get_bit.3 index d2009d58..d3d1d3ec 100644 --- a/man/man3/tomo-Int.get_bit.3 +++ b/man/man3/tomo-Int.get_bit.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.get_bit 3 2025-09-21 "Tomo man-pages" +.TH Int.get_bit 3 2025-11-09 "Tomo man-pages" .SH NAME Int.get_bit \- check whether a bit is set .SH LIBRARY diff --git a/man/man3/tomo-Int.hex.3 b/man/man3/tomo-Int.hex.3 index fcfee9de..f1c2fc8e 100644 --- a/man/man3/tomo-Int.hex.3 +++ b/man/man3/tomo-Int.hex.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.hex 3 2025-09-21 "Tomo man-pages" +.TH Int.hex 3 2025-11-09 "Tomo man-pages" .SH NAME Int.hex \- convert to hexidecimal .SH LIBRARY diff --git a/man/man3/tomo-Int.is_between.3 b/man/man3/tomo-Int.is_between.3 index 41c84c15..89340542 100644 --- a/man/man3/tomo-Int.is_between.3 +++ b/man/man3/tomo-Int.is_between.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.is_between 3 2025-09-21 "Tomo man-pages" +.TH Int.is_between 3 2025-11-09 "Tomo man-pages" .SH NAME Int.is_between \- test if an int is in a range .SH LIBRARY diff --git a/man/man3/tomo-Int.is_prime.3 b/man/man3/tomo-Int.is_prime.3 index d5adbac8..ad5cdc66 100644 --- a/man/man3/tomo-Int.is_prime.3 +++ b/man/man3/tomo-Int.is_prime.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.is_prime 3 2025-09-21 "Tomo man-pages" +.TH Int.is_prime 3 2025-11-09 "Tomo man-pages" .SH NAME Int.is_prime \- check if an integer is prime .SH LIBRARY diff --git a/man/man3/tomo-Int.next_prime.3 b/man/man3/tomo-Int.next_prime.3 index bac4e2ed..9380bc5f 100644 --- a/man/man3/tomo-Int.next_prime.3 +++ b/man/man3/tomo-Int.next_prime.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.next_prime 3 2025-09-21 "Tomo man-pages" +.TH Int.next_prime 3 2025-11-09 "Tomo man-pages" .SH NAME Int.next_prime \- get the next prime .SH LIBRARY diff --git a/man/man3/tomo-Int.octal.3 b/man/man3/tomo-Int.octal.3 index 3cd4f7f6..e4e462ae 100644 --- a/man/man3/tomo-Int.octal.3 +++ b/man/man3/tomo-Int.octal.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.octal 3 2025-09-21 "Tomo man-pages" +.TH Int.octal 3 2025-11-09 "Tomo man-pages" .SH NAME Int.octal \- convert to octal .SH LIBRARY diff --git a/man/man3/tomo-Int.onward.3 b/man/man3/tomo-Int.onward.3 index 2b38014b..106a84b9 100644 --- a/man/man3/tomo-Int.onward.3 +++ b/man/man3/tomo-Int.onward.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.onward 3 2025-09-21 "Tomo man-pages" +.TH Int.onward 3 2025-11-09 "Tomo man-pages" .SH NAME Int.onward \- iterate from a number onward .SH LIBRARY diff --git a/man/man3/tomo-Int.parse.3 b/man/man3/tomo-Int.parse.3 index 16793672..d2fc563f 100644 --- a/man/man3/tomo-Int.parse.3 +++ b/man/man3/tomo-Int.parse.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.parse 3 2025-09-21 "Tomo man-pages" +.TH Int.parse 3 2025-11-09 "Tomo man-pages" .SH NAME Int.parse \- convert text to integer .SH LIBRARY diff --git a/man/man3/tomo-Int.prev_prime.3 b/man/man3/tomo-Int.prev_prime.3 index 3391de4e..b66a0235 100644 --- a/man/man3/tomo-Int.prev_prime.3 +++ b/man/man3/tomo-Int.prev_prime.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.prev_prime 3 2025-09-21 "Tomo man-pages" +.TH Int.prev_prime 3 2025-11-09 "Tomo man-pages" .SH NAME Int.prev_prime \- get the previous prime .SH LIBRARY diff --git a/man/man3/tomo-Int.sqrt.3 b/man/man3/tomo-Int.sqrt.3 index a2a66a09..d1fd1023 100644 --- a/man/man3/tomo-Int.sqrt.3 +++ b/man/man3/tomo-Int.sqrt.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.sqrt 3 2025-09-21 "Tomo man-pages" +.TH Int.sqrt 3 2025-11-09 "Tomo man-pages" .SH NAME Int.sqrt \- square root .SH LIBRARY diff --git a/man/man3/tomo-Int.to.3 b/man/man3/tomo-Int.to.3 index ea8112bc..804f5064 100644 --- a/man/man3/tomo-Int.to.3 +++ b/man/man3/tomo-Int.to.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Int.to 3 2025-09-21 "Tomo man-pages" +.TH Int.to 3 2025-11-09 "Tomo man-pages" .SH NAME Int.to \- iterate a range of integers .SH LIBRARY diff --git a/man/man3/tomo-List.binary_search.3 b/man/man3/tomo-List.binary_search.3 index b2cb1759..a13ec08c 100644 --- a/man/man3/tomo-List.binary_search.3 +++ b/man/man3/tomo-List.binary_search.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.binary_search 3 2025-09-21 "Tomo man-pages" +.TH List.binary_search 3 2025-11-09 "Tomo man-pages" .SH NAME List.binary_search \- binary search .SH LIBRARY diff --git a/man/man3/tomo-List.by.3 b/man/man3/tomo-List.by.3 index 4d201c43..28373446 100644 --- a/man/man3/tomo-List.by.3 +++ b/man/man3/tomo-List.by.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.by 3 2025-09-21 "Tomo man-pages" +.TH List.by 3 2025-11-09 "Tomo man-pages" .SH NAME List.by \- slice by a step value .SH LIBRARY diff --git a/man/man3/tomo-List.clear.3 b/man/man3/tomo-List.clear.3 index bece5524..6c2eeb3e 100644 --- a/man/man3/tomo-List.clear.3 +++ b/man/man3/tomo-List.clear.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.clear 3 2025-10-11 "Tomo man-pages" +.TH List.clear 3 2025-11-09 "Tomo man-pages" .SH NAME List.clear \- clear a list .SH LIBRARY diff --git a/man/man3/tomo-List.counts.3 b/man/man3/tomo-List.counts.3 index 5b6d9b1b..b64a29f8 100644 --- a/man/man3/tomo-List.counts.3 +++ b/man/man3/tomo-List.counts.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.counts 3 2025-09-21 "Tomo man-pages" +.TH List.counts 3 2025-11-09 "Tomo man-pages" .SH NAME List.counts \- count occurrences .SH LIBRARY diff --git a/man/man3/tomo-List.find.3 b/man/man3/tomo-List.find.3 index 65ae5926..76c8c0fb 100644 --- a/man/man3/tomo-List.find.3 +++ b/man/man3/tomo-List.find.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.find 3 2025-09-21 "Tomo man-pages" +.TH List.find 3 2025-11-09 "Tomo man-pages" .SH NAME List.find \- find an element's index .SH LIBRARY diff --git a/man/man3/tomo-List.from.3 b/man/man3/tomo-List.from.3 index a7a24cd6..516dd140 100644 --- a/man/man3/tomo-List.from.3 +++ b/man/man3/tomo-List.from.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.from 3 2025-09-21 "Tomo man-pages" +.TH List.from 3 2025-11-09 "Tomo man-pages" .SH NAME List.from \- slice an array from a start index .SH LIBRARY diff --git a/man/man3/tomo-List.has.3 b/man/man3/tomo-List.has.3 index 96507253..cd04b66b 100644 --- a/man/man3/tomo-List.has.3 +++ b/man/man3/tomo-List.has.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.has 3 2025-09-21 "Tomo man-pages" +.TH List.has 3 2025-11-09 "Tomo man-pages" .SH NAME List.has \- check for member .SH LIBRARY diff --git a/man/man3/tomo-List.heap_pop.3 b/man/man3/tomo-List.heap_pop.3 index cd4e292a..d4662a45 100644 --- a/man/man3/tomo-List.heap_pop.3 +++ b/man/man3/tomo-List.heap_pop.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.heap_pop 3 2025-09-21 "Tomo man-pages" +.TH List.heap_pop 3 2025-11-09 "Tomo man-pages" .SH NAME List.heap_pop \- heap pop .SH LIBRARY diff --git a/man/man3/tomo-List.heap_push.3 b/man/man3/tomo-List.heap_push.3 index 3c1804bd..8a5d098a 100644 --- a/man/man3/tomo-List.heap_push.3 +++ b/man/man3/tomo-List.heap_push.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.heap_push 3 2025-10-11 "Tomo man-pages" +.TH List.heap_push 3 2025-11-09 "Tomo man-pages" .SH NAME List.heap_push \- heap push .SH LIBRARY diff --git a/man/man3/tomo-List.heapify.3 b/man/man3/tomo-List.heapify.3 index 345a47b9..e1a26082 100644 --- a/man/man3/tomo-List.heapify.3 +++ b/man/man3/tomo-List.heapify.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.heapify 3 2025-10-11 "Tomo man-pages" +.TH List.heapify 3 2025-11-09 "Tomo man-pages" .SH NAME List.heapify \- convert a list into a heap .SH LIBRARY diff --git a/man/man3/tomo-List.insert.3 b/man/man3/tomo-List.insert.3 index 0ab71a3f..5876bb80 100644 --- a/man/man3/tomo-List.insert.3 +++ b/man/man3/tomo-List.insert.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.insert 3 2025-09-21 "Tomo man-pages" +.TH List.insert 3 2025-11-09 "Tomo man-pages" .SH NAME List.insert \- add an item to a list .SH LIBRARY diff --git a/man/man3/tomo-List.insert_all.3 b/man/man3/tomo-List.insert_all.3 index 795f4a2d..0c5e2b97 100644 --- a/man/man3/tomo-List.insert_all.3 +++ b/man/man3/tomo-List.insert_all.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.insert_all 3 2025-09-21 "Tomo man-pages" +.TH List.insert_all 3 2025-11-09 "Tomo man-pages" .SH NAME List.insert_all \- add multiple items to a list .SH LIBRARY diff --git a/man/man3/tomo-List.pop.3 b/man/man3/tomo-List.pop.3 index b157e0ac..c9623752 100644 --- a/man/man3/tomo-List.pop.3 +++ b/man/man3/tomo-List.pop.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.pop 3 2025-09-21 "Tomo man-pages" +.TH List.pop 3 2025-11-09 "Tomo man-pages" .SH NAME List.pop \- pop an item from a list .SH LIBRARY diff --git a/man/man3/tomo-List.random.3 b/man/man3/tomo-List.random.3 index 0c82bfd0..44ae1377 100644 --- a/man/man3/tomo-List.random.3 +++ b/man/man3/tomo-List.random.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.random 3 2025-09-21 "Tomo man-pages" +.TH List.random 3 2025-11-09 "Tomo man-pages" .SH NAME List.random \- pick a random element .SH LIBRARY diff --git a/man/man3/tomo-List.remove_at.3 b/man/man3/tomo-List.remove_at.3 index 8e993931..236a6d9e 100644 --- a/man/man3/tomo-List.remove_at.3 +++ b/man/man3/tomo-List.remove_at.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.remove_at 3 2025-09-21 "Tomo man-pages" +.TH List.remove_at 3 2025-11-09 "Tomo man-pages" .SH NAME List.remove_at \- remove an item by index .SH LIBRARY diff --git a/man/man3/tomo-List.remove_item.3 b/man/man3/tomo-List.remove_item.3 index 02631ba6..92aded13 100644 --- a/man/man3/tomo-List.remove_item.3 +++ b/man/man3/tomo-List.remove_item.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.remove_item 3 2025-09-21 "Tomo man-pages" +.TH List.remove_item 3 2025-11-09 "Tomo man-pages" .SH NAME List.remove_item \- remove an item by value .SH LIBRARY diff --git a/man/man3/tomo-List.reversed.3 b/man/man3/tomo-List.reversed.3 index 2b84e333..406963fd 100644 --- a/man/man3/tomo-List.reversed.3 +++ b/man/man3/tomo-List.reversed.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.reversed 3 2025-09-21 "Tomo man-pages" +.TH List.reversed 3 2025-11-09 "Tomo man-pages" .SH NAME List.reversed \- get a reversed list .SH LIBRARY diff --git a/man/man3/tomo-List.sample.3 b/man/man3/tomo-List.sample.3 index 0e4d779c..c090d8b7 100644 --- a/man/man3/tomo-List.sample.3 +++ b/man/man3/tomo-List.sample.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.sample 3 2025-09-21 "Tomo man-pages" +.TH List.sample 3 2025-11-09 "Tomo man-pages" .SH NAME List.sample \- weighted random choices .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI List.sample\ :\ func(list:\ [T],\ count:\ Int,\ weights:\ [Num]?\ =\ none,\ random:\ func(->Num)?\ =\ none\ ->\ [T]) +.BI List.sample\ :\ func(list:\ [T],\ count:\ Int,\ weights:\ [Float64]?\ =\ none,\ random:\ func(->Float64)?\ =\ none\ ->\ [T]) .fi .SH DESCRIPTION Selects a sample of elements from the list, optionally with weighted probabilities. @@ -24,8 +24,8 @@ l l l l. Name Type Description Default list [T] The list to sample from. - count Int The number of elements to sample. - -weights [Num]? The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. none -random func(->Num)? If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) none +weights [Float64]? The probability weights for each element in the list. These values do not need to add up to any particular number, they are relative weights. If no weights are given, elements will be sampled with uniform probability. none +random func(->Float64)? If provided, this function will be used to get random values for sampling the list. The provided function should return random numbers between `0.0` (inclusive) and `1.0` (exclusive). (Used for deterministic pseudorandom number generation) none .TE .SH RETURN A list of sampled elements from the list. diff --git a/man/man3/tomo-List.shuffle.3 b/man/man3/tomo-List.shuffle.3 index 875a73c6..ae280483 100644 --- a/man/man3/tomo-List.shuffle.3 +++ b/man/man3/tomo-List.shuffle.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.shuffle 3 2025-10-11 "Tomo man-pages" +.TH List.shuffle 3 2025-11-09 "Tomo man-pages" .SH NAME List.shuffle \- shuffle a list in place .SH LIBRARY diff --git a/man/man3/tomo-List.shuffled.3 b/man/man3/tomo-List.shuffled.3 index 25e63154..caaa90f2 100644 --- a/man/man3/tomo-List.shuffled.3 +++ b/man/man3/tomo-List.shuffled.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.shuffled 3 2025-09-21 "Tomo man-pages" +.TH List.shuffled 3 2025-11-09 "Tomo man-pages" .SH NAME List.shuffled \- return a shuffled list .SH LIBRARY diff --git a/man/man3/tomo-List.slice.3 b/man/man3/tomo-List.slice.3 index 676e2a08..6d560b21 100644 --- a/man/man3/tomo-List.slice.3 +++ b/man/man3/tomo-List.slice.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.slice 3 2025-09-21 "Tomo man-pages" +.TH List.slice 3 2025-11-09 "Tomo man-pages" .SH NAME List.slice \- get a slice of a list .SH LIBRARY diff --git a/man/man3/tomo-List.sort.3 b/man/man3/tomo-List.sort.3 index 3957e9fe..355d3bff 100644 --- a/man/man3/tomo-List.sort.3 +++ b/man/man3/tomo-List.sort.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.sort 3 2025-09-21 "Tomo man-pages" +.TH List.sort 3 2025-11-09 "Tomo man-pages" .SH NAME List.sort \- sort a list .SH LIBRARY diff --git a/man/man3/tomo-List.sorted.3 b/man/man3/tomo-List.sorted.3 index 49d75ecd..264743f4 100644 --- a/man/man3/tomo-List.sorted.3 +++ b/man/man3/tomo-List.sorted.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.sorted 3 2025-09-21 "Tomo man-pages" +.TH List.sorted 3 2025-11-09 "Tomo man-pages" .SH NAME List.sorted \- sorted copy of a list .SH LIBRARY diff --git a/man/man3/tomo-List.to.3 b/man/man3/tomo-List.to.3 index 5af2a6db..658d2d63 100644 --- a/man/man3/tomo-List.to.3 +++ b/man/man3/tomo-List.to.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.to 3 2025-09-21 "Tomo man-pages" +.TH List.to 3 2025-11-09 "Tomo man-pages" .SH NAME List.to \- slice a list to an end index .SH LIBRARY diff --git a/man/man3/tomo-List.unique.3 b/man/man3/tomo-List.unique.3 index 9ed81687..efe1157d 100644 --- a/man/man3/tomo-List.unique.3 +++ b/man/man3/tomo-List.unique.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.unique 3 2025-10-11 "Tomo man-pages" +.TH List.unique 3 2025-11-09 "Tomo man-pages" .SH NAME List.unique \- get the unique items in a list .SH LIBRARY diff --git a/man/man3/tomo-List.where.3 b/man/man3/tomo-List.where.3 index 8d5c71ef..837d30ea 100644 --- a/man/man3/tomo-List.where.3 +++ b/man/man3/tomo-List.where.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH List.where 3 2025-09-21 "Tomo man-pages" +.TH List.where 3 2025-11-09 "Tomo man-pages" .SH NAME List.where \- find an index where a predicate matches .SH LIBRARY diff --git a/man/man3/tomo-Path.accessed.3 b/man/man3/tomo-Path.accessed.3 index 51e4bbed..866a6c47 100644 --- a/man/man3/tomo-Path.accessed.3 +++ b/man/man3/tomo-Path.accessed.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.accessed 3 2025-09-21 "Tomo man-pages" +.TH Path.accessed 3 2025-11-09 "Tomo man-pages" .SH NAME Path.accessed \- access time .SH LIBRARY diff --git a/man/man3/tomo-Path.append.3 b/man/man3/tomo-Path.append.3 index af1f0a5f..0073718b 100644 --- a/man/man3/tomo-Path.append.3 +++ b/man/man3/tomo-Path.append.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.append 3 2025-05-17 "Tomo man-pages" +.TH Path.append 3 2025-11-09 "Tomo man-pages" .SH NAME Path.append \- append to a file .SH LIBRARY diff --git a/man/man3/tomo-Path.append_bytes.3 b/man/man3/tomo-Path.append_bytes.3 index 3a6dc1c8..ee63c089 100644 --- a/man/man3/tomo-Path.append_bytes.3 +++ b/man/man3/tomo-Path.append_bytes.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.append_bytes 3 2025-05-17 "Tomo man-pages" +.TH Path.append_bytes 3 2025-11-09 "Tomo man-pages" .SH NAME Path.append_bytes \- append bytes to a file .SH LIBRARY diff --git a/man/man3/tomo-Path.base_name.3 b/man/man3/tomo-Path.base_name.3 index fe43fc04..dbd09e8d 100644 --- a/man/man3/tomo-Path.base_name.3 +++ b/man/man3/tomo-Path.base_name.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.base_name 3 2025-09-21 "Tomo man-pages" +.TH Path.base_name 3 2025-11-09 "Tomo man-pages" .SH NAME Path.base_name \- base name of a file .SH LIBRARY diff --git a/man/man3/tomo-Path.by_line.3 b/man/man3/tomo-Path.by_line.3 index ff7a737c..476de256 100644 --- a/man/man3/tomo-Path.by_line.3 +++ b/man/man3/tomo-Path.by_line.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.by_line 3 2025-05-17 "Tomo man-pages" +.TH Path.by_line 3 2025-11-09 "Tomo man-pages" .SH NAME Path.by_line \- iterate by line .SH LIBRARY diff --git a/man/man3/tomo-Path.can_execute.3 b/man/man3/tomo-Path.can_execute.3 index 7f9ed358..2970f78b 100644 --- a/man/man3/tomo-Path.can_execute.3 +++ b/man/man3/tomo-Path.can_execute.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.can_execute 3 2025-09-21 "Tomo man-pages" +.TH Path.can_execute 3 2025-11-09 "Tomo man-pages" .SH NAME Path.can_execute \- check execute permissions .SH LIBRARY diff --git a/man/man3/tomo-Path.can_read.3 b/man/man3/tomo-Path.can_read.3 index 30cb39a0..785d3d54 100644 --- a/man/man3/tomo-Path.can_read.3 +++ b/man/man3/tomo-Path.can_read.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.can_read 3 2025-09-21 "Tomo man-pages" +.TH Path.can_read 3 2025-11-09 "Tomo man-pages" .SH NAME Path.can_read \- check read permissions .SH LIBRARY diff --git a/man/man3/tomo-Path.can_write.3 b/man/man3/tomo-Path.can_write.3 index d1be5006..19a3b944 100644 --- a/man/man3/tomo-Path.can_write.3 +++ b/man/man3/tomo-Path.can_write.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.can_write 3 2025-09-21 "Tomo man-pages" +.TH Path.can_write 3 2025-11-09 "Tomo man-pages" .SH NAME Path.can_write \- check write permissions .SH LIBRARY diff --git a/man/man3/tomo-Path.changed.3 b/man/man3/tomo-Path.changed.3 index b6bd8033..f942bf69 100644 --- a/man/man3/tomo-Path.changed.3 +++ b/man/man3/tomo-Path.changed.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.changed 3 2025-09-21 "Tomo man-pages" +.TH Path.changed 3 2025-11-09 "Tomo man-pages" .SH NAME Path.changed \- get the last changed time .SH LIBRARY diff --git a/man/man3/tomo-Path.child.3 b/man/man3/tomo-Path.child.3 index f61bc9d0..1b4e0497 100644 --- a/man/man3/tomo-Path.child.3 +++ b/man/man3/tomo-Path.child.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.child 3 2025-09-21 "Tomo man-pages" +.TH Path.child 3 2025-11-09 "Tomo man-pages" .SH NAME Path.child \- append a child to a path .SH LIBRARY diff --git a/man/man3/tomo-Path.children.3 b/man/man3/tomo-Path.children.3 index 10e80713..9c83a366 100644 --- a/man/man3/tomo-Path.children.3 +++ b/man/man3/tomo-Path.children.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.children 3 2025-09-21 "Tomo man-pages" +.TH Path.children 3 2025-11-09 "Tomo man-pages" .SH NAME Path.children \- get children of a directory .SH LIBRARY diff --git a/man/man3/tomo-Path.create_directory.3 b/man/man3/tomo-Path.create_directory.3 index adfe7e97..50e139df 100644 --- a/man/man3/tomo-Path.create_directory.3 +++ b/man/man3/tomo-Path.create_directory.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.create_directory 3 2025-05-17 "Tomo man-pages" +.TH Path.create_directory 3 2025-11-09 "Tomo man-pages" .SH NAME Path.create_directory \- make a directory .SH LIBRARY diff --git a/man/man3/tomo-Path.current_dir.3 b/man/man3/tomo-Path.current_dir.3 index 2d887983..ac6eb326 100644 --- a/man/man3/tomo-Path.current_dir.3 +++ b/man/man3/tomo-Path.current_dir.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.current_dir 3 2025-09-21 "Tomo man-pages" +.TH Path.current_dir 3 2025-11-09 "Tomo man-pages" .SH NAME Path.current_dir \- get current directory .SH LIBRARY diff --git a/man/man3/tomo-Path.exists.3 b/man/man3/tomo-Path.exists.3 index 923fa27d..7bf91bd8 100644 --- a/man/man3/tomo-Path.exists.3 +++ b/man/man3/tomo-Path.exists.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.exists 3 2025-09-21 "Tomo man-pages" +.TH Path.exists 3 2025-11-09 "Tomo man-pages" .SH NAME Path.exists \- check if a path exists .SH LIBRARY diff --git a/man/man3/tomo-Path.expand_home.3 b/man/man3/tomo-Path.expand_home.3 index 7114b65b..c88f25bd 100644 --- a/man/man3/tomo-Path.expand_home.3 +++ b/man/man3/tomo-Path.expand_home.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.expand_home 3 2025-10-11 "Tomo man-pages" +.TH Path.expand_home 3 2025-11-09 "Tomo man-pages" .SH NAME Path.expand_home \- expand ~ to $HOME .SH LIBRARY diff --git a/man/man3/tomo-Path.extension.3 b/man/man3/tomo-Path.extension.3 index f77f692a..0185400a 100644 --- a/man/man3/tomo-Path.extension.3 +++ b/man/man3/tomo-Path.extension.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.extension 3 2025-09-21 "Tomo man-pages" +.TH Path.extension 3 2025-11-09 "Tomo man-pages" .SH NAME Path.extension \- get file extension .SH LIBRARY diff --git a/man/man3/tomo-Path.files.3 b/man/man3/tomo-Path.files.3 index fcde934f..32c180fa 100644 --- a/man/man3/tomo-Path.files.3 +++ b/man/man3/tomo-Path.files.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.files 3 2025-09-21 "Tomo man-pages" +.TH Path.files 3 2025-11-09 "Tomo man-pages" .SH NAME Path.files \- list files in a directory .SH LIBRARY diff --git a/man/man3/tomo-Path.from_components.3 b/man/man3/tomo-Path.from_components.3 index f7dbd7f1..eea6d2db 100644 --- a/man/man3/tomo-Path.from_components.3 +++ b/man/man3/tomo-Path.from_components.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.from_components 3 2025-09-21 "Tomo man-pages" +.TH Path.from_components 3 2025-11-09 "Tomo man-pages" .SH NAME Path.from_components \- build a path from components .SH LIBRARY diff --git a/man/man3/tomo-Path.glob.3 b/man/man3/tomo-Path.glob.3 index 07de7a33..d5feeef7 100644 --- a/man/man3/tomo-Path.glob.3 +++ b/man/man3/tomo-Path.glob.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.glob 3 2025-09-21 "Tomo man-pages" +.TH Path.glob 3 2025-11-09 "Tomo man-pages" .SH NAME Path.glob \- perform file globbing .SH LIBRARY diff --git a/man/man3/tomo-Path.group.3 b/man/man3/tomo-Path.group.3 index 5c9f80c8..4c746746 100644 --- a/man/man3/tomo-Path.group.3 +++ b/man/man3/tomo-Path.group.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.group 3 2025-09-21 "Tomo man-pages" +.TH Path.group 3 2025-11-09 "Tomo man-pages" .SH NAME Path.group \- get the owning group .SH LIBRARY diff --git a/man/man3/tomo-Path.has_extension.3 b/man/man3/tomo-Path.has_extension.3 index ffd1f967..7fca6987 100644 --- a/man/man3/tomo-Path.has_extension.3 +++ b/man/man3/tomo-Path.has_extension.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.has_extension 3 2025-09-21 "Tomo man-pages" +.TH Path.has_extension 3 2025-11-09 "Tomo man-pages" .SH NAME Path.has_extension \- check if a path has a given extension .SH LIBRARY diff --git a/man/man3/tomo-Path.is_directory.3 b/man/man3/tomo-Path.is_directory.3 index 8ed41249..089cf3b8 100644 --- a/man/man3/tomo-Path.is_directory.3 +++ b/man/man3/tomo-Path.is_directory.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.is_directory 3 2025-09-21 "Tomo man-pages" +.TH Path.is_directory 3 2025-11-09 "Tomo man-pages" .SH NAME Path.is_directory \- check if a path is a directory .SH LIBRARY diff --git a/man/man3/tomo-Path.is_file.3 b/man/man3/tomo-Path.is_file.3 index 8d6218f3..be425328 100644 --- a/man/man3/tomo-Path.is_file.3 +++ b/man/man3/tomo-Path.is_file.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.is_file 3 2025-09-21 "Tomo man-pages" +.TH Path.is_file 3 2025-11-09 "Tomo man-pages" .SH NAME Path.is_file \- check if a path is a file .SH LIBRARY diff --git a/man/man3/tomo-Path.is_socket.3 b/man/man3/tomo-Path.is_socket.3 index 1733364e..d371d1d9 100644 --- a/man/man3/tomo-Path.is_socket.3 +++ b/man/man3/tomo-Path.is_socket.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.is_socket 3 2025-09-21 "Tomo man-pages" +.TH Path.is_socket 3 2025-11-09 "Tomo man-pages" .SH NAME Path.is_socket \- check if a path is a socket .SH LIBRARY diff --git a/man/man3/tomo-Path.is_symlink.3 b/man/man3/tomo-Path.is_symlink.3 index 6a8bdb7e..1f54231c 100644 --- a/man/man3/tomo-Path.is_symlink.3 +++ b/man/man3/tomo-Path.is_symlink.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.is_symlink 3 2025-09-21 "Tomo man-pages" +.TH Path.is_symlink 3 2025-11-09 "Tomo man-pages" .SH NAME Path.is_symlink \- check if a path is a symbolic link .SH LIBRARY diff --git a/man/man3/tomo-Path.modified.3 b/man/man3/tomo-Path.modified.3 index c91aae03..fd47e9fe 100644 --- a/man/man3/tomo-Path.modified.3 +++ b/man/man3/tomo-Path.modified.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.modified 3 2025-09-21 "Tomo man-pages" +.TH Path.modified 3 2025-11-09 "Tomo man-pages" .SH NAME Path.modified \- get file modification time .SH LIBRARY diff --git a/man/man3/tomo-Path.owner.3 b/man/man3/tomo-Path.owner.3 index 2f4913cd..f3a086e2 100644 --- a/man/man3/tomo-Path.owner.3 +++ b/man/man3/tomo-Path.owner.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.owner 3 2025-09-21 "Tomo man-pages" +.TH Path.owner 3 2025-11-09 "Tomo man-pages" .SH NAME Path.owner \- get file owner .SH LIBRARY diff --git a/man/man3/tomo-Path.parent.3 b/man/man3/tomo-Path.parent.3 index 459d97c3..1e81ab7c 100644 --- a/man/man3/tomo-Path.parent.3 +++ b/man/man3/tomo-Path.parent.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.parent 3 2025-09-21 "Tomo man-pages" +.TH Path.parent 3 2025-11-09 "Tomo man-pages" .SH NAME Path.parent \- get parent directory .SH LIBRARY diff --git a/man/man3/tomo-Path.read.3 b/man/man3/tomo-Path.read.3 index 779bb397..88ad9e80 100644 --- a/man/man3/tomo-Path.read.3 +++ b/man/man3/tomo-Path.read.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.read 3 2025-09-21 "Tomo man-pages" +.TH Path.read 3 2025-11-09 "Tomo man-pages" .SH NAME Path.read \- read file contents .SH LIBRARY diff --git a/man/man3/tomo-Path.read_bytes.3 b/man/man3/tomo-Path.read_bytes.3 index a23cbf6d..0c7d82da 100644 --- a/man/man3/tomo-Path.read_bytes.3 +++ b/man/man3/tomo-Path.read_bytes.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.read_bytes 3 2025-09-21 "Tomo man-pages" +.TH Path.read_bytes 3 2025-11-09 "Tomo man-pages" .SH NAME Path.read_bytes \- read file contents as bytes .SH LIBRARY diff --git a/man/man3/tomo-Path.relative_to.3 b/man/man3/tomo-Path.relative_to.3 index 963b9a5b..e528205a 100644 --- a/man/man3/tomo-Path.relative_to.3 +++ b/man/man3/tomo-Path.relative_to.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.relative_to 3 2025-09-21 "Tomo man-pages" +.TH Path.relative_to 3 2025-11-09 "Tomo man-pages" .SH NAME Path.relative_to \- apply a relative path to another .SH LIBRARY diff --git a/man/man3/tomo-Path.remove.3 b/man/man3/tomo-Path.remove.3 index 7dcb4361..da3179b4 100644 --- a/man/man3/tomo-Path.remove.3 +++ b/man/man3/tomo-Path.remove.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.remove 3 2025-05-17 "Tomo man-pages" +.TH Path.remove 3 2025-11-09 "Tomo man-pages" .SH NAME Path.remove \- remove a file or directory .SH LIBRARY diff --git a/man/man3/tomo-Path.resolved.3 b/man/man3/tomo-Path.resolved.3 index a40fd80c..efc76e28 100644 --- a/man/man3/tomo-Path.resolved.3 +++ b/man/man3/tomo-Path.resolved.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.resolved 3 2025-09-21 "Tomo man-pages" +.TH Path.resolved 3 2025-11-09 "Tomo man-pages" .SH NAME Path.resolved \- resolve a path .SH LIBRARY diff --git a/man/man3/tomo-Path.set_owner.3 b/man/man3/tomo-Path.set_owner.3 index f83d9470..48a256d5 100644 --- a/man/man3/tomo-Path.set_owner.3 +++ b/man/man3/tomo-Path.set_owner.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.set_owner 3 2025-05-17 "Tomo man-pages" +.TH Path.set_owner 3 2025-11-09 "Tomo man-pages" .SH NAME Path.set_owner \- set the owner .SH LIBRARY diff --git a/man/man3/tomo-Path.sibling.3 b/man/man3/tomo-Path.sibling.3 index 5c39d159..324f8f4d 100644 --- a/man/man3/tomo-Path.sibling.3 +++ b/man/man3/tomo-Path.sibling.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.sibling 3 2025-09-21 "Tomo man-pages" +.TH Path.sibling 3 2025-11-09 "Tomo man-pages" .SH NAME Path.sibling \- get another path in the same directory .SH LIBRARY diff --git a/man/man3/tomo-Path.subdirectories.3 b/man/man3/tomo-Path.subdirectories.3 index a691f94a..f54f9a11 100644 --- a/man/man3/tomo-Path.subdirectories.3 +++ b/man/man3/tomo-Path.subdirectories.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.subdirectories 3 2025-09-21 "Tomo man-pages" +.TH Path.subdirectories 3 2025-11-09 "Tomo man-pages" .SH NAME Path.subdirectories \- get subdirectories .SH LIBRARY diff --git a/man/man3/tomo-Path.unique_directory.3 b/man/man3/tomo-Path.unique_directory.3 index 866ca565..0a1c8fe9 100644 --- a/man/man3/tomo-Path.unique_directory.3 +++ b/man/man3/tomo-Path.unique_directory.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.unique_directory 3 2025-09-21 "Tomo man-pages" +.TH Path.unique_directory 3 2025-11-09 "Tomo man-pages" .SH NAME Path.unique_directory \- create a directory with a unique name .SH LIBRARY diff --git a/man/man3/tomo-Path.write.3 b/man/man3/tomo-Path.write.3 index 447e407e..ab0aef36 100644 --- a/man/man3/tomo-Path.write.3 +++ b/man/man3/tomo-Path.write.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.write 3 2025-05-17 "Tomo man-pages" +.TH Path.write 3 2025-11-09 "Tomo man-pages" .SH NAME Path.write \- write to a file .SH LIBRARY diff --git a/man/man3/tomo-Path.write_bytes.3 b/man/man3/tomo-Path.write_bytes.3 index d914378f..b3ea648b 100644 --- a/man/man3/tomo-Path.write_bytes.3 +++ b/man/man3/tomo-Path.write_bytes.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.write_bytes 3 2025-05-17 "Tomo man-pages" +.TH Path.write_bytes 3 2025-11-09 "Tomo man-pages" .SH NAME Path.write_bytes \- write bytes to a file .SH LIBRARY diff --git a/man/man3/tomo-Path.write_unique.3 b/man/man3/tomo-Path.write_unique.3 index 94f3cd6f..400f4097 100644 --- a/man/man3/tomo-Path.write_unique.3 +++ b/man/man3/tomo-Path.write_unique.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.write_unique 3 2025-09-21 "Tomo man-pages" +.TH Path.write_unique 3 2025-11-09 "Tomo man-pages" .SH NAME Path.write_unique \- write to a uniquely named file .SH LIBRARY diff --git a/man/man3/tomo-Path.write_unique_bytes.3 b/man/man3/tomo-Path.write_unique_bytes.3 index f4a82e63..53cb7bfd 100644 --- a/man/man3/tomo-Path.write_unique_bytes.3 +++ b/man/man3/tomo-Path.write_unique_bytes.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Path.write_unique_bytes 3 2025-09-21 "Tomo man-pages" +.TH Path.write_unique_bytes 3 2025-11-09 "Tomo man-pages" .SH NAME Path.write_unique_bytes \- write bytes to a uniquely named file .SH LIBRARY diff --git a/man/man3/tomo-Table.clear.3 b/man/man3/tomo-Table.clear.3 index 5b1be29e..be91c5ce 100644 --- a/man/man3/tomo-Table.clear.3 +++ b/man/man3/tomo-Table.clear.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.clear 3 2025-09-21 "Tomo man-pages" +.TH Table.clear 3 2025-11-09 "Tomo man-pages" .SH NAME Table.clear \- clear a table .SH LIBRARY diff --git a/man/man3/tomo-Table.difference.3 b/man/man3/tomo-Table.difference.3 index 8f123834..b216b283 100644 --- a/man/man3/tomo-Table.difference.3 +++ b/man/man3/tomo-Table.difference.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.difference 3 2025-09-21 "Tomo man-pages" +.TH Table.difference 3 2025-11-09 "Tomo man-pages" .SH NAME Table.difference \- return a table using keys not present in both tables .SH LIBRARY diff --git a/man/man3/tomo-Table.get.3 b/man/man3/tomo-Table.get.3 index ede699cf..ce0b1f95 100644 --- a/man/man3/tomo-Table.get.3 +++ b/man/man3/tomo-Table.get.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.get 3 2025-09-21 "Tomo man-pages" +.TH Table.get 3 2025-11-09 "Tomo man-pages" .SH NAME Table.get \- get an item from a table .SH LIBRARY diff --git a/man/man3/tomo-Table.get_or_set.3 b/man/man3/tomo-Table.get_or_set.3 index 38e73a4b..69d5a236 100644 --- a/man/man3/tomo-Table.get_or_set.3 +++ b/man/man3/tomo-Table.get_or_set.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.get_or_set 3 2025-09-21 "Tomo man-pages" +.TH Table.get_or_set 3 2025-11-09 "Tomo man-pages" .SH NAME Table.get_or_set \- get an item or set a default if absent .SH LIBRARY diff --git a/man/man3/tomo-Table.has.3 b/man/man3/tomo-Table.has.3 index b2efffd6..c4b4a09b 100644 --- a/man/man3/tomo-Table.has.3 +++ b/man/man3/tomo-Table.has.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.has 3 2025-09-21 "Tomo man-pages" +.TH Table.has 3 2025-11-09 "Tomo man-pages" .SH NAME Table.has \- check for a key .SH LIBRARY diff --git a/man/man3/tomo-Table.intersection.3 b/man/man3/tomo-Table.intersection.3 index 64a2e32c..c01f4336 100644 --- a/man/man3/tomo-Table.intersection.3 +++ b/man/man3/tomo-Table.intersection.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.intersection 3 2025-09-21 "Tomo man-pages" +.TH Table.intersection 3 2025-11-09 "Tomo man-pages" .SH NAME Table.intersection \- return a table with common key/value pairs from two tables .SH LIBRARY diff --git a/man/man3/tomo-Table.remove.3 b/man/man3/tomo-Table.remove.3 index ce6010b3..07fd042d 100644 --- a/man/man3/tomo-Table.remove.3 +++ b/man/man3/tomo-Table.remove.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.remove 3 2025-09-21 "Tomo man-pages" +.TH Table.remove 3 2025-11-09 "Tomo man-pages" .SH NAME Table.remove \- remove a table entry .SH LIBRARY diff --git a/man/man3/tomo-Table.set.3 b/man/man3/tomo-Table.set.3 index f1303189..bf8c39cd 100644 --- a/man/man3/tomo-Table.set.3 +++ b/man/man3/tomo-Table.set.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.set 3 2025-09-21 "Tomo man-pages" +.TH Table.set 3 2025-11-09 "Tomo man-pages" .SH NAME Table.set \- set a table entry .SH LIBRARY diff --git a/man/man3/tomo-Table.with.3 b/man/man3/tomo-Table.with.3 index 988fb888..d9a70f97 100644 --- a/man/man3/tomo-Table.with.3 +++ b/man/man3/tomo-Table.with.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.with 3 2025-09-21 "Tomo man-pages" +.TH Table.with 3 2025-11-09 "Tomo man-pages" .SH NAME Table.with \- return a table with values added from another table .SH LIBRARY diff --git a/man/man3/tomo-Table.with_fallback.3 b/man/man3/tomo-Table.with_fallback.3 index c0719bd3..ea8f7979 100644 --- a/man/man3/tomo-Table.with_fallback.3 +++ b/man/man3/tomo-Table.with_fallback.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.with_fallback 3 2025-09-21 "Tomo man-pages" +.TH Table.with_fallback 3 2025-11-09 "Tomo man-pages" .SH NAME Table.with_fallback \- return a table with a new fallback .SH LIBRARY diff --git a/man/man3/tomo-Table.without.3 b/man/man3/tomo-Table.without.3 index 7244dac6..c9d1b0e9 100644 --- a/man/man3/tomo-Table.without.3 +++ b/man/man3/tomo-Table.without.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Table.without 3 2025-09-21 "Tomo man-pages" +.TH Table.without 3 2025-11-09 "Tomo man-pages" .SH NAME Table.without \- return a table without key/value pairs in another table .SH LIBRARY diff --git a/man/man3/tomo-Text.as_c_string.3 b/man/man3/tomo-Text.as_c_string.3 index ef49eeb7..fec6a393 100644 --- a/man/man3/tomo-Text.as_c_string.3 +++ b/man/man3/tomo-Text.as_c_string.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.as_c_string 3 2025-09-21 "Tomo man-pages" +.TH Text.as_c_string 3 2025-11-09 "Tomo man-pages" .SH NAME Text.as_c_string \- convert to C-style string .SH LIBRARY diff --git a/man/man3/tomo-Text.at.3 b/man/man3/tomo-Text.at.3 index 2d46c256..1908f6c0 100644 --- a/man/man3/tomo-Text.at.3 +++ b/man/man3/tomo-Text.at.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.at 3 2025-09-21 "Tomo man-pages" +.TH Text.at 3 2025-11-09 "Tomo man-pages" .SH NAME Text.at \- get a letter .SH LIBRARY diff --git a/man/man3/tomo-Text.by_line.3 b/man/man3/tomo-Text.by_line.3 index 6f28263b..6f996ed1 100644 --- a/man/man3/tomo-Text.by_line.3 +++ b/man/man3/tomo-Text.by_line.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.by_line 3 2025-04-30 "Tomo man-pages" +.TH Text.by_line 3 2025-11-09 "Tomo man-pages" .SH NAME Text.by_line \- iterate by line .SH LIBRARY diff --git a/man/man3/tomo-Text.by_split.3 b/man/man3/tomo-Text.by_split.3 index 3acef72e..188c3592 100644 --- a/man/man3/tomo-Text.by_split.3 +++ b/man/man3/tomo-Text.by_split.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.by_split 3 2025-04-30 "Tomo man-pages" +.TH Text.by_split 3 2025-11-09 "Tomo man-pages" .SH NAME Text.by_split \- iterate by a spliting text .SH LIBRARY diff --git a/man/man3/tomo-Text.by_split_any.3 b/man/man3/tomo-Text.by_split_any.3 index c8616c82..dfce89a7 100644 --- a/man/man3/tomo-Text.by_split_any.3 +++ b/man/man3/tomo-Text.by_split_any.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.by_split_any 3 2025-04-30 "Tomo man-pages" +.TH Text.by_split_any 3 2025-11-09 "Tomo man-pages" .SH NAME Text.by_split_any \- iterate by one of many splitting characters .SH LIBRARY diff --git a/man/man3/tomo-Text.caseless_equals.3 b/man/man3/tomo-Text.caseless_equals.3 index 1470c4db..1818851c 100644 --- a/man/man3/tomo-Text.caseless_equals.3 +++ b/man/man3/tomo-Text.caseless_equals.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.caseless_equals 3 2025-09-21 "Tomo man-pages" +.TH Text.caseless_equals 3 2025-11-09 "Tomo man-pages" .SH NAME Text.caseless_equals \- case-insensitive comparison .SH LIBRARY diff --git a/man/man3/tomo-Text.codepoint_names.3 b/man/man3/tomo-Text.codepoint_names.3 index 61a4c9a5..80ac3d6f 100644 --- a/man/man3/tomo-Text.codepoint_names.3 +++ b/man/man3/tomo-Text.codepoint_names.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.codepoint_names 3 2025-09-21 "Tomo man-pages" +.TH Text.codepoint_names 3 2025-11-09 "Tomo man-pages" .SH NAME Text.codepoint_names \- get unicode codepoint names .SH LIBRARY diff --git a/man/man3/tomo-Text.ends_with.3 b/man/man3/tomo-Text.ends_with.3 index 7b5ff696..aa34489a 100644 --- a/man/man3/tomo-Text.ends_with.3 +++ b/man/man3/tomo-Text.ends_with.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.ends_with 3 2025-09-21 "Tomo man-pages" +.TH Text.ends_with 3 2025-11-09 "Tomo man-pages" .SH NAME Text.ends_with \- check suffix .SH LIBRARY diff --git a/man/man3/tomo-Text.from.3 b/man/man3/tomo-Text.from.3 index 6132c572..2d15ac55 100644 --- a/man/man3/tomo-Text.from.3 +++ b/man/man3/tomo-Text.from.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from 3 2025-09-21 "Tomo man-pages" +.TH Text.from 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from \- slice from a starting index .SH LIBRARY diff --git a/man/man3/tomo-Text.from_c_string.3 b/man/man3/tomo-Text.from_c_string.3 index 98b153d8..18a7c576 100644 --- a/man/man3/tomo-Text.from_c_string.3 +++ b/man/man3/tomo-Text.from_c_string.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from_c_string 3 2025-09-21 "Tomo man-pages" +.TH Text.from_c_string 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from_c_string \- convert C-style string to text .SH LIBRARY diff --git a/man/man3/tomo-Text.from_codepoint_names.3 b/man/man3/tomo-Text.from_codepoint_names.3 index 4a1f9f56..464e87e6 100644 --- a/man/man3/tomo-Text.from_codepoint_names.3 +++ b/man/man3/tomo-Text.from_codepoint_names.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from_codepoint_names 3 2025-10-11 "Tomo man-pages" +.TH Text.from_codepoint_names 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from_codepoint_names \- convert list of unicode codepoint names to text .SH LIBRARY diff --git a/man/man3/tomo-Text.from_utf16.3 b/man/man3/tomo-Text.from_utf16.3 index 6668baf0..6e52230e 100644 --- a/man/man3/tomo-Text.from_utf16.3 +++ b/man/man3/tomo-Text.from_utf16.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from_utf16 3 2025-09-21 "Tomo man-pages" +.TH Text.from_utf16 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from_utf16 \- convert UTF16 list to text .SH LIBRARY diff --git a/man/man3/tomo-Text.from_utf32.3 b/man/man3/tomo-Text.from_utf32.3 index d93ad2c9..1f1689a6 100644 --- a/man/man3/tomo-Text.from_utf32.3 +++ b/man/man3/tomo-Text.from_utf32.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from_utf32 3 2025-09-21 "Tomo man-pages" +.TH Text.from_utf32 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from_utf32 \- convert UTF32 codepoints to text .SH LIBRARY diff --git a/man/man3/tomo-Text.from_utf8.3 b/man/man3/tomo-Text.from_utf8.3 index ec5261ec..9cd848bc 100644 --- a/man/man3/tomo-Text.from_utf8.3 +++ b/man/man3/tomo-Text.from_utf8.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.from_utf8 3 2025-09-21 "Tomo man-pages" +.TH Text.from_utf8 3 2025-11-09 "Tomo man-pages" .SH NAME Text.from_utf8 \- convert UTF8 byte list to text .SH LIBRARY diff --git a/man/man3/tomo-Text.has.3 b/man/man3/tomo-Text.has.3 index 75b6b0c9..7e56020b 100644 --- a/man/man3/tomo-Text.has.3 +++ b/man/man3/tomo-Text.has.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.has 3 2025-09-21 "Tomo man-pages" +.TH Text.has 3 2025-11-09 "Tomo man-pages" .SH NAME Text.has \- check for substring .SH LIBRARY diff --git a/man/man3/tomo-Text.join.3 b/man/man3/tomo-Text.join.3 index b736f721..699765f3 100644 --- a/man/man3/tomo-Text.join.3 +++ b/man/man3/tomo-Text.join.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.join 3 2025-09-21 "Tomo man-pages" +.TH Text.join 3 2025-11-09 "Tomo man-pages" .SH NAME Text.join \- concatenate with separator .SH LIBRARY diff --git a/man/man3/tomo-Text.left_pad.3 b/man/man3/tomo-Text.left_pad.3 index e79e4ad6..30150211 100644 --- a/man/man3/tomo-Text.left_pad.3 +++ b/man/man3/tomo-Text.left_pad.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.left_pad 3 2025-09-21 "Tomo man-pages" +.TH Text.left_pad 3 2025-11-09 "Tomo man-pages" .SH NAME Text.left_pad \- left-pad text .SH LIBRARY diff --git a/man/man3/tomo-Text.lines.3 b/man/man3/tomo-Text.lines.3 index 60aa4430..a2397c40 100644 --- a/man/man3/tomo-Text.lines.3 +++ b/man/man3/tomo-Text.lines.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.lines 3 2025-09-21 "Tomo man-pages" +.TH Text.lines 3 2025-11-09 "Tomo man-pages" .SH NAME Text.lines \- get list of lines .SH LIBRARY diff --git a/man/man3/tomo-Text.lower.3 b/man/man3/tomo-Text.lower.3 index 877227e7..eae3cebe 100644 --- a/man/man3/tomo-Text.lower.3 +++ b/man/man3/tomo-Text.lower.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.lower 3 2025-09-21 "Tomo man-pages" +.TH Text.lower 3 2025-11-09 "Tomo man-pages" .SH NAME Text.lower \- convert to lowercase .SH LIBRARY diff --git a/man/man3/tomo-Text.middle_pad.3 b/man/man3/tomo-Text.middle_pad.3 index 8b57bf6e..a9358619 100644 --- a/man/man3/tomo-Text.middle_pad.3 +++ b/man/man3/tomo-Text.middle_pad.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.middle_pad 3 2025-09-21 "Tomo man-pages" +.TH Text.middle_pad 3 2025-11-09 "Tomo man-pages" .SH NAME Text.middle_pad \- pad text, centered .SH LIBRARY diff --git a/man/man3/tomo-Text.quoted.3 b/man/man3/tomo-Text.quoted.3 index 8f6824fd..5142eef8 100644 --- a/man/man3/tomo-Text.quoted.3 +++ b/man/man3/tomo-Text.quoted.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.quoted 3 2025-09-21 "Tomo man-pages" +.TH Text.quoted 3 2025-11-09 "Tomo man-pages" .SH NAME Text.quoted \- add quotation marks and escapes .SH LIBRARY diff --git a/man/man3/tomo-Text.repeat.3 b/man/man3/tomo-Text.repeat.3 index fdc9561f..3bfcce74 100644 --- a/man/man3/tomo-Text.repeat.3 +++ b/man/man3/tomo-Text.repeat.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.repeat 3 2025-09-21 "Tomo man-pages" +.TH Text.repeat 3 2025-11-09 "Tomo man-pages" .SH NAME Text.repeat \- repeat text .SH LIBRARY diff --git a/man/man3/tomo-Text.replace.3 b/man/man3/tomo-Text.replace.3 index 7a272106..16c7756b 100644 --- a/man/man3/tomo-Text.replace.3 +++ b/man/man3/tomo-Text.replace.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.replace 3 2025-09-21 "Tomo man-pages" +.TH Text.replace 3 2025-11-09 "Tomo man-pages" .SH NAME Text.replace \- replace a substring .SH LIBRARY diff --git a/man/man3/tomo-Text.reversed.3 b/man/man3/tomo-Text.reversed.3 index 51b37acb..6f06d4e6 100644 --- a/man/man3/tomo-Text.reversed.3 +++ b/man/man3/tomo-Text.reversed.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.reversed 3 2025-09-21 "Tomo man-pages" +.TH Text.reversed 3 2025-11-09 "Tomo man-pages" .SH NAME Text.reversed \- get a reversed copy .SH LIBRARY diff --git a/man/man3/tomo-Text.right_pad.3 b/man/man3/tomo-Text.right_pad.3 index 0fb128cb..4c1a1efb 100644 --- a/man/man3/tomo-Text.right_pad.3 +++ b/man/man3/tomo-Text.right_pad.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.right_pad 3 2025-09-21 "Tomo man-pages" +.TH Text.right_pad 3 2025-11-09 "Tomo man-pages" .SH NAME Text.right_pad \- right-pad text .SH LIBRARY diff --git a/man/man3/tomo-Text.slice.3 b/man/man3/tomo-Text.slice.3 index 48e0516a..f974e2af 100644 --- a/man/man3/tomo-Text.slice.3 +++ b/man/man3/tomo-Text.slice.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.slice 3 2025-09-21 "Tomo man-pages" +.TH Text.slice 3 2025-11-09 "Tomo man-pages" .SH NAME Text.slice \- get a slice of a text .SH LIBRARY diff --git a/man/man3/tomo-Text.split.3 b/man/man3/tomo-Text.split.3 index 8634c509..b80023a0 100644 --- a/man/man3/tomo-Text.split.3 +++ b/man/man3/tomo-Text.split.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.split 3 2025-09-21 "Tomo man-pages" +.TH Text.split 3 2025-11-09 "Tomo man-pages" .SH NAME Text.split \- split a text by a delimiter .SH LIBRARY diff --git a/man/man3/tomo-Text.split_any.3 b/man/man3/tomo-Text.split_any.3 index 6c77d8d6..28eb7783 100644 --- a/man/man3/tomo-Text.split_any.3 +++ b/man/man3/tomo-Text.split_any.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.split_any 3 2025-09-21 "Tomo man-pages" +.TH Text.split_any 3 2025-11-09 "Tomo man-pages" .SH NAME Text.split_any \- split a text by multiple delimiters .SH LIBRARY diff --git a/man/man3/tomo-Text.starts_with.3 b/man/man3/tomo-Text.starts_with.3 index ac35fa8d..5de9a947 100644 --- a/man/man3/tomo-Text.starts_with.3 +++ b/man/man3/tomo-Text.starts_with.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.starts_with 3 2025-09-21 "Tomo man-pages" +.TH Text.starts_with 3 2025-11-09 "Tomo man-pages" .SH NAME Text.starts_with \- check prefix .SH LIBRARY diff --git a/man/man3/tomo-Text.title.3 b/man/man3/tomo-Text.title.3 index d1b3e962..bf4e768d 100644 --- a/man/man3/tomo-Text.title.3 +++ b/man/man3/tomo-Text.title.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.title 3 2025-09-21 "Tomo man-pages" +.TH Text.title 3 2025-11-09 "Tomo man-pages" .SH NAME Text.title \- titlecase .SH LIBRARY diff --git a/man/man3/tomo-Text.to.3 b/man/man3/tomo-Text.to.3 index 4de082d3..7ca58bfa 100644 --- a/man/man3/tomo-Text.to.3 +++ b/man/man3/tomo-Text.to.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.to 3 2025-09-21 "Tomo man-pages" +.TH Text.to 3 2025-11-09 "Tomo man-pages" .SH NAME Text.to \- slice to an end index .SH LIBRARY diff --git a/man/man3/tomo-Text.translate.3 b/man/man3/tomo-Text.translate.3 index 8cfeb3f7..e436a2ee 100644 --- a/man/man3/tomo-Text.translate.3 +++ b/man/man3/tomo-Text.translate.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.translate 3 2025-10-11 "Tomo man-pages" +.TH Text.translate 3 2025-11-09 "Tomo man-pages" .SH NAME Text.translate \- perform multiple replacements .SH LIBRARY diff --git a/man/man3/tomo-Text.trim.3 b/man/man3/tomo-Text.trim.3 index b7daa310..fae9f3a5 100644 --- a/man/man3/tomo-Text.trim.3 +++ b/man/man3/tomo-Text.trim.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.trim 3 2025-09-21 "Tomo man-pages" +.TH Text.trim 3 2025-11-09 "Tomo man-pages" .SH NAME Text.trim \- trim characters .SH LIBRARY diff --git a/man/man3/tomo-Text.upper.3 b/man/man3/tomo-Text.upper.3 index dc10ff21..6ac7e072 100644 --- a/man/man3/tomo-Text.upper.3 +++ b/man/man3/tomo-Text.upper.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.upper 3 2025-09-21 "Tomo man-pages" +.TH Text.upper 3 2025-11-09 "Tomo man-pages" .SH NAME Text.upper \- uppercase .SH LIBRARY diff --git a/man/man3/tomo-Text.utf16.3 b/man/man3/tomo-Text.utf16.3 index 2d5d0817..b8696254 100644 --- a/man/man3/tomo-Text.utf16.3 +++ b/man/man3/tomo-Text.utf16.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.utf16 3 2025-09-21 "Tomo man-pages" +.TH Text.utf16 3 2025-11-09 "Tomo man-pages" .SH NAME Text.utf16 \- get UTF16 codepoints .SH LIBRARY diff --git a/man/man3/tomo-Text.utf32.3 b/man/man3/tomo-Text.utf32.3 index a74b04d2..276e8dad 100644 --- a/man/man3/tomo-Text.utf32.3 +++ b/man/man3/tomo-Text.utf32.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.utf32 3 2025-09-21 "Tomo man-pages" +.TH Text.utf32 3 2025-11-09 "Tomo man-pages" .SH NAME Text.utf32 \- get UTF32 codepoints .SH LIBRARY diff --git a/man/man3/tomo-Text.utf8.3 b/man/man3/tomo-Text.utf8.3 index e64bbaf1..8ace9dfb 100644 --- a/man/man3/tomo-Text.utf8.3 +++ b/man/man3/tomo-Text.utf8.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.utf8 3 2025-09-21 "Tomo man-pages" +.TH Text.utf8 3 2025-11-09 "Tomo man-pages" .SH NAME Text.utf8 \- get UTF8 bytes .SH LIBRARY diff --git a/man/man3/tomo-Text.width.3 b/man/man3/tomo-Text.width.3 index 7118c9bb..17666301 100644 --- a/man/man3/tomo-Text.width.3 +++ b/man/man3/tomo-Text.width.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.width 3 2025-09-21 "Tomo man-pages" +.TH Text.width 3 2025-11-09 "Tomo man-pages" .SH NAME Text.width \- get display width .SH LIBRARY diff --git a/man/man3/tomo-Text.without_prefix.3 b/man/man3/tomo-Text.without_prefix.3 index 12479791..5c12c4e8 100644 --- a/man/man3/tomo-Text.without_prefix.3 +++ b/man/man3/tomo-Text.without_prefix.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.without_prefix 3 2025-09-21 "Tomo man-pages" +.TH Text.without_prefix 3 2025-11-09 "Tomo man-pages" .SH NAME Text.without_prefix \- remove prefix .SH LIBRARY diff --git a/man/man3/tomo-Text.without_suffix.3 b/man/man3/tomo-Text.without_suffix.3 index 45d818a7..08053ab0 100644 --- a/man/man3/tomo-Text.without_suffix.3 +++ b/man/man3/tomo-Text.without_suffix.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH Text.without_suffix 3 2025-09-21 "Tomo man-pages" +.TH Text.without_suffix 3 2025-11-09 "Tomo man-pages" .SH NAME Text.without_suffix \- remove suffix .SH LIBRARY diff --git a/man/man3/tomo-USE_COLOR.3 b/man/man3/tomo-USE_COLOR.3 index 3b48329d..168c3c06 100644 --- a/man/man3/tomo-USE_COLOR.3 +++ b/man/man3/tomo-USE_COLOR.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH USE_COLOR 3 2025-05-17 "Tomo man-pages" +.TH USE_COLOR 3 2025-11-09 "Tomo man-pages" .SH NAME USE_COLOR \- whether to use colors .SH LIBRARY diff --git a/man/man3/tomo-ask.3 b/man/man3/tomo-ask.3 index 684efd63..7eed621d 100644 --- a/man/man3/tomo-ask.3 +++ b/man/man3/tomo-ask.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH ask 3 2025-09-21 "Tomo man-pages" +.TH ask 3 2025-11-09 "Tomo man-pages" .SH NAME ask \- get user input .SH LIBRARY diff --git a/man/man3/tomo-exit.3 b/man/man3/tomo-exit.3 index 48e0bd79..cb1ee064 100644 --- a/man/man3/tomo-exit.3 +++ b/man/man3/tomo-exit.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH exit 3 2025-05-17 "Tomo man-pages" +.TH exit 3 2025-11-09 "Tomo man-pages" .SH NAME exit \- exit the program .SH LIBRARY diff --git a/man/man3/tomo-fail.3 b/man/man3/tomo-fail.3 index ed969cc4..14fa0cf8 100644 --- a/man/man3/tomo-fail.3 +++ b/man/man3/tomo-fail.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH fail 3 2025-05-17 "Tomo man-pages" +.TH fail 3 2025-11-09 "Tomo man-pages" .SH NAME fail \- abort the program .SH LIBRARY diff --git a/man/man3/tomo-getenv.3 b/man/man3/tomo-getenv.3 index 84bef6be..1fa1f1e7 100644 --- a/man/man3/tomo-getenv.3 +++ b/man/man3/tomo-getenv.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH getenv 3 2025-10-11 "Tomo man-pages" +.TH getenv 3 2025-11-09 "Tomo man-pages" .SH NAME getenv \- get an environment variable .SH LIBRARY diff --git a/man/man3/tomo-print.3 b/man/man3/tomo-print.3 index ccb9863e..68ac5060 100644 --- a/man/man3/tomo-print.3 +++ b/man/man3/tomo-print.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH print 3 2025-05-17 "Tomo man-pages" +.TH print 3 2025-11-09 "Tomo man-pages" .SH NAME print \- print some text .SH LIBRARY diff --git a/man/man3/tomo-say.3 b/man/man3/tomo-say.3 index 4e9bfeb4..d6b7202f 100644 --- a/man/man3/tomo-say.3 +++ b/man/man3/tomo-say.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH say 3 2025-05-17 "Tomo man-pages" +.TH say 3 2025-11-09 "Tomo man-pages" .SH NAME say \- print some text .SH LIBRARY diff --git a/man/man3/tomo-setenv.3 b/man/man3/tomo-setenv.3 index a9ed528d..4e0c5ca3 100644 --- a/man/man3/tomo-setenv.3 +++ b/man/man3/tomo-setenv.3 @@ -2,7 +2,7 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH setenv 3 2025-05-17 "Tomo man-pages" +.TH setenv 3 2025-11-09 "Tomo man-pages" .SH NAME setenv \- set an environment variable .SH LIBRARY diff --git a/man/man3/tomo-sleep.3 b/man/man3/tomo-sleep.3 index efe73c14..783e0aee 100644 --- a/man/man3/tomo-sleep.3 +++ b/man/man3/tomo-sleep.3 @@ -2,14 +2,14 @@ .\" Copyright (c) 2025 Bruce Hill .\" All rights reserved. .\" -.TH sleep 3 2025-05-17 "Tomo man-pages" +.TH sleep 3 2025-11-09 "Tomo man-pages" .SH NAME sleep \- wait for an interval .SH LIBRARY Tomo Standard Library .SH SYNOPSIS .nf -.BI sleep\ :\ func(seconds:\ Num\ ->\ Void) +.BI sleep\ :\ func(seconds:\ Float64\ ->\ Void) .fi .SH DESCRIPTION Pause execution for a given number of seconds. @@ -22,7 +22,7 @@ allbox; lb lb lbx lb l l l l. Name Type Description Default -seconds Num How many seconds to sleep for. - +seconds Float64 How many seconds to sleep for. - .TE .SH RETURN Nothing. diff --git a/src/compile/assignments.c b/src/compile/assignments.c index c0f45f5b..84c43153 100644 --- a/src/compile/assignments.c +++ b/src/compile/assignments.c @@ -22,22 +22,22 @@ Text_t compile_update_assignment(env_t *env, ast_t *ast) { Text_t update_assignment = EMPTY_TEXT; switch (ast->tag) { case PlusUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " += ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case MinusUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " -= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case MultiplyUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " *= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } case DivideUpdate: { - if (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType) + if (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType) update_assignment = Texts(lhs, " /= ", compile_to_type(env, update.rhs, lhs_t), ";"); break; } diff --git a/src/compile/binops.c b/src/compile/binops.c index acf1e031..a84e34ba 100644 --- a/src/compile/binops.c +++ b/src/compile/binops.c @@ -113,14 +113,15 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { switch (ast->tag) { case Power: { - if (overall_t->tag != NumType) - code_err(ast, "Exponentiation is only supported for Num types, not ", type_to_text(overall_t)); - if (overall_t->tag == NumType && Match(overall_t, NumType)->bits == TYPE_NBITS32) + if (overall_t->tag != FloatType) + code_err(ast, "Exponentiation is only supported for floating point number types, not ", + type_to_text(overall_t)); + if (overall_t->tag == FloatType && Match(overall_t, FloatType)->bits == TYPE_NBITS32) return Texts("powf(", lhs, ", ", rhs, ")"); else return Texts("pow(", lhs, ", ", rhs, ")"); } case Multiply: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -128,7 +129,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " * ", rhs, ")"); } case Divide: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -136,7 +137,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " / ", rhs, ")"); } case Mod: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -144,7 +145,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " % ", rhs, ")"); } case Mod1: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -152,7 +153,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("((((", lhs, ")-1) % (", rhs, ")) + 1)"); } case Plus: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -160,7 +161,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " + ", rhs, ")"); } case Minus: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -168,7 +169,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " - ", rhs, ")"); } case LeftShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -176,7 +177,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " << ", rhs, ")"); } case RightShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -184,7 +185,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", lhs, " >> ", rhs, ")"); } case UnsignedLeftShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", @@ -192,7 +193,7 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) { return Texts("(", compile_type(overall_t), ")((", compile_unsigned_type(lhs_t), ")", lhs, " << ", rhs, ")"); } case UnsignedRightShift: { - if (overall_t->tag != IntType && overall_t->tag != NumType && overall_t->tag != ByteType) + if (overall_t->tag != IntType && overall_t->tag != FloatType && overall_t->tag != ByteType) code_err(ast, "Math operations are only supported for values of the same " "numeric type, not ", diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c index ffa04b9d..bc927599 100644 --- a/src/compile/comparisons.c +++ b/src/compile/comparisons.c @@ -50,7 +50,7 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { case BoolType: case ByteType: case IntType: - case NumType: + case FloatType: case PointerType: case FunctionType: return Texts("(", lhs, ast->tag == Equals ? " == " : " != ", rhs, ")"); default: @@ -92,7 +92,7 @@ Text_t compile_comparison(env_t *env, ast_t *ast) { case BoolType: case ByteType: case IntType: - case NumType: + case FloatType: case PointerType: case FunctionType: return Texts("(", lhs, " ", op, " ", rhs, ")"); default: diff --git a/src/compile/expressions.c b/src/compile/expressions.c index 108bda80..ce44dafc 100644 --- a/src/compile/expressions.c +++ b/src/compile/expressions.c @@ -53,8 +53,8 @@ Text_t compile_empty(type_t *t) { return empty_pointed.length == 0 ? EMPTY_TEXT : Texts(ptr->is_stack ? Text("stack(") : Text("heap("), empty_pointed, ")"); } - case NumType: { - return Match(t, NumType)->bits == TYPE_NBITS32 ? Text("N32(0.0f)") : Text("N64(0.0)"); + case FloatType: { + return Match(t, FloatType)->bits == TYPE_NBITS32 ? Text("F32(0.0f)") : Text("F64(0.0)"); } case StructType: return compile_empty_struct(t); case EnumType: return compile_empty_enum(t); @@ -109,7 +109,7 @@ Text_t compile(env_t *env, ast_t *ast) { return Texts(b->code, "(", compile_arguments(env, ast, fn->args, new (arg_ast_t, .value = value)), ")"); } - if (t->tag == IntType || t->tag == NumType) return Texts("-(", compile(env, value), ")"); + if (t->tag == IntType || t->tag == FloatType) return Texts("-(", compile(env, value), ")"); code_err(ast, "I don't know how to get the negative value of type ", type_to_text(t)); } @@ -165,7 +165,7 @@ Text_t compile(env_t *env, ast_t *ast) { if (key_t->tag == BigIntType) comparison = Texts("(Int$compare_value(", lhs_key, ", ", rhs_key, ")", (ast->tag == Min ? "<=" : ">="), "0)"); - else if (key_t->tag == IntType || key_t->tag == NumType || key_t->tag == BoolType || key_t->tag == PointerType + else if (key_t->tag == IntType || key_t->tag == FloatType || key_t->tag == BoolType || key_t->tag == PointerType || key_t->tag == ByteType) comparison = Texts("((", lhs_key, ")", (ast->tag == Min ? "<=" : ">="), "(", rhs_key, "))"); else diff --git a/src/compile/functions.c b/src/compile/functions.c index 4a2812ba..a14c0455 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -4,8 +4,8 @@ #include "../environment.h" #include "../naming.h" #include "../stdlib/datatypes.h" +#include "../stdlib/floats.h" #include "../stdlib/integers.h" -#include "../stdlib/nums.h" #include "../stdlib/tables.h" #include "../stdlib/text.h" #include "../stdlib/util.h" @@ -79,12 +79,12 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ Text_t value; if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) { + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Int) { OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Int)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); - if (Match(spec_arg->type, NumType)->bits == TYPE_NBITS64) - value = Text$from_str(String(hex_double(Num$from_int(int_val, false)))); - else value = Text$from_str(String(hex_double((double)Num32$from_int(int_val, false)), "f")); + if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) + value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); + else value = Text$from_str(String(hex_double((double)Float32$from_int(int_val, false)), "f")); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); value = compile_maybe_incref(arg_env, call_arg->value, spec_arg->type); @@ -103,12 +103,12 @@ Text_t compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_ Text_t value; if (spec_arg->type->tag == IntType && call_arg->value->tag == Int) { value = compile_int_to_type(env, call_arg->value, spec_arg->type); - } else if (spec_arg->type->tag == NumType && call_arg->value->tag == Int) { + } else if (spec_arg->type->tag == FloatType && call_arg->value->tag == Int) { OptionalInt_t int_val = Int$from_str(Match(call_arg->value, Int)->str); if (int_val.small == 0) code_err(call_arg->value, "Failed to parse this integer"); - if (Match(spec_arg->type, NumType)->bits == TYPE_NBITS64) - value = Text$from_str(String(hex_double(Num$from_int(int_val, false)))); - else value = Text$from_str(String(hex_double((double)Num32$from_int(int_val, false)), "f")); + if (Match(spec_arg->type, FloatType)->bits == TYPE_NBITS64) + value = Text$from_str(String(hex_double(Float64$from_int(int_val, false)))); + else value = Text$from_str(String(hex_double((double)Float32$from_int(int_val, false)), "f")); } else { env_t *arg_env = with_enum_scope(env, spec_arg->type); value = compile_maybe_incref(arg_env, call_arg->value, spec_arg->type); @@ -179,7 +179,7 @@ Text_t compile_function_call(env_t *env, ast_t *ast) { // not go through any conversion, just a cast: if (is_numeric_type(t) && call->args && !call->args->next && call->args->value->tag == Int) return compile_to_type(env, call->args->value, t); - else if (t->tag == NumType && call->args && !call->args->next && call->args->value->tag == Num) + else if (t->tag == FloatType && call->args && !call->args->next && call->args->value->tag == Num) return compile_to_type(env, call->args->value, t); binding_t *constructor = diff --git a/src/compile/integers.c b/src/compile/integers.c index 78d48b70..219847cf 100644 --- a/src/compile/integers.c +++ b/src/compile/integers.c @@ -49,11 +49,11 @@ Text_t compile_int_to_type(env_t *env, ast_t *ast, type_t *target) { if (target->tag == ByteType) { if (mpz_cmp_si(i, UINT8_MAX) <= 0 && mpz_cmp_si(i, 0) >= 0) return Texts("(Byte_t)(", c_literal, ")"); code_err(ast, "This integer cannot fit in a byte"); - } else if (target->tag == NumType) { - if (Match(target, NumType)->bits == TYPE_NBITS64) { - return Texts("N64(", c_literal, ")"); + } else if (target->tag == FloatType) { + if (Match(target, FloatType)->bits == TYPE_NBITS64) { + return Texts("F64(", c_literal, ")"); } else { - return Texts("N32(", c_literal, ")"); + return Texts("F32(", c_literal, ")"); } } else if (target->tag == IntType) { int64_t target_bits = (int64_t)Match(target, IntType)->bits; diff --git a/src/compile/lists.c b/src/compile/lists.c index 54ad6e7f..1f3590a9 100644 --- a/src/compile/lists.c +++ b/src/compile/lists.c @@ -113,12 +113,12 @@ Text_t compile_list_method_call(env_t *env, ast_t *ast) { return Texts("List$has_value(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", compile_type_info(self_value_t), ")"); } else if (streq(call->name, "sample")) { - type_t *random_num_type = parse_type_string(env, "func(->Num)?"); + type_t *random_num_type = parse_type_string(env, "func(->Float64)?"); self = compile_to_pointer_depth(env, call->self, 0, false); arg_t *arg_spec = new (arg_t, .name = "count", .type = INT_TYPE, .next = new ( - arg_t, .name = "weights", .type = Type(ListType, .item_type = Type(NumType, .bits = TYPE_NBITS64)), + arg_t, .name = "weights", .type = Type(ListType, .item_type = Type(FloatType, .bits = TYPE_NBITS64)), .default_val = FakeAST(None), .next = new (arg_t, .name = "random", .type = random_num_type, .default_val = FakeAST(None)))); return Texts("List$sample(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", diff --git a/src/compile/optionals.c b/src/compile/optionals.c index b4930d02..7da50b0b 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -75,7 +75,7 @@ Text_t compile_none(type_t *t) { case CStringType: return Text("NULL"); case PointerType: return Texts("((", compile_type(t), ")NULL)"); case ClosureType: return Text("NONE_CLOSURE"); - case NumType: return Text("nan(\"none\")"); + case FloatType: return Text("nan(\"none\")"); case StructType: return Texts("((", compile_type(Type(OptionalType, .type = t)), "){.has_value=false})"); case EnumType: { env_t *enum_env = Match(t, EnumType)->env; @@ -96,8 +96,8 @@ Text_t check_none(type_t *t, Text_t value) { else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATHTYPE_NONE)"); else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)"); else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)"); - else if (t->tag == NumType) - return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")"); + else if (t->tag == FloatType) + return Texts(Match(t, FloatType)->bits == TYPE_NBITS64 ? "Float64$isnan(" : "Float32$isnan(", value, ")"); else if (t->tag == ListType) return Texts("((", value, ").data == NULL)"); else if (t->tag == TableType) return Texts("((", value, ").entries.data == NULL)"); else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)"); diff --git a/src/compile/promotions.c b/src/compile/promotions.c index b3cbb361..2a346668 100644 --- a/src/compile/promotions.c +++ b/src/compile/promotions.c @@ -56,7 +56,8 @@ bool promote(env_t *env, ast_t *ast, Text_t *code, type_t *actual, type_t *neede if (actual->tag == TextType && needed->tag == TextType && streq(Match(needed, TextType)->lang, "Text")) return true; // Automatic optional checking for nums: - if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType) { + if (needed->tag == FloatType && actual->tag == OptionalType + && Match(actual, OptionalType)->type->tag == FloatType) { int64_t line = get_line_number(ast->file, ast->start); *code = Texts("({ ", compile_declaration(actual, Text("opt")), " = ", *code, "; ", "if unlikely (", @@ -129,9 +130,9 @@ Text_t compile_to_type(env_t *env, ast_t *ast, type_t *t) { if (ast->tag == Int && is_numeric_type(non_optional(t))) { return compile_int_to_type(env, ast, t); - } else if (ast->tag == Num && t->tag == NumType) { + } else if (ast->tag == Num && t->tag == FloatType) { double n = Match(ast, Num)->n; - switch (Match(t, NumType)->bits) { + switch (Match(t, FloatType)->bits) { case TYPE_NBITS64: return Text$from_str(String(hex_double(n))); case TYPE_NBITS32: return Text$from_str(String(hex_double(n), "f")); default: code_err(ast, "This is not a valid number bit width"); diff --git a/src/compile/statements.c b/src/compile/statements.c index 0cd85b5d..f554263c 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -28,7 +28,7 @@ Text_t with_source_info(env_t *env, ast_t *ast, Text_t code) { static Text_t compile_simple_update_assignment(env_t *env, ast_t *ast, const char *op) { binary_operands_t update = BINARY_OPERANDS(ast); type_t *lhs_t = get_type(env, update.lhs); - if (is_idempotent(update.lhs) && (lhs_t->tag == IntType || lhs_t->tag == NumType || lhs_t->tag == ByteType)) + if (is_idempotent(update.lhs) && (lhs_t->tag == IntType || lhs_t->tag == FloatType || lhs_t->tag == ByteType)) return Texts(compile_lvalue(env, update.lhs), " ", op, "= ", compile_to_type(env, update.rhs, lhs_t), ";"); return compile_update_assignment(env, ast); } diff --git a/src/compile/text.c b/src/compile/text.c index 3a8a227c..25a6e9a7 100644 --- a/src/compile/text.c +++ b/src/compile/text.c @@ -24,7 +24,7 @@ Text_t expr_as_text(Text_t expr, type_t *t, Text_t color) { case BigIntType: case IntType: case ByteType: - case NumType: { + case FloatType: { Text_t name = type_to_text(t); return Texts(name, "$as_text(stack(", expr, "), ", color, ", &", name, "$info)"); } diff --git a/src/compile/types.c b/src/compile/types.c index 2b345b41..94da1c49 100644 --- a/src/compile/types.c +++ b/src/compile/types.c @@ -24,9 +24,7 @@ Text_t compile_type(type_t *t) { case CStringType: return Text("const char*"); case BigIntType: return Text("Int_t"); case IntType: return Texts("Int", (int32_t)Match(t, IntType)->bits, "_t"); - case NumType: - return Match(t, NumType)->bits == TYPE_NBITS64 ? Text("Num_t") - : Texts("Num", (int32_t)Match(t, NumType)->bits, "_t"); + case FloatType: return Texts("Float", (int32_t)Match(t, FloatType)->bits, "_t"); case TextType: { DeclareMatch(text, t, TextType); if (!text->lang || streq(text->lang, "Text")) return Text("Text_t"); @@ -66,7 +64,7 @@ Text_t compile_type(type_t *t) { case TextType: case IntType: case BigIntType: - case NumType: + case FloatType: case BoolType: case ByteType: case ListType: @@ -97,7 +95,7 @@ Text_t compile_type_info(type_t *t) { case ByteType: case IntType: case BigIntType: - case NumType: + case FloatType: case CStringType: return Texts("&", type_to_text(t), "$info"); case TextType: { DeclareMatch(text, t, TextType); diff --git a/src/environment.c b/src/environment.c index 96595ac7..7ab0d4fc 100644 --- a/src/environment.c +++ b/src/environment.c @@ -226,27 +226,27 @@ env_t *global_env(bool source_mapping) { {"unsigned_right_shifted", "Int8$unsigned_right_shifted", "func(x:Int8,y:Int8 -> Int8)"}, // {"wrapping_minus", "Int8$wrapping_minus", "func(x:Int8,y:Int8 -> Int8)"}, // {"wrapping_plus", "Int8$wrapping_plus", "func(x:Int8,y:Int8 -> Int8)"}, ), -#define C(name) {#name, "M_" #name, "Num"} -#define F(name) {#name, #name, "func(n:Num -> Num)"} -#define F_opt(name) {#name, #name, "func(n:Num -> Num?)"} -#define F2(name) {#name, #name, "func(x,y:Num -> Num)"} +#define C(name) {#name, "M_" #name, "Float64"} +#define F(name) {#name, #name, "func(n:Float64 -> Float64)"} +#define F_opt(name) {#name, #name, "func(n:Float64 -> Float64?)"} +#define F2(name) {#name, #name, "func(x,y:Float64 -> Float64)"} MAKE_TYPE( // - "Num", Type(NumType, .bits = TYPE_NBITS64), Text("Num_t"), Text("Num$info"), - {"near", "Num$near", "func(x,y:Num, ratio=1e-9, min_epsilon=1e-9 -> Bool)"}, // - {"clamped", "Num$clamped", "func(x,low,high:Num -> Num)"}, // - {"percent", "Num$percent", "func(n:Num,precision=0.01 -> Text)"}, // - {"with_precision", "Num$with_precision", "func(n:Num,precision:Num -> Num)"}, // - {"is_between", "Num$is_between", "func(x:Num,low:Num,high:Num -> Bool)"}, // - {"isinf", "Num$isinf", "func(n:Num -> Bool)"}, // - {"isfinite", "Num$isfinite", "func(n:Num -> Bool)"}, // - {"modulo", "Num$mod", "func(x,y:Num -> Num)"}, // - {"modulo1", "Num$mod1", "func(x,y:Num -> Num)"}, // + "Float64", Type(FloatType, .bits = TYPE_NBITS64), Text("Float64_t"), Text("Float64$info"), + {"near", "Float64$near", "func(x,y:Float64, ratio=1e-9, min_epsilon=1e-9 -> Bool)"}, // + {"clamped", "Float64$clamped", "func(x,low,high:Float64 -> Float64)"}, // + {"percent", "Float64$percent", "func(n:Float64,precision=0.01 -> Text)"}, // + {"with_precision", "Float64$with_precision", "func(n:Float64,precision:Float64 -> Float64)"}, // + {"is_between", "Float64$is_between", "func(x:Float64,low:Float64,high:Float64 -> Bool)"}, // + {"isinf", "Float64$isinf", "func(n:Float64 -> Bool)"}, // + {"isfinite", "Float64$isfinite", "func(n:Float64 -> Bool)"}, // + {"modulo", "Float64$mod", "func(x,y:Float64 -> Float64)"}, // + {"modulo1", "Float64$mod1", "func(x,y:Float64 -> Float64)"}, // C(2_SQRTPI), C(E), C(PI_2), C(2_PI), C(1_PI), C(LN10), C(LN2), C(LOG2E), C(PI), C(PI_4), C(SQRT2), - C(SQRT1_2), {"INF", "(Num_t)(INFINITY)", "Num"}, // - {"TAU", "(Num_t)(2.*M_PI)", "Num"}, // - {"mix", "Num$mix", "func(amount,x,y:Num -> Num)"}, // - {"parse", "Num$parse", "func(text:Text, remainder:&Text? = none -> Num?)"}, // - {"abs", "fabs", "func(n:Num -> Num)"}, // + C(SQRT1_2), {"INF", "(Float64_t)(INFINITY)", "Float64"}, // + {"TAU", "(Float64_t)(2.*M_PI)", "Float64"}, // + {"mix", "Float64$mix", "func(amount,x,y:Float64 -> Float64)"}, // + {"parse", "Float64$parse", "func(text:Text, remainder:&Text? = none -> Float64?)"}, // + {"abs", "fabs", "func(n:Float64 -> Float64)"}, // F_opt(acos), F_opt(acosh), F_opt(asin), F(asinh), F(atan), F_opt(atanh), F(cbrt), F(ceil), F_opt(cos), F(cosh), F(erf), F(erfc), F(exp), F(exp2), F(expm1), F(floor), F(j0), F(j1), F_opt(log), F_opt(log10), F_opt(log1p), F_opt(log2), F(logb), F(rint), F(round), F(significand), F_opt(sin), F(sinh), F_opt(sqrt), @@ -256,28 +256,28 @@ env_t *global_env(bool source_mapping) { #undef F_opt #undef F #undef C -#define C(name) {#name, "(Num32_t)(M_" #name ")", "Num32"} -#define F(name) {#name, #name "f", "func(n:Num32 -> Num32)"} -#define F_opt(name) {#name, #name "f", "func(n:Num32 -> Num32?)"} -#define F2(name) {#name, #name "f", "func(x,y:Num32 -> Num32)"} +#define C(name) {#name, "(Float32_t)(M_" #name ")", "Float32"} +#define F(name) {#name, #name "f", "func(n:Float32 -> Float32)"} +#define F_opt(name) {#name, #name "f", "func(n:Float32 -> Float32?)"} +#define F2(name) {#name, #name "f", "func(x,y:Float32 -> Float32)"} MAKE_TYPE( // - "Num32", Type(NumType, .bits = TYPE_NBITS32), Text("Num32_t"), Text("Num32$info"), // - {"near", "Num32$near", "func(x,y:Num32, ratio=Num32(1e-9), min_epsilon=Num32(1e-9) -> Bool)"}, // - {"clamped", "Num32$clamped", "func(x,low,high:Num32 -> Num32)"}, // - {"percent", "Num32$percent", "func(n:Num32,precision=Num32(.01) -> Text)"}, // - {"with_precision", "Num32$with_precision", "func(n:Num32,precision:Num32 -> Num32)"}, // - {"is_between", "Num32$is_between", "func(x:Num32,low:Num32,high:Num32 -> Bool)"}, // - {"isinf", "Num32$isinf", "func(n:Num32 -> Bool)"}, // - {"isfinite", "Num32$isfinite", "func(n:Num32 -> Bool)"}, // + "Float32", Type(FloatType, .bits = TYPE_NBITS32), Text("Float32_t"), Text("Float32$info"), // + {"near", "Float32$near", "func(x,y:Float32, ratio=Float32(1e-9), min_epsilon=Float32(1e-9) -> Bool)"}, // + {"clamped", "Float32$clamped", "func(x,low,high:Float32 -> Float32)"}, // + {"percent", "Float32$percent", "func(n:Float32,precision=Float32(.01) -> Text)"}, // + {"with_precision", "Float32$with_precision", "func(n:Float32,precision:Float32 -> Float32)"}, // + {"is_between", "Float32$is_between", "func(x:Float32,low:Float32,high:Float32 -> Bool)"}, // + {"isinf", "Float32$isinf", "func(n:Float32 -> Bool)"}, // + {"isfinite", "Float32$isfinite", "func(n:Float32 -> Bool)"}, // C(2_SQRTPI), C(E), C(PI_2), C(2_PI), C(1_PI), C(LN10), C(LN2), C(LOG2E), C(PI), C(PI_4), C(SQRT2), C(SQRT1_2), // - {"INF", "(Num32_t)(INFINITY)", "Num32"}, // - {"TAU", "(Num32_t)(2.f*M_PI)", "Num32"}, // - {"mix", "Num32$mix", "func(amount,x,y:Num32 -> Num32)"}, // - {"parse", "Num32$parse", "func(text:Text, remainder:&Text? = none -> Num32?)"}, // - {"abs", "fabsf", "func(n:Num32 -> Num32)"}, // - {"modulo", "Num32$mod", "func(x,y:Num32 -> Num32)"}, // - {"modulo1", "Num32$mod1", "func(x,y:Num32 -> Num32)"}, // + {"INF", "(Float32_t)(INFINITY)", "Float32"}, // + {"TAU", "(Float32_t)(2.f*M_PI)", "Float32"}, // + {"mix", "Float32$mix", "func(amount,x,y:Float32 -> Float32)"}, // + {"parse", "Float32$parse", "func(text:Text, remainder:&Text? = none -> Float32?)"}, // + {"abs", "fabsf", "func(n:Float32 -> Float32)"}, // + {"modulo", "Float32$mod", "func(x,y:Float32 -> Float32)"}, // + {"modulo1", "Float32$mod1", "func(x,y:Float32 -> Float32)"}, // F_opt(acos), F_opt(acosh), F_opt(asin), F(asinh), F(atan), F_opt(atanh), F(cbrt), F(ceil), F_opt(cos), F(cosh), F(erf), F(erfc), F(exp), F(exp2), F(expm1), F(floor), F(j0), F(j1), F_opt(log), F_opt(log10), F_opt(log1p), F_opt(log2), F(logb), F(rint), F(round), F(significand), F_opt(sin), F(sinh), F_opt(sqrt), @@ -457,8 +457,8 @@ env_t *global_env(bool source_mapping) { {"Int$from_int16", "func(i:Int16 -> Int)"}, // {"Int$from_int32", "func(i:Int32 -> Int)"}, // {"Int$from_int64", "func(i:Int64 -> Int)"}, // - {"Int$from_num", "func(n:Num, truncate=no -> Int)"}, // - {"Int$from_num32", "func(n:Num32, truncate=no -> Int)"}); + {"Int$from_float64", "func(n:Float64, truncate=no -> Int)"}, // + {"Int$from_float32", "func(n:Float32, truncate=no -> Int)"}); ADD_CONSTRUCTORS("Int64", // {"Int64$from_bool", "func(b:Bool -> Int64)"}, // {"Int64$from_byte", "func(b:Byte -> Int64)"}, // @@ -466,8 +466,8 @@ env_t *global_env(bool source_mapping) { {"Int64$from_int16", "func(i:Int16 -> Int64)"}, // {"Int64$from_int32", "func(i:Int32 -> Int64)"}, // {"Int64$from_int", "func(i:Int, truncate=no -> Int64)"}, // - {"Int64$from_num", "func(n:Num, truncate=no -> Int64)"}, // - {"Int64$from_num32", "func(n:Num32, truncate=no -> Int64)"}); + {"Int64$from_float64", "func(n:Float64, truncate=no -> Int64)"}, // + {"Int64$from_float32", "func(n:Float32, truncate=no -> Int64)"}); ADD_CONSTRUCTORS("Int32", // {"Int32$from_bool", "func(b:Bool -> Int32)"}, // {"Int32$from_byte", "func(b:Byte -> Int32)"}, // @@ -475,8 +475,8 @@ env_t *global_env(bool source_mapping) { {"Int32$from_int16", "func(i:Int16 -> Int32)"}, // {"Int32$from_int64", "func(i:Int64, truncate=no -> Int32)"}, // {"Int32$from_int", "func(i:Int, truncate=no -> Int32)"}, // - {"Int32$from_num", "func(n:Num, truncate=no -> Int32)"}, // - {"Int32$from_num32", "func(n:Num32, truncate=no -> Int32)"}); + {"Int32$from_float64", "func(n:Float64, truncate=no -> Int32)"}, // + {"Int32$from_float32", "func(n:Float32, truncate=no -> Int32)"}); ADD_CONSTRUCTORS("Int16", // {"Int16$from_bool", "func(b:Bool -> Int16)"}, // {"Int16$from_byte", "func(b:Byte -> Int16)"}, // @@ -484,8 +484,8 @@ env_t *global_env(bool source_mapping) { {"Int16$from_int32", "func(i:Int32, truncate=no -> Int16)"}, // {"Int16$from_int64", "func(i:Int64, truncate=no -> Int16)"}, // {"Int16$from_int", "func(i:Int, truncate=no -> Int16)"}, // - {"Int16$from_num", "func(n:Num, truncate=no -> Int16)"}, // - {"Int16$from_num32", "func(n:Num32, truncate=no -> Int16)"}); + {"Int16$from_float64", "func(n:Float64, truncate=no -> Int16)"}, // + {"Int16$from_float32", "func(n:Float32, truncate=no -> Int16)"}); ADD_CONSTRUCTORS("Int8", // {"Int8$from_bool", "func(b:Bool -> Int8)"}, // {"Int8$from_byte", "func(b:Byte -> Int8)"}, // @@ -493,26 +493,26 @@ env_t *global_env(bool source_mapping) { {"Int8$from_int32", "func(i:Int32, truncate=no -> Int8)"}, // {"Int8$from_int64", "func(i:Int64, truncate=no -> Int8)"}, // {"Int8$from_int", "func(i:Int, truncate=no -> Int8)"}, // - {"Int8$from_num", "func(n:Num, truncate=no -> Int8)"}, // - {"Int8$from_num32", "func(n:Num32, truncate=no -> Int8)"}); - ADD_CONSTRUCTORS("Num", // - {"Num$from_bool", "func(b:Bool -> Num)"}, // - {"Num$from_byte", "func(b:Byte -> Num)"}, // - {"Num$from_int8", "func(i:Int8 -> Num)"}, // - {"Num$from_int16", "func(i:Int16 -> Num)"}, // - {"Num$from_int32", "func(i:Int32 -> Num)"}, // - {"Num$from_int64", "func(i:Int64, truncate=no -> Num)"}, // - {"Num$from_int", "func(i:Int, truncate=no -> Num)"}, // - {"Num$from_num32", "func(n:Num32 -> Num)"}); - ADD_CONSTRUCTORS("Num32", // - {"Num32$from_bool", "func(b:Bool -> Num32)"}, // - {"Num32$from_byte", "func(b:Byte -> Num32)"}, // - {"Num32$from_int8", "func(i:Int8 -> Num32)"}, // - {"Num32$from_int16", "func(i:Int16 -> Num32)"}, // - {"Num32$from_int32", "func(i:Int32, truncate=no -> Num32)"}, // - {"Num32$from_int64", "func(i:Int64, truncate=no -> Num32)"}, // - {"Num32$from_int", "func(i:Int, truncate=no -> Num32)"}, // - {"Num32$from_num", "func(n:Num -> Num32)"}); + {"Int8$from_float64", "func(n:Float64, truncate=no -> Int8)"}, // + {"Int8$from_float32", "func(n:Float32, truncate=no -> Int8)"}); + ADD_CONSTRUCTORS("Float64", // + {"Float64$from_bool", "func(b:Bool -> Float64)"}, // + {"Float64$from_byte", "func(b:Byte -> Float64)"}, // + {"Float64$from_int8", "func(i:Int8 -> Float64)"}, // + {"Float64$from_int16", "func(i:Int16 -> Float64)"}, // + {"Float64$from_int32", "func(i:Int32 -> Float64)"}, // + {"Float64$from_int64", "func(i:Int64, truncate=no -> Float64)"}, // + {"Float64$from_int", "func(i:Int, truncate=no -> Float64)"}, // + {"Float64$from_float32", "func(n:Float32 -> Float32)"}); + ADD_CONSTRUCTORS("Float32", // + {"Float32$from_bool", "func(b:Bool -> Float32)"}, // + {"Float32$from_byte", "func(b:Byte -> Float32)"}, // + {"Float32$from_int8", "func(i:Int8 -> Float32)"}, // + {"Float32$from_int16", "func(i:Int16 -> Float32)"}, // + {"Float32$from_int32", "func(i:Int32, truncate=no -> Float32)"}, // + {"Float32$from_int64", "func(i:Int64, truncate=no -> Float32)"}, // + {"Float32$from_int", "func(i:Int, truncate=no -> Float32)"}, // + {"Float32$from_float64", "func(n:Float64 -> Float32)"}); ADD_CONSTRUCTORS("Path", // {"Path$escape_text", "func(text:Text -> Path)"}, // {"Path$escape_path", "func(path:Path -> Path)"}, // @@ -536,7 +536,7 @@ env_t *global_env(bool source_mapping) { {"ask", "ask", "func(prompt:Text, bold=yes, force_tty=yes -> Text?)"}, {"exit", "tomo_exit", "func(message:Text?=none, code=Int32(1) -> Abort)"}, {"fail", "fail_text", "func(message:Text -> Abort)"}, - {"sleep", "sleep_num", "func(seconds:Num)"}, + {"sleep", "sleep_float64", "func(seconds:Float64)"}, {"EMPTY", "EMPTY", "Empty"}, }; @@ -671,7 +671,7 @@ env_t *get_namespace_by_type(env_t *env, type_t *t) { case BoolType: case IntType: case BigIntType: - case NumType: + case FloatType: case ByteType: { binding_t *b = get_binding(env, Text$as_c_string(type_to_text(t))); assert(b); diff --git a/src/stdlib/README.md b/src/stdlib/README.md index 671d330a..cf375ff6 100644 --- a/src/stdlib/README.md +++ b/src/stdlib/README.md @@ -22,9 +22,9 @@ some common functionality. - C Strings: [c_strings.h](c_strings.h), [c_strings.c](c_strings.c) - Files (used internally only): [files.h](files.h), [files.c](files.c) - Functiontype: [functiontype.h](functiontype.h), [functiontype.c](functiontype.c) -- Integers: [integers.h](integers.h), [integers.c](integers.c) +- Integers: [bigint.h](bigint.h), [bigint.c](bigint.c), [intX.h](intX.h), [intX.c.h](intX.c.h) - Memory: [memory.h](memory.h), [memory.c](memory.c) -- Nums: [nums.h](nums.h), [nums.c](nums.c) +- Floating point numbers: [floatX.h](floatX.h), [floatX.c.h](floatX.c.h) - Optionals: [optionals.h](optionals.h), [optionals.c](optionals.c) - Paths: [paths.h](paths.h), [paths.c](paths.c) - Pointers: [pointers.h](pointers.h), [pointers.c](pointers.c) diff --git a/src/stdlib/bigint.h b/src/stdlib/bigint.h index 614e1501..e50a6847 100644 --- a/src/stdlib/bigint.h +++ b/src/stdlib/bigint.h @@ -1,4 +1,5 @@ // Big integer type (`Int` in Tomo) +#pragma once #include <gmp.h> #include <stdbool.h> @@ -189,13 +190,13 @@ MACROLIKE PUREFUNC bool Int$is_negative(Int_t x) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif -MACROLIKE PUREFUNC Int_t Int$from_num(double n, bool truncate) { +MACROLIKE PUREFUNC Int_t Int$from_float64(double n, bool truncate) { mpz_t result; mpz_init_set_d(result, n); if (!truncate && unlikely(mpz_get_d(result) != n)) fail("Could not convert to an integer without truncation: ", n); return Int$from_mpz(result); } -MACROLIKE PUREFUNC Int_t Int$from_num32(float n, bool truncate) { return Int$from_num((double)n, truncate); } +MACROLIKE PUREFUNC Int_t Int$from_float32(float n, bool truncate) { return Int$from_float64((double)n, truncate); } MACROLIKE Int_t Int$from_int64(int64_t i) { if likely (i >= SMALLEST_SMALL_INT && i <= BIGGEST_SMALL_INT) return (Int_t){.small = (i << 2L) | 1L}; mpz_t result; diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c index 22ed9b94..8301a2c2 100644 --- a/src/stdlib/cli.c +++ b/src/stdlib/cli.c @@ -17,7 +17,7 @@ #include "cli.h" #include "integers.h" #include "metamethods.h" -#include "nums.h" +#include "floats.h" #include "optionals.h" #include "paths.h" #include "print.h" @@ -209,8 +209,8 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty if (type->tag == OptionalInfo) { const TypeInfo_t *nonnull = type->OptionalInfo.type; if (streq(arg, "none")) { - if (nonnull == &Num$info) *(double *)dest = (double)NAN; - else if (nonnull == &Num32$info) *(float *)dest = (float)NAN; + if (nonnull == &Float64$info) *(double *)dest = (double)NAN; + else if (nonnull == &Float32$info) *(float *)dest = (float)NAN; else memset(dest, 0, (size_t)type->size); return List$from(args, I(2)); } else { @@ -258,14 +258,14 @@ static List_t parse_arg_list(List_t args, const char *flag, void *dest, const Ty OptionalBool_t parsed = Bool$parse(Text$from_str(arg), NULL); if (parsed == NONE_BOOL) print_err("Could not parse argument for ", flag, ": ", arg); *(Bool_t *)dest = parsed; - } else if (type == &Num$info) { - OptionalNum_t parsed = Num$parse(Text$from_str(arg), NULL); + } else if (type == &Float64$info) { + OptionalFloat64_t parsed = Float64$parse(Text$from_str(arg), NULL); if (isnan(parsed)) print_err("Could not parse argument for ", flag, ": ", arg); - *(Num_t *)dest = parsed; - } else if (type == &Num32$info) { - OptionalNum32_t parsed = Num32$parse(Text$from_str(arg), NULL); + *(Float64_t *)dest = parsed; + } else if (type == &Float32$info) { + OptionalFloat32_t parsed = Float32$parse(Text$from_str(arg), NULL); if (isnan(parsed)) print_err("Could not parse argument for ", flag, ": ", arg); - *(Num32_t *)dest = parsed; + *(Float32_t *)dest = parsed; } else if (type->tag == PointerInfo) { // For pointers, we can just allocate memory for the value and then parse the value void *value = GC_MALLOC((size_t)type->PointerInfo.pointed->size); diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h index 446df0ef..c177a0a5 100644 --- a/src/stdlib/datatypes.h +++ b/src/stdlib/datatypes.h @@ -18,8 +18,8 @@ #define LIST_MAX_DATA_REFCOUNT MAX_FOR_N_BITS(LIST_REFCOUNT_BITS) #define LIST_MAX_FREE_ENTRIES MAX_FOR_N_BITS(LIST_FREE_BITS) -#define Num_t double -#define Num32_t float +#define Float64_t double +#define Float32_t float #define Int64_t int64_t #define Int32_t int32_t diff --git a/src/stdlib/float32.c b/src/stdlib/float32.c new file mode 100644 index 00000000..855118ba --- /dev/null +++ b/src/stdlib/float32.c @@ -0,0 +1,4 @@ +// Type infos and methods for Float32 (32-bit floating point) using a template file + +#define FLOATX_C_H__BITS 32 +#include "floatX.c.h" diff --git a/src/stdlib/float64.c b/src/stdlib/float64.c new file mode 100644 index 00000000..e41c01f5 --- /dev/null +++ b/src/stdlib/float64.c @@ -0,0 +1,4 @@ +// Type infos and methods for Float64 (64-bit floating point) using a template file + +#define FLOATX_C_H__BITS 64 +#include "floatX.c.h" diff --git a/src/stdlib/numX.c.h b/src/stdlib/floatX.c.h index 7b030ab4..0961631c 100644 --- a/src/stdlib/numX.c.h +++ b/src/stdlib/floatX.c.h @@ -1,8 +1,8 @@ -// Type infos and methods for Nums (floating point) -// This file is a template that expects `NUMSX_C_H__BITS` to be defined before including: +// Type infos and methods for Floats (floating point numbers) +// This file is a template that expects `FLOATX_C_H__BITS` to be defined before including: // -// #define NUMX_C_H__BITS 64 -// #include "numX.c.h" +// #define FLOATX_C_H__BITS 64 +// #include "floatX.c.h" // #include <float.h> #include <gc.h> @@ -14,32 +14,32 @@ #include "text.h" #include "types.h" -#ifndef NUMX_C_H__BITS -#define NUMX_C_H__BITS 64 +#ifndef FLOATX_C_H__BITS +#define FLOATX_C_H__BITS 64 #endif -#if NUMX_C_H__BITS == 64 -#define NUM_T double +#if FLOATX_C_H__BITS == 64 +#define FLOAT_T double #define OPT_T double -#define NAMESPACED(x) Num$##x -#define TYPE_STR "Num" +#define NAMESPACED(x) Float64$##x +#define TYPE_STR "Float64" #define SUFFIXED(x) x -#elif NUMX_C_H__BITS == 32 -#define NUM_T float +#elif FLOATX_C_H__BITS == 32 +#define FLOAT_T float #define OPT_T float -#define NAMESPACED(x) Num32$##x -#define TYPE_STR "Num32" +#define NAMESPACED(x) Float32$##x +#define TYPE_STR "Float32" #define SUFFIXED(x) x##f #else -#error "Unsupported bit width for Num" +#error "Unsupported bit width for Float" #endif -#if NUMX_C_H__BITS == 64 +#if FLOATX_C_H__BITS == 64 #include "fpconv.h" #include "string.h" public -PUREFUNC Text_t NAMESPACED(value_as_text)(NUM_T x) { +PUREFUNC Text_t NAMESPACED(value_as_text)(FLOAT_T x) { char *str = GC_MALLOC_ATOMIC(24); int len = fpconv_dtoa(x, str); return Text$from_strn(str, (size_t)len); @@ -49,7 +49,7 @@ PUREFUNC Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo (void)info; if (!x) return Text(TYPE_STR); static const Text_t color_prefix = Text("\x1b[35m"), color_suffix = Text("\x1b[m"); - Text_t text = NAMESPACED(value_as_text)(*(NUM_T *)x); + Text_t text = NAMESPACED(value_as_text)(*(FLOAT_T *)x); return colorize ? Texts(color_prefix, text, color_suffix) : text; } public @@ -64,14 +64,14 @@ PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInf return (rx > ry) - (rx < ry); } -#elif NUMX_C_H__BITS == 32 +#elif FLOATX_C_H__BITS == 32 public -PUREFUNC Text_t NAMESPACED(value_as_text)(NUM_T x) { return Num$value_as_text((double)x); } +PUREFUNC Text_t NAMESPACED(value_as_text)(FLOAT_T x) { return Float64$value_as_text((double)x); } PUREFUNC Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo_t *info) { (void)info; if (!x) return Text(TYPE_STR); static const Text_t color_prefix = Text("\x1b[35m"), color_suffix = Text("\x1b[m"); - Text_t text = Num$value_as_text((double)*(NUM_T *)x); + Text_t text = Float64$value_as_text((double)*(FLOAT_T *)x); return colorize ? Texts(color_prefix, text, color_suffix) : text; } public @@ -91,69 +91,71 @@ PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInf public PUREFUNC bool NAMESPACED(equal)(const void *x, const void *y, const TypeInfo_t *info) { (void)info; - return *(NUM_T *)x == *(NUM_T *)y; + return *(FLOAT_T *)x == *(FLOAT_T *)y; } public -CONSTFUNC bool NAMESPACED(near)(NUM_T a, NUM_T b, NUM_T ratio, NUM_T absolute) { +CONSTFUNC bool NAMESPACED(near)(FLOAT_T a, FLOAT_T b, FLOAT_T ratio, FLOAT_T absolute) { if (ratio < 0) ratio = 0; else if (ratio > 1) ratio = 1; if (a == b) return true; - NUM_T diff = SUFFIXED(fabs)(a - b); + FLOAT_T diff = SUFFIXED(fabs)(a - b); if (diff < absolute) return true; else if (isnan(diff)) return false; - NUM_T epsilon = SUFFIXED(fabs)(a * ratio) + SUFFIXED(fabs)(b * ratio); + FLOAT_T epsilon = SUFFIXED(fabs)(a * ratio) + SUFFIXED(fabs)(b * ratio); if (isinf(epsilon)) epsilon = DBL_MAX; return (diff < epsilon); } public -Text_t NAMESPACED(percent)(NUM_T x, NUM_T precision) { - NUM_T d = SUFFIXED(100.) * x; +Text_t NAMESPACED(percent)(FLOAT_T x, FLOAT_T precision) { + FLOAT_T d = SUFFIXED(100.) * x; d = NAMESPACED(with_precision)(d, precision); return Texts(NAMESPACED(value_as_text)(d), Text("%")); } public -CONSTFUNC NUM_T NAMESPACED(with_precision)(NUM_T num, NUM_T precision) { - if (precision == SUFFIXED(0.0)) return num; +CONSTFUNC FLOAT_T NAMESPACED(with_precision)(FLOAT_T n, FLOAT_T precision) { + if (precision == SUFFIXED(0.0)) return n; // Precision will be, e.g. 0.01 or 100. if (precision < SUFFIXED(1.)) { - NUM_T inv = SUFFIXED(round)(SUFFIXED(1.) / precision); // Necessary to make the math work - NUM_T k = num * inv; + FLOAT_T inv = SUFFIXED(round)(SUFFIXED(1.) / precision); // Necessary to make the math work + FLOAT_T k = n * inv; return SUFFIXED(round)(k) / inv; } else { - NUM_T k = num / precision; + FLOAT_T k = n / precision; return SUFFIXED(round)(k) * precision; } } public -CONSTFUNC NUM_T NAMESPACED(mod)(NUM_T num, NUM_T modulus) { +CONSTFUNC FLOAT_T NAMESPACED(mod)(FLOAT_T n, FLOAT_T modulus) { // Euclidean division, see: // https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf - NUM_T r = (NUM_T)remainder((double)num, (double)modulus); + FLOAT_T r = (FLOAT_T)remainder((double)n, (double)modulus); r -= (r < SUFFIXED(0.)) * (SUFFIXED(2.) * (modulus < SUFFIXED(0.)) - SUFFIXED(1.)) * modulus; return r; } public -CONSTFUNC NUM_T NAMESPACED(mod1)(NUM_T num, NUM_T modulus) { - return SUFFIXED(1.0) + NAMESPACED(mod)(num - SUFFIXED(1.0), modulus); +CONSTFUNC FLOAT_T NAMESPACED(mod1)(FLOAT_T n, FLOAT_T modulus) { + return SUFFIXED(1.0) + NAMESPACED(mod)(n - SUFFIXED(1.0), modulus); } public -CONSTFUNC NUM_T NAMESPACED(mix)(NUM_T amount, NUM_T x, NUM_T y) { return (SUFFIXED(1.0) - amount) * x + amount * y; } +CONSTFUNC FLOAT_T NAMESPACED(mix)(FLOAT_T amount, FLOAT_T x, FLOAT_T y) { + return (SUFFIXED(1.0) - amount) * x + amount * y; +} public -CONSTFUNC bool NAMESPACED(is_between)(const NUM_T x, const NUM_T low, const NUM_T high) { +CONSTFUNC bool NAMESPACED(is_between)(const FLOAT_T x, const FLOAT_T low, const FLOAT_T high) { return low <= x && x <= high; } public -CONSTFUNC NUM_T NAMESPACED(clamped)(NUM_T x, NUM_T low, NUM_T high) { +CONSTFUNC FLOAT_T NAMESPACED(clamped)(FLOAT_T x, FLOAT_T low, FLOAT_T high) { return (x <= low) ? low : (x >= high ? high : x); } @@ -161,10 +163,10 @@ public OPT_T NAMESPACED(parse)(Text_t text, Text_t *remainder) { const char *str = Text$as_c_string(text); char *end = NULL; -#if NUMX_C_H__BITS == 64 - NUM_T n = strtod(str, &end); -#elif NUMX_C_H__BITS == 32 - NUM_T n = strtof(str, &end); +#if FLOATX_C_H__BITS == 64 + FLOAT_T n = strtod(str, &end); +#elif FLOATX_C_H__BITS == 32 + FLOAT_T n = strtof(str, &end); #endif if (end > str) { if (remainder) *remainder = Text$from_str(end); @@ -179,20 +181,20 @@ OPT_T NAMESPACED(parse)(Text_t text, Text_t *remainder) { public CONSTFUNC bool NAMESPACED(is_none)(const void *n, const TypeInfo_t *info) { (void)info; - return isnan(*(NUM_T *)n); + return isnan(*(FLOAT_T *)n); } public -CONSTFUNC bool NAMESPACED(isinf)(NUM_T n) { return (fpclassify(n) == FP_INFINITE); } +CONSTFUNC bool NAMESPACED(isinf)(FLOAT_T n) { return (fpclassify(n) == FP_INFINITE); } public -CONSTFUNC bool NAMESPACED(finite)(NUM_T n) { return (fpclassify(n) != FP_INFINITE); } +CONSTFUNC bool NAMESPACED(finite)(FLOAT_T n) { return (fpclassify(n) != FP_INFINITE); } public -CONSTFUNC bool NAMESPACED(isnan)(NUM_T n) { return (fpclassify(n) == FP_NAN); } +CONSTFUNC bool NAMESPACED(isnan)(FLOAT_T n) { return (fpclassify(n) == FP_NAN); } public const TypeInfo_t NAMESPACED(info) = { - .size = sizeof(NUM_T), - .align = __alignof__(NUM_T), + .size = sizeof(FLOAT_T), + .align = __alignof__(FLOAT_T), .metamethods = { .compare = NAMESPACED(compare), @@ -202,9 +204,9 @@ const TypeInfo_t NAMESPACED(info) = { }, }; -#undef NUM_T +#undef FLOAT_T #undef OPT_T #undef NAMESPACED #undef TYPE_STR #undef SUFFIXED -#undef NUMX_C_H__BITS +#undef FLOATX_C_H__BITS diff --git a/src/stdlib/floatX.h b/src/stdlib/floatX.h new file mode 100644 index 00000000..ff2d0931 --- /dev/null +++ b/src/stdlib/floatX.h @@ -0,0 +1,103 @@ +// Template header for 64 and 32 bit floating point numbers +// This file expects `FLOATX_H__BITS` to be defined before including: +// +// #define FLOATX_H__BITS 64 +// #include "floatX.h" +// + +#include <stdbool.h> +#include <stdint.h> + +#include "datatypes.h" +#include "stdlib.h" +#include "types.h" +#include "util.h" + +#ifndef FLOATX_H__BITS +#define FLOATX_H__BITS 64 +#endif + +#if FLOATX_H__BITS == 64 +#define FLOAT_T double +#define OPT_T double +#define NAMESPACED(x) Float64$##x +#define TYPE_STR "Float64" +#define SUFFIXED(x) x +#elif FLOATX_H__BITS == 32 +#define FLOAT_T float +#define OPT_T float +#define NAMESPACED(x) Float32$##x +#define TYPE_STR "Float32" +#define SUFFIXED(x) x##f +#else +#error "Unsupported bit width for Float" +#endif + +Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo_t *type); +Text_t NAMESPACED(value_as_text)(FLOAT_T x); +PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *type); +PUREFUNC bool NAMESPACED(equal)(const void *x, const void *y, const TypeInfo_t *type); +CONSTFUNC bool NAMESPACED(near)(FLOAT_T a, FLOAT_T b, FLOAT_T ratio, FLOAT_T absolute); +Text_t NAMESPACED(percent)(FLOAT_T x, FLOAT_T precision); +FLOAT_T CONSTFUNC NAMESPACED(with_precision)(FLOAT_T n, FLOAT_T precision); +FLOAT_T NAMESPACED(mod)(FLOAT_T n, FLOAT_T modulus); +FLOAT_T NAMESPACED(mod1)(FLOAT_T n, FLOAT_T modulus); +CONSTFUNC bool NAMESPACED(isinf)(FLOAT_T n); +CONSTFUNC bool NAMESPACED(finite)(FLOAT_T n); +CONSTFUNC bool NAMESPACED(isnan)(FLOAT_T n); +bool NAMESPACED(is_none)(const void *n, const TypeInfo_t *info); +FLOAT_T NAMESPACED(nan)(Text_t tag); +CONSTFUNC FLOAT_T NAMESPACED(mix)(FLOAT_T amount, FLOAT_T x, FLOAT_T y); +OPT_T NAMESPACED(parse)(Text_t text, Text_t *remainder); +CONSTFUNC bool NAMESPACED(is_between)(const FLOAT_T x, const FLOAT_T low, const FLOAT_T high); +CONSTFUNC FLOAT_T NAMESPACED(clamped)(FLOAT_T x, FLOAT_T low, FLOAT_T high); + +#if FLOATX_H__BITS == 64 +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_float32)(float n) { return (FLOAT_T)n; } +#elif FLOATX_H__BITS == 32 +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_float64)(double n) { return (FLOAT_T)n; } +#endif + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_int)(Int_t i, bool truncate) { + if likely (i.small & 0x1) { + FLOAT_T ret = (FLOAT_T)(i.small >> 2); + if unlikely (!truncate && (int64_t)ret != (i.small >> 2)) + fail("Could not convert integer to " TYPE_STR " without losing precision: ", i.small >> 2); + return ret; + } else { + FLOAT_T ret = mpz_get_d(i.big); + if (!truncate) { + mpz_t roundtrip; + mpz_init_set_d(roundtrip, (double)ret); + if unlikely (mpz_cmp(i.big, roundtrip) != 0) + fail("Could not convert integer to " TYPE_STR " without losing precision: ", i); + } + return ret; + } +} +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_int64)(Int64_t i, bool truncate) { + FLOAT_T n = (FLOAT_T)i; + if unlikely (!truncate && (Int64_t)n != i) + fail("Could not convert integer to " TYPE_STR " without losing precision: ", i); + return n; +} +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_int32)(Int32_t i) { return (FLOAT_T)i; } +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_int16)(Int16_t i) { return (FLOAT_T)i; } +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_int8)(Int8_t i) { return (FLOAT_T)i; } +MACROLIKE CONSTFUNC FLOAT_T NAMESPACED(from_byte)(Byte_t i) { return (FLOAT_T)i; } + +extern const TypeInfo_t NAMESPACED(info); + +#undef FLOAT_T +#undef OPT_T +#undef NAMESPACED +#undef TYPE_STR +#undef SUFFIXED +#undef FLOATX_H__BITS diff --git a/src/stdlib/floats.h b/src/stdlib/floats.h new file mode 100644 index 00000000..c23974c1 --- /dev/null +++ b/src/stdlib/floats.h @@ -0,0 +1,13 @@ +// Type infos and methods for Floats (floating point numbers) + +#pragma once + +#define F64(n) ((double)(n)) +#define OptionalFloat64_t double +#define FLOATX_H__BITS 64 +#include "floatX.h" + +#define F32(n) ((float)(n)) +#define OptionalFloat32_t float +#define FLOATX_H__BITS 32 +#include "floatX.h" diff --git a/src/stdlib/intX.h b/src/stdlib/intX.h index 765543fd..03aa7247 100644 --- a/src/stdlib/intX.h +++ b/src/stdlib/intX.h @@ -88,16 +88,17 @@ MACROLIKE PUREFUNC INTX_T NAMESPACED(unsigned_right_shifted)(INTX_T x, INTX_T y) void NAMESPACED(serialize)(const void *obj, FILE *out, Table_t *, const TypeInfo_t *); void NAMESPACED(deserialize)(FILE *in, void *outval, List_t *, const TypeInfo_t *); -MACROLIKE PUREFUNC INTX_T NAMESPACED(from_num)(Num_t n, bool truncate) { +MACROLIKE PUREFUNC INTX_T NAMESPACED(from_float64)(Float64_t n, bool truncate) { INTX_T i = (INTX_T)n; - if (!truncate && unlikely((Num_t)i != n)) fail("Could not convert Num to an " NAME_STR " without truncation: ", n); + if (!truncate && unlikely((Float64_t)i != n)) + fail("Could not convert Float64 to an " NAME_STR " without truncation: ", n); return i; } -MACROLIKE PUREFUNC INTX_T NAMESPACED(from_num32)(Num32_t n, bool truncate) { +MACROLIKE PUREFUNC INTX_T NAMESPACED(from_float32)(Float32_t n, bool truncate) { INTX_T i = (INTX_T)n; - if (!truncate && unlikely((Num32_t)i != n)) - fail("Could not convert Num32 to an " NAME_STR " without truncation: ", n); + if (!truncate && unlikely((Float32_t)i != n)) + fail("Could not convert Float32 to an " NAME_STR " without truncation: ", n); return i; } diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c index db514671..1a47f2e3 100644 --- a/src/stdlib/lists.c +++ b/src/stdlib/lists.c @@ -345,18 +345,18 @@ Table_t List$counts(List_t list, const TypeInfo_t *type) { return counts; } -static double _default_random_num(void *userdata) { +static double _default_random_float64(void *userdata) { (void)userdata; union { - Num_t num; + Float64_t n; uint64_t bits; - } r = {.bits = 0}, one = {.num = 1.0}; + } r = {.bits = 0}, one = {.n = 1.0}; assert(getrandom((uint8_t *)&r, sizeof(r), 0) == sizeof(r)); - // Set r.num to 1.<random-bits> + // Set r.n to 1.<random-bits> r.bits &= ~(0xFFFULL << 52); r.bits |= (one.bits & (0xFFFULL << 52)); - return r.num - 1.0; + return r.n - 1.0; } public @@ -419,7 +419,7 @@ List_t List$sample(List_t list, Int_t int_n, List_t weights, OptionalClosure_t r if (aliases[i].alias == -1) aliases[i].alias = i; typedef double (*rng_fn_t)(void *); - rng_fn_t rng_fn = random_num.fn ? (rng_fn_t)random_num.fn : _default_random_num; + rng_fn_t rng_fn = random_num.fn ? (rng_fn_t)random_num.fn : _default_random_float64; List_t selected = {.data = list.atomic ? GC_MALLOC_ATOMIC((size_t)(n * padded_item_size)) : GC_MALLOC((size_t)(n * padded_item_size)), diff --git a/src/stdlib/num32.c b/src/stdlib/num32.c deleted file mode 100644 index 6d505f37..00000000 --- a/src/stdlib/num32.c +++ /dev/null @@ -1,4 +0,0 @@ -// Type infos and methods for Num32 (32-bit floating point) using a template file - -#define NUMX_C_H__BITS 32 -#include "numX.c.h" diff --git a/src/stdlib/num64.c b/src/stdlib/num64.c deleted file mode 100644 index 7fdc8f35..00000000 --- a/src/stdlib/num64.c +++ /dev/null @@ -1,4 +0,0 @@ -// Type infos and methods for Num (64-bit floating point) using a template file - -#define NUMX_C_H__BITS 64 -#include "numX.c.h" diff --git a/src/stdlib/numX.h b/src/stdlib/numX.h deleted file mode 100644 index 3d65cb59..00000000 --- a/src/stdlib/numX.h +++ /dev/null @@ -1,103 +0,0 @@ -// Template header for 64 and 32 bit Nums -// This file expects `NUMX_H__BITS` to be defined before including: -// -// #define NUMX_H__BITS 64 -// #include "numX.h" -// - -#include <stdbool.h> -#include <stdint.h> - -#include "datatypes.h" -#include "stdlib.h" -#include "types.h" -#include "util.h" - -#ifndef NUMX_H__BITS -#define NUMX_H__BITS 64 -#endif - -#if NUMX_H__BITS == 64 -#define NUM_T double -#define OPT_T double -#define NAMESPACED(x) Num$##x -#define TYPE_STR "Num" -#define SUFFIXED(x) x -#elif NUMX_H__BITS == 32 -#define NUM_T float -#define OPT_T float -#define NAMESPACED(x) Num32$##x -#define TYPE_STR "Num32" -#define SUFFIXED(x) x##f -#else -#error "Unsupported bit width for Num" -#endif - -Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo_t *type); -Text_t NAMESPACED(value_as_text)(NUM_T x); -PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *type); -PUREFUNC bool NAMESPACED(equal)(const void *x, const void *y, const TypeInfo_t *type); -CONSTFUNC bool NAMESPACED(near)(NUM_T a, NUM_T b, NUM_T ratio, NUM_T absolute); -Text_t NAMESPACED(percent)(NUM_T x, NUM_T precision); -NUM_T CONSTFUNC NAMESPACED(with_precision)(NUM_T num, NUM_T precision); -NUM_T NAMESPACED(mod)(NUM_T num, NUM_T modulus); -NUM_T NAMESPACED(mod1)(NUM_T num, NUM_T modulus); -CONSTFUNC bool NAMESPACED(isinf)(NUM_T n); -CONSTFUNC bool NAMESPACED(finite)(NUM_T n); -CONSTFUNC bool NAMESPACED(isnan)(NUM_T n); -bool NAMESPACED(is_none)(const void *n, const TypeInfo_t *info); -NUM_T NAMESPACED(nan)(Text_t tag); -CONSTFUNC NUM_T NAMESPACED(mix)(NUM_T amount, NUM_T x, NUM_T y); -OPT_T NAMESPACED(parse)(Text_t text, Text_t *remainder); -CONSTFUNC bool NAMESPACED(is_between)(const NUM_T x, const NUM_T low, const NUM_T high); -CONSTFUNC NUM_T NAMESPACED(clamped)(NUM_T x, NUM_T low, NUM_T high); - -#if NUMX_H__BITS == 64 -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num32)(float n) { return (NUM_T)n; } -#elif NUMX_H__BITS == 32 -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num64)(double n) { return (NUM_T)n; } -#endif - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" -#endif -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int)(Int_t i, bool truncate) { - if likely (i.small & 0x1) { - NUM_T ret = (NUM_T)(i.small >> 2); - if unlikely (!truncate && (int64_t)ret != (i.small >> 2)) - fail("Could not convert integer to " TYPE_STR " without losing precision: ", i.small >> 2); - return ret; - } else { - NUM_T ret = mpz_get_d(i.big); - if (!truncate) { - mpz_t roundtrip; - mpz_init_set_d(roundtrip, (double)ret); - if unlikely (mpz_cmp(i.big, roundtrip) != 0) - fail("Could not convert integer to " TYPE_STR " without losing precision: ", i); - } - return ret; - } -} -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int64)(Int64_t i, bool truncate) { - NUM_T n = (NUM_T)i; - if unlikely (!truncate && (Int64_t)n != i) - fail("Could not convert integer to " TYPE_STR " without losing precision: ", i); - return n; -} -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int32)(Int32_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int16)(Int16_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int8)(Int8_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_byte)(Byte_t i) { return (NUM_T)i; } - -extern const TypeInfo_t NAMESPACED(info); - -#undef NUM_T -#undef OPT_T -#undef NAMESPACED -#undef TYPE_STR -#undef SUFFIXED -#undef NUMX_H__BITS diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h deleted file mode 100644 index 8cea9e84..00000000 --- a/src/stdlib/nums.h +++ /dev/null @@ -1,13 +0,0 @@ -// Type infos and methods for Nums (floating point) - -#pragma once - -#define N64(n) ((double)(n)) -#define OptionalNum_t double -#define NUMX_H__BITS 64 -#include "numX.h" - -#define N32(n) ((float)(n)) -#define OptionalNum32_t float -#define NUMX_H__BITS 32 -#include "numX.h" diff --git a/src/stdlib/optionals.c b/src/stdlib/optionals.c index 3fe812b1..b2cd584d 100644 --- a/src/stdlib/optionals.c +++ b/src/stdlib/optionals.c @@ -3,8 +3,8 @@ #include <math.h> #include "datatypes.h" +#include "floats.h" #include "metamethods.h" -#include "nums.h" #include "optionals.h" #include "text.h" #include "util.h" @@ -66,8 +66,8 @@ void Optional$deserialize(FILE *in, void *outval, List_t *pointers, const TypeIn if (nonnull->tag == TextInfo) *(Text_t *)outval = NONE_TEXT; else if (nonnull->tag == ListInfo) *(List_t *)outval = NONE_LIST; else if (nonnull->tag == TableInfo) *(Table_t *)outval = NONE_TABLE; - else if (nonnull == &Num$info) *(double *)outval = (double)NAN; - else if (nonnull == &Num32$info) *(float *)outval = (float)NAN; + else if (nonnull == &Float64$info) *(double *)outval = (double)NAN; + else if (nonnull == &Float32$info) *(float *)outval = (float)NAN; else if (nonnull->tag == StructInfo || (nonnull->tag == OpaqueInfo && type->size > nonnull->size)) memset(outval + type->size, -1, (size_t)(type->size - nonnull->size)); else memset(outval, 0, (size_t)type->size); diff --git a/src/stdlib/reals.c b/src/stdlib/reals.c index a48cd9f2..0cfcfc81 100644 --- a/src/stdlib/reals.c +++ b/src/stdlib/reals.c @@ -6,7 +6,7 @@ #include "bigint.h" #include "datatypes.h" -#include "nums.h" +#include "floats.h" #include "text.h" struct ieee754_bits { @@ -54,10 +54,10 @@ static Int_t Real$compute_double(Real_t r, int64_t precision) { if (data.bits.biased_exponent + precision > 2047) { int64_t double_shift = 2047 - data.bits.biased_exponent; data.bits.biased_exponent += double_shift; - return Int$left_shifted(Int$from_num(data.n, true), Int$from_int64(precision - double_shift)); + return Int$left_shifted(Int$from_float64(data.n, true), Int$from_int64(precision - double_shift)); } else { data.bits.biased_exponent += precision; - return Int$from_num(data.n, true); + return Int$from_float64(data.n, true); } } @@ -67,26 +67,27 @@ double Real$as_float64(Real_t x) { int64_t my_msd = most_significant_bit(x, -1080 /* slightly > exp. range */); if (my_msd == INT64_MIN) return 0.0; int needed_prec = my_msd - 60; - double scaled_int = Num$from_int(Real$compute(x, needed_prec), true); + union { + double d; + uint64_t bits; + } scaled_int = {.d = Float64$from_int(Real$compute(x, needed_prec), true)}; bool may_underflow = (needed_prec < -1000); - int64_t scaled_int_rep = *(int64_t *)&scaled_int; - long exp_adj = may_underflow ? needed_prec + 96 : needed_prec; - long orig_exp = (scaled_int_rep >> 52) & 0x7ff; - if (((orig_exp + exp_adj) & ~0x7ff) != 0) { + uint64_t exp_adj = may_underflow ? (uint64_t)(needed_prec + 96l) : (uint64_t)needed_prec; + uint64_t orig_exp = (scaled_int.bits >> 52) & 0x7fful; + if (((orig_exp + exp_adj) & ~0x7fful) != 0) { // overflow - if (scaled_int < 0.0) { + if (scaled_int.d < 0.0) { return -INFINITY; } else { return INFINITY; } } - scaled_int_rep += exp_adj << 52; - double result = *(double *)&scaled_int_rep; + scaled_int.bits += exp_adj << 52; if (may_underflow) { double two48 = (double)(1L << 48); - return result / two48 / two48; + return scaled_int.d / two48 / two48; } else { - return result; + return scaled_int.d; } return 0.0; @@ -148,7 +149,7 @@ static Int_t Real$compute_times(Real_t r, int64_t precision) { Int_t approx_small = Real$compute(big, precision - MAX(lhs_msb, rhs_msb) - 3); if (approx_small.small == 0x1) return I(0); - Int_t approx_big = Real$compute(big, precision - MIN(lhs_msb, rhs_msb) - 3); + Int_t approx_big = Real$compute(small, precision - MIN(lhs_msb, rhs_msb) - 3); if (approx_big.small == 0x1) return I(0); return Int$right_shifted(Int$times(approx_big, approx_small), Int$from_int64(lhs_msb + rhs_msb - precision)); @@ -194,10 +195,10 @@ static Int_t Real$compute_sqrt(Real_t r, int64_t precision) { int64_t op_prec = (msd - fp_op_prec) & ~1L; int64_t working_prec = op_prec - fp_op_prec; Int_t scaled_bi_appr = Int$left_shifted(Real$compute(operand, op_prec), Int$from_int64(fp_op_prec)); - double scaled_appr = Num$from_int(scaled_bi_appr, true); + double scaled_appr = Float64$from_int(scaled_bi_appr, true); if (scaled_appr < 0.0) fail("Underflow?!?!"); double scaled_fp_sqrt = sqrt(scaled_appr); - Int_t scaled_sqrt = Int$from_num(scaled_fp_sqrt, true); + Int_t scaled_sqrt = Int$from_float64(scaled_fp_sqrt, true); int64_t shift_count = working_prec / 2 - precision; return Int$left_shifted(scaled_sqrt, Int$from_int64(shift_count)); } diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 45a4bd00..c3ea1d36 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -204,7 +204,7 @@ cleanup: } public -void sleep_num(double seconds) { +void sleep_float64(double seconds) { struct timespec ts; ts.tv_sec = (time_t)seconds; ts.tv_nsec = (long)((seconds - (double)ts.tv_sec) * 1e9); diff --git a/src/stdlib/text.h b/src/stdlib/text.h index 821325a9..15630858 100644 --- a/src/stdlib/text.h +++ b/src/stdlib/text.h @@ -7,9 +7,9 @@ #include <stdint.h> #include "datatypes.h" +#include "floats.h" // IWYU pragma: export #include "integers.h" // IWYU pragma: export #include "mapmacro.h" -#include "nums.h" // IWYU pragma: export #include "types.h" #include "util.h" @@ -42,8 +42,8 @@ static inline Text_t Text_from_text(Text_t t) { return t; } int16_t: Int16$value_as_text, \ int32_t: Int32$value_as_text, \ int64_t: Int64$value_as_text, \ - double: Num$value_as_text, \ - float: Num32$value_as_text)(x) + double: Float64$value_as_text, \ + float: Float32$value_as_text)(x) Text_t Text$_concat(int n, Text_t items[n]); #define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__}) / sizeof(Text_t), (Text_t[]){__VA_ARGS__}) diff --git a/src/stdlib/tomo.h b/src/stdlib/tomo.h index 1ff065b9..4abf8856 100644 --- a/src/stdlib/tomo.h +++ b/src/stdlib/tomo.h @@ -15,12 +15,12 @@ #include "datatypes.h" // IWYU pragma: export #include "enums.h" // IWYU pragma: export #include "files.h" // IWYU pragma: export +#include "floats.h" // IWYU pragma: export #include "functiontype.h" // IWYU pragma: export #include "integers.h" // IWYU pragma: export #include "lists.h" // IWYU pragma: export #include "memory.h" // IWYU pragma: export #include "metamethods.h" // IWYU pragma: export -#include "nums.h" // IWYU pragma: export #include "optionals.h" // IWYU pragma: export #include "paths.h" // IWYU pragma: export #include "pointers.h" // IWYU pragma: export diff --git a/src/typecheck.c b/src/typecheck.c index 07c3acf9..8e5c7fcb 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -706,7 +706,7 @@ type_t *get_type(env_t *env, ast_t *ast) { return Type(BigIntType); } case Num: { - return Type(NumType, .bits = TYPE_NBITS64); + return Type(FloatType, .bits = TYPE_NBITS64); } case HeapAllocate: { type_t *pointed = get_type(env, Match(ast, HeapAllocate)->value); @@ -912,7 +912,7 @@ type_t *get_type(env_t *env, ast_t *ast) { binding_t *constructor = get_constructor(env, t, call->args, env->current_type != NULL && type_eq(env->current_type, t)); if (constructor) return t; - else if (t->tag == StructType || t->tag == IntType || t->tag == BigIntType || t->tag == NumType + else if (t->tag == StructType || t->tag == IntType || t->tag == BigIntType || t->tag == FloatType || t->tag == ByteType || t->tag == TextType || t->tag == CStringType) return t; // Constructor arg_t *arg_types = NULL; @@ -1081,7 +1081,7 @@ type_t *get_type(env_t *env, ast_t *ast) { case Negative: { ast_t *value = Match(ast, Negative)->value; type_t *t = get_type(env, value); - if (t->tag == IntType || t->tag == NumType) return t; + if (t->tag == IntType || t->tag == FloatType) return t; binding_t *b = get_namespace_binding(env, value, "negative"); if (b && b->type->tag == FunctionType) { @@ -1093,7 +1093,7 @@ type_t *get_type(env_t *env, ast_t *ast) { } case Not: { type_t *t = get_type(env, Match(ast, Not)->value); - if (t->tag == IntType || t->tag == NumType || t->tag == BoolType) return t; + if (t->tag == IntType || t->tag == FloatType || t->tag == BoolType) return t; if (t->tag == OptionalType) return Type(BoolType); ast_t *value = Match(ast, Not)->value; @@ -1138,8 +1138,8 @@ type_t *get_type(env_t *env, ast_t *ast) { non_opt = most_complete_type(non_opt, rhs_t); if (non_opt != NULL) return non_opt; } else if ((is_numeric_type(lhs_t) || lhs_t->tag == BoolType) - && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) && lhs_t->tag != NumType - && rhs_t->tag != NumType) { + && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) && lhs_t->tag != FloatType + && rhs_t->tag != FloatType) { if (can_compile_to_type(env, binop.rhs, lhs_t)) return lhs_t; else if (can_compile_to_type(env, binop.lhs, rhs_t)) return rhs_t; } else if (lhs_t->tag == TableType && rhs_t->tag == TableType && type_eq(lhs_t, rhs_t)) { @@ -1169,7 +1169,7 @@ type_t *get_type(env_t *env, ast_t *ast) { // Bitwise AND: if ((is_numeric_type(lhs_t) || lhs_t->tag == BoolType) && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) - && lhs_t->tag != NumType && rhs_t->tag != NumType) { + && lhs_t->tag != FloatType && rhs_t->tag != FloatType) { if (can_compile_to_type(env, binop.rhs, lhs_t)) return lhs_t; else if (can_compile_to_type(env, binop.lhs, rhs_t)) return rhs_t; } else if (lhs_t->tag == TableType && rhs_t->tag == TableType && type_eq(lhs_t, rhs_t)) { @@ -1199,7 +1199,7 @@ type_t *get_type(env_t *env, ast_t *ast) { // Bitwise XOR: if ((is_numeric_type(lhs_t) || lhs_t->tag == BoolType) && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) - && lhs_t->tag != NumType && rhs_t->tag != NumType) { + && lhs_t->tag != FloatType && rhs_t->tag != FloatType) { if (can_compile_to_type(env, binop.rhs, lhs_t)) return lhs_t; else if (can_compile_to_type(env, binop.lhs, rhs_t)) return rhs_t; } else if (lhs_t->tag == TableType && rhs_t->tag == TableType && type_eq(lhs_t, rhs_t)) { @@ -1699,7 +1699,7 @@ PUREFUNC bool can_compile_to_type(env_t *env, ast_t *ast, type_t *needed) { if (actual->tag == OptionalType && needed->tag == OptionalType) return can_promote(actual, needed); if (is_numeric_type(needed) && ast->tag == Int) return true; - if (needed->tag == NumType && ast->tag == Num) return true; + if (needed->tag == FloatType && ast->tag == Num) return true; needed = non_optional(needed); if (needed->tag == ListType && ast->tag == List) { diff --git a/src/types.c b/src/types.c index 33c5e55b..cc3ac010 100644 --- a/src/types.c +++ b/src/types.c @@ -30,7 +30,7 @@ Text_t type_to_text(type_t *t) { case TextType: return Match(t, TextType)->lang ? Text$from_str(Match(t, TextType)->lang) : Text("Text"); case BigIntType: return Text("Int"); case IntType: return Texts("Int", (int32_t)Match(t, IntType)->bits); - case NumType: return Match(t, NumType)->bits == TYPE_NBITS32 ? Text("Num32") : Text("Num"); + case FloatType: return Match(t, FloatType)->bits == TYPE_NBITS32 ? Text("Float32") : Text("Float64"); case ListType: { DeclareMatch(list, t, ListType); return Texts("[", type_to_text(list->item_type), "]"); @@ -155,7 +155,7 @@ type_t *type_or_type(type_t *a, type_t *b) { if (type_is_a(a, b)) return b; if (a->tag == AbortType || a->tag == ReturnType) return non_optional(b); if (b->tag == AbortType || b->tag == ReturnType) return non_optional(a); - if ((a->tag == IntType || a->tag == NumType) && (b->tag == IntType || b->tag == NumType)) { + if ((a->tag == IntType || a->tag == FloatType) && (b->tag == IntType || b->tag == FloatType)) { switch (compare_precision(a, b)) { case NUM_PRECISION_EQUAL: case NUM_PRECISION_MORE: return a; @@ -181,7 +181,7 @@ static PUREFUNC INLINE double type_min_magnitude(type_t *t) { default: errx(1, "Invalid integer bit size"); } } - case NumType: return -1. / 0.; + case FloatType: return -1. / 0.; default: return (double)NAN; } } @@ -200,7 +200,7 @@ static PUREFUNC INLINE double type_max_magnitude(type_t *t) { default: errx(1, "Invalid integer bit size"); } } - case NumType: return 1. / 0.; + case FloatType: return 1. / 0.; default: return (double)NAN; } } @@ -208,8 +208,8 @@ static PUREFUNC INLINE double type_max_magnitude(type_t *t) { PUREFUNC precision_cmp_e compare_precision(type_t *a, type_t *b) { if (a == NULL || b == NULL) return NUM_PRECISION_INCOMPARABLE; - if (is_int_type(a) && b->tag == NumType) return NUM_PRECISION_LESS; - else if (a->tag == NumType && is_int_type(b)) return NUM_PRECISION_MORE; + if (is_int_type(a) && b->tag == FloatType) return NUM_PRECISION_LESS; + else if (a->tag == FloatType && is_int_type(b)) return NUM_PRECISION_MORE; double a_min = type_min_magnitude(a), b_min = type_min_magnitude(b), a_max = type_max_magnitude(a), b_max = type_max_magnitude(b); @@ -279,11 +279,11 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) { // Serialization/deserialization if (type_eq(actual, Type(ListType, Type(ByteType))) || type_eq(needed, Type(ListType, Type(ByteType)))) return true; - if (actual->tag == NumType && needed->tag == IntType) return false; + if (actual->tag == FloatType && needed->tag == IntType) return false; - if (actual->tag == IntType && (needed->tag == NumType || needed->tag == BigIntType)) return true; + if (actual->tag == IntType && (needed->tag == FloatType || needed->tag == BigIntType)) return true; - if (actual->tag == BigIntType && needed->tag == NumType) return true; + if (actual->tag == BigIntType && needed->tag == FloatType) return true; if (actual->tag == IntType && needed->tag == IntType) { precision_cmp_e cmp = compare_precision(actual, needed); @@ -305,7 +305,7 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) { if (Match(actual, OptionalType)->type == NULL) return (needed->tag == OptionalType); // Optional num -> num - if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType) + if (needed->tag == FloatType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == FloatType) return can_promote(Match(actual, OptionalType)->type, needed); } @@ -379,11 +379,11 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) { PUREFUNC bool is_int_type(type_t *t) { return t->tag == IntType || t->tag == BigIntType || t->tag == ByteType; } PUREFUNC bool is_numeric_type(type_t *t) { - return t->tag == IntType || t->tag == BigIntType || t->tag == NumType || t->tag == ByteType; + return t->tag == IntType || t->tag == BigIntType || t->tag == FloatType || t->tag == ByteType; } PUREFUNC bool is_packed_data(type_t *t) { - if (t->tag == IntType || t->tag == NumType || t->tag == ByteType || t->tag == PointerType || t->tag == BoolType + if (t->tag == IntType || t->tag == FloatType || t->tag == ByteType || t->tag == PointerType || t->tag == BoolType || t->tag == FunctionType) { return true; } else if (t->tag == StructType) { @@ -458,7 +458,7 @@ PUREFUNC size_t type_size(type_t *t) { default: errx(1, "Invalid integer bit size"); } } - case NumType: return Match(t, NumType)->bits == TYPE_NBITS64 ? sizeof(double) : sizeof(float); + case FloatType: return Match(t, FloatType)->bits == TYPE_NBITS64 ? sizeof(double) : sizeof(float); case TextType: return sizeof(Text_t); case ListType: return sizeof(List_t); case TableType: return sizeof(Table_t); @@ -547,7 +547,7 @@ PUREFUNC size_t type_align(type_t *t) { default: return 0; } } - case NumType: return Match(t, NumType)->bits == TYPE_NBITS64 ? __alignof__(double) : __alignof__(float); + case FloatType: return Match(t, FloatType)->bits == TYPE_NBITS64 ? __alignof__(double) : __alignof__(float); case TextType: return __alignof__(Text_t); case ListType: return __alignof__(List_t); case TableType: return __alignof__(Table_t); diff --git a/src/types.h b/src/types.h index 2a94a512..e5cc008b 100644 --- a/src/types.h +++ b/src/types.h @@ -47,7 +47,7 @@ struct type_s { ByteType, BigIntType, IntType, - NumType, + FloatType, CStringType, TextType, ListType, @@ -77,7 +77,7 @@ struct type_s { } ByteType; struct { enum { TYPE_NBITS32 = 32, TYPE_NBITS64 = 64 } bits; - } NumType; + } FloatType; struct { } CStringType; struct { @@ -131,7 +131,7 @@ struct type_s { #define Type(typetag, ...) new (type_t, .tag = typetag, .__data.typetag = {__VA_ARGS__}) #define INT_TYPE Type(BigIntType) -#define NUM_TYPE Type(NumType, .bits = TYPE_NBITS64) +#define NUM_TYPE Type(FloatType, .bits = TYPE_NBITS64) #define NewFunctionType(ret, ...) \ _make_function_type(ret, sizeof((arg_t[]){__VA_ARGS__}) / sizeof(arg_t), (arg_t[]){__VA_ARGS__}) diff --git a/test/_vectors.tm b/test/_vectors.tm index 84646cc9..85c25ca0 100644 --- a/test/_vectors.tm +++ b/test/_vectors.tm @@ -1 +1 @@ -struct Vec2(x,y:Num) +struct Vec2(x,y:Float64) diff --git a/test/lists.tm b/test/lists.tm index 4e9f769b..832c18ba 100644 --- a/test/lists.tm +++ b/test/lists.tm @@ -1,10 +1,10 @@ func main() do - nums : [Num32] = [] + nums : [Float32] = [] assert nums == [] do - nums : [Num32] + nums : [Float32] assert nums == [] do diff --git a/test/minmax.tm b/test/minmax.tm index 038f03e4..3c6d7efd 100644 --- a/test/minmax.tm +++ b/test/minmax.tm @@ -1,7 +1,7 @@ struct Foo(x:Int, y:Int) - func len(f:Foo->Num) - return Num.sqrt(Num(f.x*f.x + f.y*f.y))! + func len(f:Foo->Float64) + return Float64.sqrt(Float64(f.x*f.x + f.y*f.y))! func main() assert (3 _min_ 5) == 3 diff --git a/test/nums.tm b/test/nums.tm index ef139d0d..9077a67f 100644 --- a/test/nums.tm +++ b/test/nums.tm @@ -8,14 +8,14 @@ func main() assert n - n == 0. - assert Num.PI == 3.141592653589793 + assert Float64.PI == 3.141592653589793 - assert Num.PI.with_precision(0.01) == 3.14 + assert Float64.PI.with_precision(0.01) == 3.14 - assert Num.INF == Num.INF - assert Num.INF.isinf() + assert Float64.INF == Float64.INF + assert Float64.INF.isinf() - none_num : Num? = none + none_num : Float64? = none assert none_num == none assert none_num == none_num assert (none_num < none_num) == no @@ -36,17 +36,17 @@ func main() # >> 0./0. # = none - assert Num.PI.cos()!.near(-1) - assert Num.PI.sin()!.near(0) + assert Float64.PI.cos()!.near(-1) + assert Float64.PI.sin()!.near(0) - assert Num.INF.near(-Num.INF) == no + assert Float64.INF.near(-Float64.INF) == no - assert Num32.sqrt(16) == Num32(4) - assert Num32.sqrt(-1) == none + assert Float32.sqrt(16) == Float32(4) + assert Float32.sqrt(-1) == none assert (0.25).mix(10, 20) == 12.5 assert (2.0).mix(10, 20) == 30. - assert Num(5) == 5. + assert Float64(5) == 5. assert (0.5).percent() == "50%" diff --git a/test/optionals.tm b/test/optionals.tm index 51a78380..f439d998 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -43,7 +43,7 @@ func maybe_text(should_i:Bool->Text?) else return none -func maybe_num(should_i:Bool->Num?) +func maybe_num(should_i:Bool->Float64?) if should_i return 12.3 else diff --git a/test/serialization.tm b/test/serialization.tm index 39c1624f..619ddb1e 100644 --- a/test/serialization.tm +++ b/test/serialization.tm @@ -1,7 +1,7 @@ struct Foo(name:Text, next:@Foo?=none) -enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text)) +enum MyEnum(Zero, One(x:Int), Two(x:Float64, y:Text)) func main() do @@ -74,9 +74,9 @@ func main() assert roundtrip == obj do - >> obj : Num? = none + >> obj : Float64? = none >> bytes : [Byte] = obj - >> roundtrip : Num? = bytes + >> roundtrip : Float64? = bytes assert roundtrip == obj do |
