Add log(x, base) function to std::math module.

This commit is contained in:
Dmitry Atamanov
2023-09-15 11:44:09 +05:00
committed by Christoffer Lerno
parent 6be61aa19c
commit d6e9985a26
3 changed files with 42 additions and 22 deletions

View File

@@ -16,23 +16,6 @@ fn void! test_abs() @test
assert(math::abs(yy) == double[<3>] { 1, 0.5, 1000 });
}
fn void! test_sign() @test
{
int x = -21;
assert(math::sign(x) == -1);
x = 238219382;
assert(math::sign(x) == 1);
x = 0;
assert(math::sign(x) == 0);
uint y = 23;
assert(math::sign(y) == 1);
y = 0;
assert(math::sign(y) == 0);
y = (uint)-21;
assert(math::sign(y) == 1);
assert(@typeis(math::sign(y), uint));
}
fn void! test_atan() @test
{
int x = 231;
@@ -109,6 +92,36 @@ fn void! test_floor() @test
assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 });
}
fn void! test_log() @test
{
double x = math::E;
assert(math::log(x, x) == 1.0);
float y = math::E;
assert(math::log(y, y) == 1.0f);
$assert @typeis(math::log(y, y), float);
double[<3>] xx = { 2, 4, 8 };
assert(math::log(xx, 2) == double[<3>] { 1.0, 2.0, 3.0 });
float[<3>] yy = { 10, 100, 1000 };
assert(math::log(yy, 10) == float[<3>] { 1.0, 2.0, 3.0 });
}
fn void! test_sign() @test
{
int x = -21;
assert(math::sign(x) == -1);
x = 238219382;
assert(math::sign(x) == 1);
x = 0;
assert(math::sign(x) == 0);
uint y = 23;
assert(math::sign(y) == 1);
y = 0;
assert(math::sign(y) == 0);
y = (uint)-21;
assert(math::sign(y) == 1);
assert(@typeis(math::sign(y), uint));
}
fn void! test_trunc() @test
{
double d = -123.9;