diff options
Diffstat (limited to 'gcc/testsuite/gdc.test/runnable/builtin.d')
-rw-r--r-- | gcc/testsuite/gdc.test/runnable/builtin.d | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/gcc/testsuite/gdc.test/runnable/builtin.d b/gcc/testsuite/gdc.test/runnable/builtin.d index 44817b16ee0..a7f09a378d6 100644 --- a/gcc/testsuite/gdc.test/runnable/builtin.d +++ b/gcc/testsuite/gdc.test/runnable/builtin.d @@ -1,7 +1,5 @@ // RUNNABLE_PHOBOS_TEST - -import std.stdio; -import std.math; +import core.math; import core.bitop; version (DigitalMars) @@ -12,30 +10,31 @@ version (DigitalMars) version = AnyX86; } +bool isClose(real lhs, real rhs, real maxRelDiff = 1e-09L, real maxAbsDiff = 0.0) +{ + if (lhs == rhs) + return true; + if (lhs == lhs.infinity || rhs == rhs.infinity || + lhs == -lhs.infinity || rhs == -rhs.infinity) + return false; + + auto diff = fabs(lhs - rhs); + return diff <= maxRelDiff*fabs(lhs) + || diff <= maxRelDiff*fabs(rhs) + || diff <= maxAbsDiff; +} + /*******************************************/ void test1() { - writefln("%a", sin(6.8L)); auto f = 6.8L; - writefln("%a", sin(f)); assert(sin(f) == sin(6.8L)); - static assert(approxEqual(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2)); + static assert(isClose(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2)); - writefln("%a", cos(6.8L)); f = 6.8L; - writefln("%a", cos(f)); assert(cos(f) == cos(6.8L)); - static assert(approxEqual(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1)); - - writefln("%a", tan(6.8L)); - f = 6.8L; - writefln("%a", tan(f)); - version (Win64) - { } - else - assert(tan(f) == tan(6.8L)); - static assert(approxEqual(tan(6.8L), 0x1.22fd752af75cd08cp-1)); + static assert(isClose(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1)); } /*******************************************/ @@ -55,7 +54,7 @@ void test2() assert(i == 2); } -/**** Bug 5703 *****************************/ +/**** https://issues.dlang.org/show_bug.cgi?id=5703 ****/ static assert({ int a = 0x80; @@ -113,7 +112,5 @@ int main() test1(); test2(); test3(); - - printf("Success\n"); return 0; } |