Mathematics
Source code for the mathematics library
fn power(x: Int, pow: Int) -> Int
{
if (pow <= 0) {
return 1;
}
return (power(x, pow - 1) * x);
}
fn abs(x: Int) -> Int
{
if (x < 0) {
return (x * -1);
}
return x;
}
fn factorial(x: Int) -> Int
{
if (x < 1) {
return x * factorial(x - 1);
}
return 1;
}
fn sum(a: [Int]) -> Int
{
s: Int = 0;
for (i: Int = 0; i < len(a); i++) {
s += a[i];
}
return s;
}
fn isPrime(n: Int) -> Bool
{
if (n <= 1) {
return false;
}
if (n == 2 || n == 3) {
return true;
}
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
for (i: Int = 5; i * i <= n; i = i + 6) {
if ((n % i == 0) || (n % (i + 2) == 0)) {
return false;
}
}
return true;
}Detailed infos
power
abs
factorial
sum
isPrime
Last updated