feat(numeric): add remaining standard math functions and the corresponding testing
This commit is contained in:
parent
bd68754903
commit
c96995ea92
@ -123,6 +123,94 @@ void TestBit()
|
||||
|
||||
void TestMath()
|
||||
{
|
||||
always_check( Math::IsWithin(0, 0, 1));
|
||||
always_check(!Math::IsWithin(1, 0, 1));
|
||||
always_check(!Math::IsWithin(2, 0, 1));
|
||||
|
||||
always_check( Math::IsWithinInclusive(0, 0, 1));
|
||||
always_check( Math::IsWithinInclusive(1, 0, 1));
|
||||
always_check(!Math::IsWithinInclusive(2, 0, 1));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(2.00), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(2.25), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(2.75), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(3.00), 3.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(-2.00), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(-2.25), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(-2.75), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Trunc(-3.00), -3.0, 1e-8));
|
||||
|
||||
always_check(Math::TruncTo<int>(2.00) == 2);
|
||||
always_check(Math::TruncTo<int>(2.25) == 2);
|
||||
always_check(Math::TruncTo<int>(2.75) == 2);
|
||||
always_check(Math::TruncTo<int>(3.00) == 3);
|
||||
|
||||
always_check(Math::TruncTo<int>(-2.00) == -2);
|
||||
always_check(Math::TruncTo<int>(-2.25) == -2);
|
||||
always_check(Math::TruncTo<int>(-2.75) == -2);
|
||||
always_check(Math::TruncTo<int>(-3.00) == -3);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(2.00), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(2.25), 3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(2.75), 3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(3.00), 3.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(-2.00), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(-2.25), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(-2.75), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Ceil(-3.00), -3.0, 1e-8));
|
||||
|
||||
always_check(Math::CeilTo<int>(2.00) == 2);
|
||||
always_check(Math::CeilTo<int>(2.25) == 3);
|
||||
always_check(Math::CeilTo<int>(2.75) == 3);
|
||||
always_check(Math::CeilTo<int>(3.00) == 3);
|
||||
|
||||
always_check(Math::CeilTo<int>(-2.00) == -2);
|
||||
always_check(Math::CeilTo<int>(-2.25) == -2);
|
||||
always_check(Math::CeilTo<int>(-2.75) == -2);
|
||||
always_check(Math::CeilTo<int>(-3.00) == -3);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(2.00), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(2.25), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(2.75), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(3.00), 3.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(-2.00), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(-2.25), -3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(-2.75), -3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Floor(-3.00), -3.0, 1e-8));
|
||||
|
||||
always_check(Math::FloorTo<int>(2.00) == 2);
|
||||
always_check(Math::FloorTo<int>(2.25) == 2);
|
||||
always_check(Math::FloorTo<int>(2.75) == 2);
|
||||
always_check(Math::FloorTo<int>(3.00) == 3);
|
||||
|
||||
always_check(Math::FloorTo<int>(-2.00) == -2);
|
||||
always_check(Math::FloorTo<int>(-2.25) == -3);
|
||||
always_check(Math::FloorTo<int>(-2.75) == -3);
|
||||
always_check(Math::FloorTo<int>(-3.00) == -3);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Round(2.00), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(2.25), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(2.75), 3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(3.00), 3.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Round(-2.00), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(-2.25), -2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(-2.75), -3.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Round(-3.00), -3.0, 1e-8));
|
||||
|
||||
always_check(Math::RoundTo<int>(2.00) == 2);
|
||||
always_check(Math::RoundTo<int>(2.25) == 2);
|
||||
always_check(Math::RoundTo<int>(2.75) == 3);
|
||||
always_check(Math::RoundTo<int>(3.00) == 3);
|
||||
|
||||
always_check(Math::RoundTo<int>(-2.00) == -2);
|
||||
always_check(Math::RoundTo<int>(-2.25) == -2);
|
||||
always_check(Math::RoundTo<int>(-2.75) == -3);
|
||||
always_check(Math::RoundTo<int>(-3.00) == -3);
|
||||
|
||||
always_check(Math::Abs(-1) == 1);
|
||||
always_check(Math::Abs( 0) == 0);
|
||||
always_check(Math::Abs( 1) == 1);
|
||||
@ -136,6 +224,50 @@ void TestMath()
|
||||
always_check(Math::Max(1, 2, 3, 4, 5) == 5);
|
||||
always_check(Math::Max(5, 4, 3, 2, 1) == 5);
|
||||
|
||||
always_check(Math::MinIndex(1, 2, 3, 4, 5) == 0);
|
||||
always_check(Math::MinIndex(5, 4, 3, 2, 1) == 4);
|
||||
always_check(Math::MaxIndex(1, 2, 3, 4, 5) == 4);
|
||||
always_check(Math::MaxIndex(5, 4, 3, 2, 1) == 0);
|
||||
|
||||
always_check(Math::Div( 5, 2).Quotient == 2);
|
||||
always_check(Math::Div( 5, 2).Remainder == 1);
|
||||
always_check(Math::Div( 5, -2).Quotient == -2);
|
||||
always_check(Math::Div( 5, -2).Remainder == 1);
|
||||
always_check(Math::Div(-5, 2).Quotient == -2);
|
||||
always_check(Math::Div(-5, 2).Remainder == -1);
|
||||
always_check(Math::Div(-5, -2).Quotient == 2);
|
||||
always_check(Math::Div(-5, -2).Remainder == -1);
|
||||
|
||||
always_check(Math::DivAndCeil(4 + 0, 4) == 1);
|
||||
always_check(Math::DivAndCeil(4 + 1, 4) == 2);
|
||||
always_check(Math::DivAndCeil(4 + 3, 4) == 2);
|
||||
always_check(Math::DivAndCeil(4 + 4, 4) == 2);
|
||||
|
||||
always_check(Math::DivAndCeil(-4 - 0, 4) == -1);
|
||||
always_check(Math::DivAndCeil(-4 - 1, 4) == -1);
|
||||
always_check(Math::DivAndCeil(-4 - 3, 4) == -1);
|
||||
always_check(Math::DivAndCeil(-4 - 4, 4) == -2);
|
||||
|
||||
always_check(Math::DivAndFloor(4 + 0, 4) == 1);
|
||||
always_check(Math::DivAndFloor(4 + 1, 4) == 1);
|
||||
always_check(Math::DivAndFloor(4 + 3, 4) == 1);
|
||||
always_check(Math::DivAndFloor(4 + 4, 4) == 2);
|
||||
|
||||
always_check(Math::DivAndFloor(-4 - 0, 4) == -1);
|
||||
always_check(Math::DivAndFloor(-4 - 1, 4) == -2);
|
||||
always_check(Math::DivAndFloor(-4 - 3, 4) == -2);
|
||||
always_check(Math::DivAndFloor(-4 - 4, 4) == -2);
|
||||
|
||||
always_check(Math::DivAndRound(4 + 0, 4) == 1);
|
||||
always_check(Math::DivAndRound(4 + 1, 4) == 1);
|
||||
always_check(Math::DivAndRound(4 + 3, 4) == 2);
|
||||
always_check(Math::DivAndRound(4 + 4, 4) == 2);
|
||||
|
||||
always_check(Math::DivAndRound(-4 - 0, 4) == -1);
|
||||
always_check(Math::DivAndRound(-4 - 1, 4) == -1);
|
||||
always_check(Math::DivAndRound(-4 - 3, 4) == -2);
|
||||
always_check(Math::DivAndRound(-4 - 4, 4) == -2);
|
||||
|
||||
always_check(Math::IsNearlyEqual(4.0, 4.0));
|
||||
|
||||
always_check(Math::IsNearlyZero(0.0));
|
||||
@ -167,6 +299,311 @@ void TestMath()
|
||||
enum class ETest : uint16 { A = 65535 };
|
||||
|
||||
always_check(Math::NaNPayload<ETest>(Math::NaN<float32>(ETest::A)) == ETest::A);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(5.0, 2.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(5.0, 2.5), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(5.0, 3.0), 2.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(-5.0, 2.0), -1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(-5.0, 2.5), -0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::FMod(-5.0, 3.0), -2.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(5.0, 2.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(5.0, 2.5), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(5.0, 3.0), -1.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(-5.0, 2.0), -1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(-5.0, 2.5), -0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Remainder(-5.0, 3.0), 1.0, 1e-8));
|
||||
|
||||
always_check(Math::RemQuo(5.0, 2.0).Quotient == 2);
|
||||
always_check(Math::RemQuo(5.0, 2.5).Quotient == 2);
|
||||
always_check(Math::RemQuo(5.0, 3.0).Quotient == 2);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(5.0, 2.0).Remainder, 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(5.0, 2.5).Remainder, 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(5.0, 3.0).Remainder, -1.0, 1e-8));
|
||||
|
||||
always_check(Math::RemQuo(-5.0, 2.0).Quotient == -2);
|
||||
always_check(Math::RemQuo(-5.0, 2.5).Quotient == -2);
|
||||
always_check(Math::RemQuo(-5.0, 3.0).Quotient == -2);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(-5.0, 2.0).Remainder, -1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(-5.0, 2.5).Remainder, -0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RemQuo(-5.0, 3.0).Remainder, 1.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::ModF(123.456).IntegralPart, 123.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::ModF(123.456).FractionalPart, 0.456, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Exp(-1.5), 0.2231301601, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp(-1.0), 0.3678794412, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp( 0.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp( 1.0), 2.7182818284, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp( 1.5), 4.4816890703, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Exp2(-1.5), 0.3535533906, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp2(-1.0), 0.5000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp2( 0.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp2( 1.0), 2.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Exp2( 1.5), 2.8284271247, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::ExpMinus1(-1.5), -0.7768698398, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::ExpMinus1(-1.0), -0.6321205588, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::ExpMinus1( 0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::ExpMinus1( 1.0), 1.7182818284, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::ExpMinus1( 1.5), 3.4816890703, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Log(0.5), -0.6931471806, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log(1.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log(1.5), 0.4054651081, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log(2.0), 0.6931471806, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log(2.5), 0.9162907319, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Log2(0.5), -1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log2(1.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log2(1.5), 0.5849625007, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log2(2.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log2(2.5), 1.3219280949, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Log10(0.5), -0.3010299957, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log10(1.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log10(1.5), 0.1760912591, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log10(2.0), 0.3010299957, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log10(2.5), 0.3979400087, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Log1Plus(0.5), 0.4054651081, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log1Plus(1.0), 0.6931471806, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log1Plus(1.5), 0.9162907319, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log1Plus(2.0), 1.0986122887, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Log1Plus(2.5), 1.2527629685, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Square(0.0), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Square(1.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Square(2.0), 4.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Square(3.0), 9.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Cube(0.0), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cube(1.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cube(2.0), 8.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cube(3.0), 27.0, 1e-8));
|
||||
|
||||
always_check(Math::Pow(2, 0) == 1);
|
||||
always_check(Math::Pow(2, 1) == 2);
|
||||
always_check(Math::Pow(2, 2) == 4);
|
||||
always_check(Math::Pow(2, 3) == 8);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Pow(2.0, 0.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Pow(2.0, 1.0), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Pow(2.0, 2.0), 4.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Pow(2.0, 3.0), 8.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(0), 0, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(1), 1, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(4), 2, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(8), 2, 1));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(1.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(2.0), 1.4142135624, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sqrt(3.0), 1.7320508076, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(0), 0, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(1), 1, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(4), 1, 1));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(8), 2, 1));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(1.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(2.0), 1.2599210499, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cbrt(3.0), 1.4422495703, 1e-8));
|
||||
|
||||
always_check(Math::Sum(1, 2, 3, 4, 5) == 15);
|
||||
|
||||
always_check(Math::SquaredSum(1, 2, 3, 4, 5) == 55);
|
||||
|
||||
always_check(Math::Avg(1, 2, 3, 4, 5) == 3);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Hypot(1.0, 2.0, 3.0, 4.0, 5.0), 7.4161984871, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Sin(-9.0), -0.4121184852, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin(-6.0), 0.2794154982, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin(-2.0), -0.9092974268, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin(-1.0), -0.8414709848, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin( 0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin( 1.0), 0.8414709848, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin( 2.0), 0.9092974268, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin( 6.0), -0.2794154982, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Sin( 9.0), 0.4121184852, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Cos(-9.0), -0.9111302619, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos(-6.0), 0.9601702866, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos(-2.0), -0.4161468365, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos(-1.0), 0.5403023059, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos( 0.0), 1.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos( 1.0), 0.5403023059, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos( 2.0), -0.4161468365, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos( 6.0), 0.9601702866, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Cos( 9.0), -0.9111302619, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Tan(-9.0), 0.4523156594, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan(-6.0), 0.2910061914, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan(-2.0), 2.1850398633, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan(-1.0), -1.5574077247, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan( 0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan( 1.0), 1.5574077247, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan( 2.0), -2.1850398633, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan( 6.0), -0.2910061914, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Tan( 9.0), -0.4523156594, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Asin(-1.0), -1.5707963268, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Asin(-0.5), -0.5235987756, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Asin( 0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Asin( 0.5), 0.5235987756, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Asin( 1.0), 1.5707963268, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Acos(-1.0), 3.1415926536, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Acos(-0.5), 2.0943951024, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Acos( 0.0), 1.5707963268, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Acos( 0.5), 1.0471975512, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Acos( 1.0), 0.0000000000, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Atan(-1.0), -0.7853981634, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan(-0.5), -0.4636476090, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan( 0.0), 0.0000000000, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan( 0.5), 0.4636476090, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan( 1.0), 0.7853981634, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Atan2(-1.0, -1.0), -2.3561944902, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan2(-0.5, -1.0), -2.6779450446, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan2( 0.0, -1.0), 3.1415926536, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan2( 0.5, -1.0), 2.6779450446, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Atan2( 1.0, -1.0), 2.3561944902, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh(-9.0), -4051.5419020, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh(-6.0), -201.71315737, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh(-2.0), -3.6268604078, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh(-1.0), -1.1752011936, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh( 0.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh( 1.0), 1.1752011936, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh( 2.0), 3.6268604078, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh( 6.0), 201.71315737, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Sinh( 9.0), 4051.5419020, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh(-9.0), 4051.5420254, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh(-6.0), 201.71563612, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh(-2.0), 3.7621956911, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh(-1.0), 1.5430806348, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh( 0.0), 1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh( 1.0), 1.5430806348, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh( 2.0), 3.7621956911, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh( 6.0), 201.71563612, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Cosh( 9.0), 4051.5420254, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh(-9.0), -1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh(-6.0), -1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh(-2.0), -0.9640275801, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh(-1.0), -0.7615941559, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh( 0.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh( 1.0), 0.7615941559, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh( 2.0), 0.9640275801, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh( 6.0), 1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Tanh( 9.0), 1.0000000000, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh(-9.0), -2.8934439858, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh(-6.0), -2.4917798526, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh(-2.0), -1.4436354752, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh(-1.0), -0.8813735870, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh( 0.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh( 1.0), 0.8813735870, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh( 2.0), 1.4436354752, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh( 6.0), 2.4917798526, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Asinh( 9.0), 2.8934439858, 1e-4));
|
||||
|
||||
always_check(Math::IsNaN( Math::Acosh(-9.0) ));
|
||||
always_check(Math::IsNaN( Math::Acosh(-6.0) ));
|
||||
always_check(Math::IsNaN( Math::Acosh(-2.0) ));
|
||||
always_check(Math::IsNaN( Math::Acosh(-1.0) ));
|
||||
always_check(Math::IsNaN( Math::Acosh( 0.0) ));
|
||||
always_check(Math::IsNearlyEqual(Math::Acosh( 1.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Acosh( 2.0), 1.3169578969, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Acosh( 6.0), 2.4778887302, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Acosh( 9.0), 2.8872709503, 1e-4));
|
||||
|
||||
always_check(Math::IsInfinity( Math::Atanh(-1.0) ));
|
||||
always_check(Math::IsNearlyEqual(Math::Atanh(-0.5), -0.5493061443, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Atanh( 0.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Atanh( 0.5), 0.5493061443, 1e-4));
|
||||
always_check(Math::IsInfinity( Math::Atanh( 1.0) ));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Erf(-6.0), -1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf(-2.0), -0.9953222650, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf(-1.0), -0.8427007929, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf( 0.0), 0.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf( 1.0), 0.8427007929, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf( 2.0), 0.9953222650, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erf( 6.0), 1.0000000000, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc(-6.0), 2.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc(-2.0), 1.9953222650, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc(-1.0), 1.8427007929, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc( 0.0), 1.0000000000, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc( 1.0), 0.1572992070, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc( 2.0), 0.0046777349, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Erfc( 6.0), 0.0000000000, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma(-0.75), -4.8341465442, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma(-0.50), -3.5449077018, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma(-0.25), -4.9016668098, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma( 0.25), 3.6256099082, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma( 0.50), 1.7724538509, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::Gamma( 0.75), 1.2254167025, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma(-0.75), 1.5757045971, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma(-0.50), 1.2655121235, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma(-0.25), 1.5895753125, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma( 0.25), 1.2880225246, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma( 0.50), 0.5723649429, 1e-4));
|
||||
always_check(Math::IsNearlyEqual(Math::LogGamma( 0.75), 0.2032809514, 1e-4));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::LdExp(1.0, 0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::LdExp(1.0, 1), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::LdExp(1.0, 2), 4.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::LdExp(1.0, 3), 8.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::RadiansToDegrees(0.0), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RadiansToDegrees(Math::TNumbers<float64>::Pi), 180.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::RadiansToDegrees(Math::TNumbers<float64>::TwoPi), 360.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::DegreesToRadians( 0.0), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::DegreesToRadians(180.0), Math::TNumbers<float64>::Pi, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::DegreesToRadians(360.0), Math::TNumbers<float64>::TwoPi, 1e-8));
|
||||
|
||||
always_check(Math::GCD(0, 0) == 0);
|
||||
always_check(Math::GCD(0, 1) == 1);
|
||||
always_check(Math::GCD(9, 6) == 3);
|
||||
|
||||
always_check(Math::LCM(0, 0) == 0);
|
||||
always_check(Math::LCM(0, 1) == 0);
|
||||
always_check(Math::LCM(9, 6) == 18);
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Clamp(0.0, 1.0, 2.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Clamp(1.0, 1.0, 2.0), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Clamp(2.0, 1.0, 2.0), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Clamp(3.0, 1.0, 2.0), 2.0, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::WrappingClamp(0.5, 0.0, 2.0), 0.5, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::WrappingClamp(1.5, 0.0, 2.0), 1.5, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::WrappingClamp(2.5, 0.0, 2.0), 0.5, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::WrappingClamp(3.5, 0.0, 2.0), 1.5, 1e-8));
|
||||
|
||||
always_check(Math::IsNearlyEqual(Math::Lerp(0.0, 2.0, 0.0), 0.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Lerp(0.0, 2.0, 0.5), 1.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Lerp(0.0, 2.0, 1.0), 2.0, 1e-8));
|
||||
always_check(Math::IsNearlyEqual(Math::Lerp(0.0, 2.0, 1.5), 3.0, 1e-8));
|
||||
|
||||
always_check(static_cast<uint8>(Math::LerpStable(0, 255, 0.0)) == 0);
|
||||
always_check(static_cast<uint8>(Math::LerpStable(0, 255, 0.5)) == 127);
|
||||
always_check(static_cast<uint8>(Math::LerpStable(0, 255, 1.0)) == 255);
|
||||
}
|
||||
|
||||
NAMESPACE_END(Testing)
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user