aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/math
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-12 22:05:51 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-12 22:05:51 +0200
commit53b3704180fc57bcf73b933ffa45028a33dab58b (patch)
treeb6e1fd17266da984170ae686c55f98a60140ab90 /test/monniaux/math
parent09db5e13fc268ba5d594d04f767d6e33605eb6a7 (diff)
downloadcompcert-kvx-53b3704180fc57bcf73b933ffa45028a33dab58b.tar.gz
compcert-kvx-53b3704180fc57bcf73b933ffa45028a33dab58b.zip
test breaks
Diffstat (limited to 'test/monniaux/math')
-rw-r--r--test/monniaux/math/test_gsl_pow.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/monniaux/math/test_gsl_pow.c b/test/monniaux/math/test_gsl_pow.c
new file mode 100644
index 00000000..54e53889
--- /dev/null
+++ b/test/monniaux/math/test_gsl_pow.c
@@ -0,0 +1,44 @@
+#include <math.h>
+#include <stdio.h>
+
+double gsl_pow_uint(double x, unsigned int n);
+
+double gsl_pow_int(double x, int n)
+{
+ unsigned int un;
+
+ if(n < 0) {
+ x = 1.0/x;
+ un = -n;
+ } else {
+ un = n;
+ }
+
+ return gsl_pow_uint(x, un);
+}
+
+double gsl_pow_uint(double x, unsigned int n)
+{
+ double value = 1.0;
+
+ /* repeated squaring method
+ * returns 0.0^0 = 1.0, so continuous in x
+ */
+ do {
+ if(n & 1) value *= x; /* for n odd */
+ n >>= 1;
+ x *= x;
+ } while (n);
+
+ return value;
+}
+
+int main() {
+ double y, y_expected;
+ for (int n = -9; n < 10; n++) {
+ y = gsl_pow_int (-3.14, n);
+ y_expected = pow (-3.14, n);
+ printf("%d %g %g\n", n, y, y_expected);
+ }
+ return 0;
+}