From 943cf022ea1290a1f20f14d35f59f90bfa2bda74 Mon Sep 17 00:00:00 2001 From: berni44 Date: Mon, 19 Apr 2021 11:39:25 +0200 Subject: [PATCH] std.math: Move some stranded unittests to correct place. --- std/math/algebraic.d | 24 ++++++++++++++ std/math/package.d | 69 ----------------------------------------- std/math/trigonometry.d | 51 ++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 69 deletions(-) diff --git a/std/math/algebraic.d b/std/math/algebraic.d index 98b3d73d7..47b0c8eac 100644 --- a/std/math/algebraic.d +++ b/std/math/algebraic.d @@ -168,6 +168,18 @@ float fabs(float f) @trusted pure nothrow @nogc assert(pfabs != null); } +@safe pure nothrow @nogc unittest +{ + float f = fabs(-2.0f); + assert(f == 2); + + double d = fabs(-2.0); + assert(d == 2); + + real r = fabs(-2.0L); + assert(r == 2); +} + /*************************************** * Compute square root of x. * @@ -217,6 +229,18 @@ real sqrt(real x) @nogc @safe pure nothrow { return core.math.sqrt(x); } enum ZX82 = sqrt(7.0L); } +@safe pure nothrow @nogc unittest +{ + float f = sqrt(2.0f); + assert(fabs(f * f - 2.0f) < .00001); + + double d = sqrt(2.0); + assert(fabs(d * d - 2.0) < .00001); + + real r = sqrt(2.0L); + assert(fabs(r * r - 2.0) < .00001); +} + /*************** * Calculates the cube root of x. * diff --git a/std/math/package.d b/std/math/package.d index 93b4befa3..6f12f4353 100644 --- a/std/math/package.d +++ b/std/math/package.d @@ -409,75 +409,6 @@ if (isUnsigned!F && isUnsigned!G && isUnsigned!H) assert(res2 == 42u); } -@safe pure nothrow @nogc unittest -{ - float f = sqrt(2.0f); - assert(fabs(f * f - 2.0f) < .00001); - - double d = sqrt(2.0); - assert(fabs(d * d - 2.0) < .00001); - - real r = sqrt(2.0L); - assert(fabs(r * r - 2.0) < .00001); -} - -@safe pure nothrow @nogc unittest -{ - float f = fabs(-2.0f); - assert(f == 2); - - double d = fabs(-2.0); - assert(d == 2); - - real r = fabs(-2.0L); - assert(r == 2); -} - -@safe pure nothrow @nogc unittest -{ - float f = sin(-2.0f); - assert(fabs(f - -0.909297f) < .00001); - - double d = sin(-2.0); - assert(fabs(d - -0.909297f) < .00001); - - real r = sin(-2.0L); - assert(fabs(r - -0.909297f) < .00001); -} - -@safe pure nothrow @nogc unittest -{ - float f = cos(-2.0f); - assert(fabs(f - -0.416147f) < .00001); - - double d = cos(-2.0); - assert(fabs(d - -0.416147f) < .00001); - - real r = cos(-2.0L); - assert(fabs(r - -0.416147f) < .00001); -} - -@safe pure nothrow @nogc unittest -{ - float f = tan(-2.0f); - assert(fabs(f - 2.18504f) < .00001); - - double d = tan(-2.0); - assert(fabs(d - 2.18504f) < .00001); - - real r = tan(-2.0L); - assert(fabs(r - 2.18504f) < .00001); - - // Verify correct behavior for large inputs - assert(!isNaN(tan(0x1p63))); - assert(!isNaN(tan(-0x1p63))); - static if (real.mant_dig >= 64) - { - assert(!isNaN(tan(0x1p300L))); - assert(!isNaN(tan(-0x1p300L))); - } -} - package(std): // Not public yet /* Return the value that lies halfway between x and y on the IEEE number line. * diff --git a/std/math/trigonometry.d b/std/math/trigonometry.d index 4b935a795..5833b61ef 100644 --- a/std/math/trigonometry.d +++ b/std/math/trigonometry.d @@ -88,6 +88,20 @@ float cos(float x) @safe pure nothrow @nogc { return core.math.cos(x); } assert(pcos != null); } +@safe pure nothrow @nogc unittest +{ + import std.math : fabs; + + float f = cos(-2.0f); + assert(fabs(f - -0.416147f) < .00001); + + double d = cos(-2.0); + assert(fabs(d - -0.416147f) < .00001); + + real r = cos(-2.0L); + assert(fabs(r - -0.416147f) < .00001); +} + /*********************************** * Returns $(HTTP en.wikipedia.org/wiki/Sine, sine) of x. x is in $(HTTP en.wikipedia.org/wiki/Radian, radians). * @@ -136,6 +150,20 @@ float sin(float x) @safe pure nothrow @nogc { return core.math.sin(x); } assert(psin != null); } +@safe pure nothrow @nogc unittest +{ + import std.math : fabs; + + float f = sin(-2.0f); + assert(fabs(f - -0.909297f) < .00001); + + double d = sin(-2.0); + assert(fabs(d - -0.909297f) < .00001); + + real r = sin(-2.0L); + assert(fabs(r - -0.909297f) < .00001); +} + /**************************************************************************** * Returns tangent of x. x is in radians. * @@ -477,6 +505,29 @@ private T tanImpl(T)(T x) @safe pure nothrow @nogc assert(isClose(tan(PI / 3), sqrt(3.0L), real.sizeof > double.sizeof ? 1e-15 : 1e-14)); } +@safe pure nothrow @nogc unittest +{ + import std.math : fabs, isNaN; + + float f = tan(-2.0f); + assert(fabs(f - 2.18504f) < .00001); + + double d = tan(-2.0); + assert(fabs(d - 2.18504f) < .00001); + + real r = tan(-2.0L); + assert(fabs(r - 2.18504f) < .00001); + + // Verify correct behavior for large inputs + assert(!isNaN(tan(0x1p63))); + assert(!isNaN(tan(-0x1p63))); + static if (real.mant_dig >= 64) + { + assert(!isNaN(tan(0x1p300L))); + assert(!isNaN(tan(-0x1p300L))); + } +} + /*************** * Calculates the arc cosine of x, * returning a value ranging from 0 to $(PI).