aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrits Talbot <frits@metapathy.com>2013-05-26 00:35:39 +0200
committerAlon Zakai <alonzakai@gmail.com>2013-06-03 13:43:00 -0700
commit3fbfd0bd4b9e03a18fd69223606f2ea2601da798 (patch)
tree29a4964fcb4997393ea84fb760cd6f00ef1bbae4 /tests
parentfef341fbe96eeac85c4f6592a62e11d6f7917487 (diff)
Fix frexp does not accept negative numbers
Add frexp unit tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 47c1f1be..803c1d2b 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1916,6 +1916,47 @@ Succeeded!
expected = open(path_from_root('tests', 'hyperbolic', 'output.txt'), 'r').read()
self.do_run(src, expected)
+ def test_frexp(self):
+ src = '''
+ #include <stdio.h>
+ #include <math.h>
+ #include <assert.h>
+
+ static const double tol=1e-16;
+
+ void test_value(double value)
+ {
+ int exponent;
+ double x=frexp(value, &exponent);
+ double expected=x*pow(2.0, exponent);
+
+ printf("%f=%f*2^%d\\n", value, x, exponent);
+
+ assert(fabs(expected-value)<tol);
+ assert(x==0 || (fabs(x)>=5e-1 && fabs(x)<1)); // x has a magnitude in the interval [1/2, 1)
+ }
+
+ int main()
+ {
+ test_value(0);
+ test_value(100.1);
+ test_value(-100.1);
+ test_value(.5);
+ test_value(-.5);
+ test_value(1-1e-16);
+ test_value(-(1-1e-16));
+
+ return 0;
+ }
+ '''
+ self.do_run(src, '''0.000000=0.000000*2^0
+100.100000=0.782031*2^7
+-100.100000=-0.782031*2^7
+0.500000=0.500000*2^0
+-0.500000=-0.500000*2^0
+1.000000=1.000000*2^0
+-1.000000=-1.000000*2^0''')
+
def test_getgep(self):
# Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP
src = '''