std.math: Move some stranded unittests to correct place.

This commit is contained in:
berni44 2021-04-19 11:39:25 +02:00 committed by The Dlang Bot
parent 7b4a336bf7
commit 943cf022ea
3 changed files with 75 additions and 69 deletions

View file

@ -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.
*

View file

@ -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.
*

View file

@ -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).