From: Szabolcs Nagy Date: Sat, 7 Mar 2015 10:00:37 +0000 (+0100) Subject: fix FLT_ROUNDS to reflect the current rounding mode X-Git-Tag: v1.1.7~15 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=559de8f5f06da9022cbba70e22e14a710eb74513;p=oweals%2Fmusl.git 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) --- diff --git a/arch/arm/bits/float.h b/arch/arm/bits/float.h index ec46b94b..c4a655e7 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 c356cba9..dd6e4029 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 ec46b94b..c4a655e7 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 ec46b94b..c4a655e7 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 ec46b94b..c4a655e7 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 ec46b94b..c4a655e7 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 ec46b94b..c4a655e7 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 9ea29914..4d8e7864 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 9ea29914..4d8e7864 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 161e167c..c6429d33 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 00000000..ec0b3689 --- /dev/null +++ b/src/fenv/__flt_rounds.c @@ -0,0 +1,19 @@ +#include +#include + +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; +}