Skip to content

Commit

Permalink
[ARM] Fix phobos unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpf91 committed Jan 15, 2014
1 parent 8b4e152 commit 8b124e4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
5 changes: 3 additions & 2 deletions std/format.d
Expand Up @@ -591,12 +591,13 @@ uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, S args)

unittest
{
import std.math;
string s = " 1.2 3.4 ";
double x, y, z;
assert(formattedRead(s, " %s %s %s ", &x, &y, &z) == 2);
assert(s.empty);
assert(x == 1.2);
assert(y == 3.4);
assert(approxEqual(x, 1.2));
assert(approxEqual(y, 3.4));
assert(isnan(z));
}

Expand Down
5 changes: 3 additions & 2 deletions std/getopt.d
Expand Up @@ -660,6 +660,7 @@ private void setConfig(ref configuration cfg, config option)

unittest
{
import std.math;
uint paranoid = 2;
string[] args = (["program.name",
"--paranoid", "--paranoid", "--paranoid"]).dup;
Expand Down Expand Up @@ -706,8 +707,8 @@ unittest
getopt(args, "tune", &tuningParms);
assert(args.length == 1);
assert(tuningParms.length == 2);
assert(tuningParms["alpha"] == 0.5);
assert(tuningParms["beta"] == 0.6);
assert(approxEqual(tuningParms["alpha"], 0.5));
assert(approxEqual(tuningParms["beta"], 0.6));

uint verbosityLevel = 1;
void myHandler(string option)
Expand Down
6 changes: 3 additions & 3 deletions std/internal/math/errorfunction.d
Expand Up @@ -215,15 +215,15 @@ unittest {

assert(feqrel(erfc(0.250L), erfc0_250 )>=real.mant_dig-1);
assert(feqrel(erfc(0.375L), erfc0_375 )>=real.mant_dig-0);
assert(feqrel(erfc(0.500L), erfc0_500 )>=real.mant_dig-1);
assert(feqrel(erfc(0.500L), erfc0_500 )>=real.mant_dig-2);
assert(feqrel(erfc(0.625L), erfc0_625 )>=real.mant_dig-1);
assert(feqrel(erfc(0.750L), erfc0_750 )>=real.mant_dig-1);
assert(feqrel(erfc(0.875L), erfc0_875 )>=real.mant_dig-4);
assert(feqrel(erfc(1.000L), erfc1_000 )>=real.mant_dig-0);
assert(feqrel(erfc(1.000L), erfc1_000 )>=real.mant_dig-2);
assert(feqrel(erfc(1.125L), erfc1_125 )>=real.mant_dig-2);
assert(feqrel(erf(0.875L), erf0_875 )>=real.mant_dig-1);
// The DMC implementation of erfc() fails this next test (just)
assert(feqrel(erfc(4.1L),0.67000276540848983727e-8L)>=real.mant_dig-4);
assert(feqrel(erfc(4.1L),0.67000276540848983727e-8L)>=real.mant_dig-5);

assert(isIdentical(erf(0.0),0.0));
assert(isIdentical(erf(-0.0),-0.0));
Expand Down
44 changes: 32 additions & 12 deletions std/math.d
Expand Up @@ -1824,7 +1824,7 @@ L_was_nan:

unittest
{
assert(exp2(0.5L)== SQRT2);
assert(feqrel(exp2(0.5L), SQRT2) >= real.mant_dig -1);
assert(exp2(8.0L) == 256.0);
assert(exp2(-9.0L)== 1.0L/512.0);
assert( core.stdc.math.exp2f(0.0f) == 1 );
Expand Down Expand Up @@ -2228,14 +2228,27 @@ real ldexp(real n, int exp) @safe pure nothrow; /* intrinsic */

unittest
{
assert(ldexp(1, -16384) == 0x1p-16384L);
assert(ldexp(1, -16382) == 0x1p-16382L);
int x;
real n = frexp(0x1p-16384L, x);
assert(n==0.5L);
assert(x==-16383);
assert(ldexp(n, x)==0x1p-16384L);

static if(real.mant_dig == 64)
{
assert(ldexp(1, -16384) == 0x1p-16384L);
assert(ldexp(1, -16382) == 0x1p-16382L);
int x;
real n = frexp(0x1p-16384L, x);
assert(n==0.5L);
assert(x==-16383);
assert(ldexp(n, x)==0x1p-16384L);
}
else static if(real.mant_dig == 53)
{
assert(ldexp(1, -1024) == 0x1p-1024L);
assert(ldexp(1, -1022) == 0x1p-1022L);
int x;
real n = frexp(0x1p-1024L, x);
assert(n==0.5L);
assert(x==-1023);
assert(ldexp(n, x)==0x1p-1024L);
}
else static assert(false, "Floating point type real not supported");
}

unittest
Expand Down Expand Up @@ -2960,7 +2973,7 @@ unittest
real y = vals[i][1];
real z = vals[i][2];
real h = hypot(x, y);
assert(isIdentical(z, h));
assert(isIdentical(z,h) || feqrel(z, h) >= real.mant_dig - 1);
}
}

Expand Down Expand Up @@ -4805,13 +4818,17 @@ unittest
{
pragma(msg, "test disabled on x86_64, see bug 5628");
}
else version(ARM)
{
pragma(msg, "test disabled on ARM, see bug 5628");
}
else
{
assert(pow(xd, neg2) == 1 / (x * x));
assert(pow(xf, neg8) == 1 / ((x * x) * (x * x) * (x * x) * (x * x)));
}

assert(pow(x, neg3) == 1 / (x * x * x));
assert(feqrel(pow(x, neg3), 1 / (x * x * x)) >= real.mant_dig - 1);
}

unittest
Expand Down Expand Up @@ -5324,7 +5341,10 @@ unittest
}

assert(feqrel(7.1824L, 7.1824L) == real.mant_dig);
assert(feqrel(real.min_normal / 8, real.min_normal / 17) == 3);
static if(real.mant_dig == 64)
{
assert(feqrel(real.min_normal / 8, real.min_normal / 17) == 3);
}

testFeqrel!(real)();
testFeqrel!(double)();
Expand Down
2 changes: 1 addition & 1 deletion std/traits.d
Expand Up @@ -5793,7 +5793,7 @@ template Largest(T...) if(T.length >= 1)

unittest
{
static assert(is(Largest!(uint, ubyte, ulong, real) == real));
static assert(is(Largest!(uint, ubyte, ushort, real) == real));
static assert(is(Largest!(ulong, double) == ulong));
static assert(is(Largest!(double, ulong) == double));
static assert(is(Largest!(uint, byte, double, short) == double));
Expand Down

0 comments on commit 8b124e4

Please sign in to comment.