aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2015-03-07 11:00:37 +0100
committerRich Felker <dalias@aerifal.cx>2015-03-07 12:05:28 -0500
commit559de8f5f06da9022cbba70e22e14a710eb74513 (patch)
treef8980299d0f0a77f4a613c2fc58ada81b789aa66
parentbd67959f3ad5049c35af0a0e2f8f1a1e60577a49 (diff)
downloadmusl-559de8f5f06da9022cbba70e22e14a710eb74513.zip
musl-559de8f5f06da9022cbba70e22e14a710eb74513.tar.gz
musl-559de8f5f06da9022cbba70e22e14a710eb74513.tar.bz2
fix FLT_ROUNDS to reflect the current rounding mode
Implemented as a wrapper around fegetround introducing a new function to the ABI: __flt_rounds. (fegetround cannot be used directly from float.h)
-rw-r--r--arch/arm/bits/float.h1
-rw-r--r--arch/i386/bits/float.h1
-rw-r--r--arch/microblaze/bits/float.h1
-rw-r--r--arch/mips/bits/float.h1
-rw-r--r--arch/or1k/bits/float.h1
-rw-r--r--arch/powerpc/bits/float.h1
-rw-r--r--arch/sh/bits/float.h1
-rw-r--r--arch/x32/bits/float.h1
-rw-r--r--arch/x86_64/bits/float.h1
-rw-r--r--include/float.h3
-rw-r--r--src/fenv/__flt_rounds.c19
11 files changed, 22 insertions, 9 deletions
diff --git a/arch/arm/bits/float.h b/arch/arm/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/arm/bits/float.h
+++ b/arch/arm/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/i386/bits/float.h b/arch/i386/bits/float.h
index c356cba..dd6e402 100644
--- a/arch/i386/bits/float.h
+++ b/arch/i386/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#ifdef __FLT_EVAL_METHOD__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
diff --git a/arch/microblaze/bits/float.h b/arch/microblaze/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/microblaze/bits/float.h
+++ b/arch/microblaze/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/mips/bits/float.h b/arch/mips/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/mips/bits/float.h
+++ b/arch/mips/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/or1k/bits/float.h b/arch/or1k/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/or1k/bits/float.h
+++ b/arch/or1k/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/powerpc/bits/float.h b/arch/powerpc/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/powerpc/bits/float.h
+++ b/arch/powerpc/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/sh/bits/float.h b/arch/sh/bits/float.h
index ec46b94..c4a655e 100644
--- a/arch/sh/bits/float.h
+++ b/arch/sh/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#define FLT_EVAL_METHOD 0
#define LDBL_TRUE_MIN 4.94065645841246544177e-324L
diff --git a/arch/x32/bits/float.h b/arch/x32/bits/float.h
index 9ea2991..4d8e786 100644
--- a/arch/x32/bits/float.h
+++ b/arch/x32/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#ifdef __FLT_EVAL_METHOD__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
diff --git a/arch/x86_64/bits/float.h b/arch/x86_64/bits/float.h
index 9ea2991..4d8e786 100644
--- a/arch/x86_64/bits/float.h
+++ b/arch/x86_64/bits/float.h
@@ -1,4 +1,3 @@
-#define FLT_ROUNDS 1
#ifdef __FLT_EVAL_METHOD__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
diff --git a/include/float.h b/include/float.h
index 161e167..c6429d3 100644
--- a/include/float.h
+++ b/include/float.h
@@ -1,6 +1,9 @@
#ifndef _FLOAT_H
#define _FLOAT_H
+int __flt_rounds(void);
+#define FLT_ROUNDS (__flt_rounds())
+
#define FLT_RADIX 2
#define FLT_TRUE_MIN 1.40129846432481707092e-45F
diff --git a/src/fenv/__flt_rounds.c b/src/fenv/__flt_rounds.c
new file mode 100644
index 0000000..ec0b368
--- /dev/null
+++ b/src/fenv/__flt_rounds.c
@@ -0,0 +1,19 @@
+#include <float.h>
+#include <fenv.h>
+
+int __flt_rounds()
+{
+ switch (fegetround()) {
+#ifdef FE_TOWARDZERO
+ case FE_TOWARDZERO: return 0;
+#endif
+ case FE_TONEAREST: return 1;
+#ifdef FE_UPWARD
+ case FE_UPWARD: return 2;
+#endif
+#ifdef FE_DOWNWARD
+ case FE_DOWNWARD: return 3;
+#endif
+ }
+ return -1;
+}