-
Notifications
You must be signed in to change notification settings - Fork 6
Functions
The functions file defines basic math functions. Most of the functions are completely generic, the non-generic functions will be converted in the future.
Returns an Int representing the sign of the given number, this is -1, 0 or +1.
protocols to adopt:
- Equatable
- Comparable
- IntegerLiteralConvertible
Returns the factorial of the given number, this is x! .
protocols to adopt:
- Comparable
- Substractable
- Multiplicable
- SetCompliant
- IntegerLiteralConvertible
Returns the factorial values up to (and including) the x'th value. The index corresponds to the parameter for factorial, so factorialsUpTo(10)[5] == factorial(5).
factorialsUpTo(5) == [1, 1, 2, 6, 24, 120]
Returns the x'th Fibonacci number F(x) where F(0) = 0 and F(1) = 1.
protocols to adopt:
- Hashable
- Addable
- Substractable
- IntegerLiteralConvertible
Returns the sum of all elements in the given sequence.
The element type of the sequence must adopt the following protocols:
- Addable
- IntegerLiteralConvertible
Returns the product of all elements in the given sequence.
The element type of the sequence must adopt the following protocols:
- Multiplicable
- IntegerLiteralConvertible
Returns a list of all divisors of the given number, this includes x and 1. The list will be sorted ascending.
protocols to adopt:
- Equatable
- Comparable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns a list of all proper divisors of the given number, this does not include x, but it does include 1. The list will be sorted ascending.
protocols to adopt:
- Equatable
- Comparable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns whether the given number is perfect. This means the sum of its proper divisors equals the number itself. 6 is an example.
protocols to adopt:
- Equatable
- Comparable
- Addable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns whether the given number is abundant. This means the sum of it's proper divisors is bigger than the number itself.
protocols to adopt:
- Equatable
- Comparable
- Addable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns a set containing the abundance up to (and maybe including) the given value.
protocols to adopt:
- Equatable
- Comparable
- Addable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns whether the given number is deficient. This means the sum of it's proper divisors is smaller than the number itself.
protocols to adopt:
- Equatable
- Comparable
- Addable
- Modulable
- Dividable
- RealPowerable, RealPowerType has to adopt Comparable, Addable and IntegerLiteralConvertible
- IntegerLiteralConvertible
Returns the greatest common divisor of the two given numbers.
protocols to adopt:
- Equatable
- Modulable
- IntegerLiteralConvertible
Returns the greatest common divisor of the two given numbers.
protocols to adopt:
- Equatable
- Comparable
- Negatable
- Multiplicable
- Modulable
- IntegerLiteralConvertible