This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[libstdc++] numeric_limits: round_style, round_error
- From: Richard Henderson <rth at twiddle dot net>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sat, 21 Sep 2002 15:31:14 -0700
- Subject: [libstdc++] numeric_limits: round_style, round_error
I think it was a bit short-sighted of the standard c++ library
to define round_style as a compile-time constant, rather than a
function that returns the current rounding mode.
But given the situation as-is, our current selection of
round_toward_zero as the default is less than ideal. To my
knowledge, without exception the default for all targets is
round_to_nearest. Personally I don't think it's worth
conditionalizing this at all until we come across a target
that needs a different default (since I don't think that'll
ever happen).
Next, round_error is intimately tied to round_style. When
round_style is round_to_nearest, this value should be 0.5.
While this is a function, not a constant, I think it would
be confusing to vary at runtime when round_style doesn't.
Ok?
r~
* include/std/std_limits.h (__glibcpp_f32_round_error,
__glibcpp_f64_round_error, __glibcpp_f80_round_error,
__glibcpp_f96_round_error, __glibcpp_f128_round_error,
__glibcpp_float_round_error, __glibcpp_double_round_error,
__glibcpp_long_double_round_error, __glibcpp_float_round_style,
__glibcpp_double_round_style, __glibcpp_long_double_round_style): Kill.
(numeric_limits<char>::epsilon, round_error): Use constant 0.
(numeric_limits<float>::round_error): Use constant 0.5.
(numeric_limits<float>::round_style): Use round_to_nearest.
(numeric_limits<double>, numeric_limits<long double>): Similarly.
Index: std_limits.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_limits.h,v
retrieving revision 1.12
diff -u -p -r1.12 std_limits.h
--- std_limits.h 17 Sep 2002 01:28:49 -0000 1.12
+++ std_limits.h 21 Sep 2002 17:55:34 -0000
@@ -150,32 +150,27 @@
#define __glibcpp_u64_digits 64
#define __glibcpp_u64_digits10 19
-#define __glibcpp_f32_round_error 1.0F
#if __GCC_FLOAT_FORMAT__ == __IEEE_FORMAT__
# define __glibcpp_f32_is_iec559 true
#endif
#ifndef __glibcpp_f32_is_iec559
# define __glibcpp_f32_is_iec559 false
#endif
-#define __glibcpp_f64_round_error 1.0
#if __GCC_FLOAT_FORMAT__ == __IEEE_FORMAT__
# define __glibcpp_f64_is_iec559 true
#endif
#ifndef __glibcpp_f64_is_iec559
# define __glibcpp_f64_is_iec559 false
#endif
-#define __glibcpp_f80_round_error 1.0L
#if __GCC_FLOAT_FORMAT__ == __IEEE_FORMAT__
# define __glibcpp_f80_is_iec559 true
#endif
#ifndef __glibcpp_f80_is_iec559
# define __glibcpp_f80_is_iec559 false
#endif
-#define __glibcpp_f96_round_error 1.0L
#if __GCC_FLOAT_FORMAT__ == __IEEE_FORMAT__
# define __glibcpp_f96_is_iec559 true
#endif
-#define __glibcpp_f128_round_error 1.0L
#if __GCC_FLOAT_FORMAT__ == __IEEE_FORMAT__
# define __glibcpp_f128_is_iec559 true
#endif
@@ -503,13 +498,10 @@
//
#if __FLOAT_BIT__ == 32
-# define __glibcpp_float_round_error __glibcpp_f32_round_error
# define __glibcpp_float_is_iec559 __glibcpp_f32_is_iec559
#elif __FLOAT_BIT__ == 64
-# define __glibcpp_float_round_error __glibcpp_f64_round_error
# define __glibcpp_float_is_iec559 __glibcpp_f64_is_iec559
#elif __FLOAT_BIT__ == 80
-# define __glibcpp_float_round_error __glibcpp_f80_round_error
# define __glibcpp_float_is_iec559 __glibcpp_f80_is_iec559
#else
// You must define these macros in the configuration file.
@@ -541,20 +533,13 @@
# define __glibcpp_float_tinyness_before false
#endif
-#ifndef __glibcpp_float_round_style
-# define __glibcpp_float_round_style round_toward_zero
-#endif
-
// double
#if __DOUBLE_BIT__ == 32
-# define __glibcpp_double_round_error __glibcpp_f32_round_error
# define __glibcpp_double_is_iec559 __glibcpp_f32_is_iec559
#elif __DOUBLE_BIT__ == 64
-# define __glibcpp_double_round_error __glibcpp_f64_round_error
# define __glibcpp_double_is_iec559 __glibcpp_f64_is_iec559
#elif __DOUBLE_BIT__ == 80
-# define __glibcpp_double_round_error __glibcpp_f80_round_error
# define __glibcpp_double_is_iec559 __glibcpp_f80_is_iec559
#else
// You must define these macros in the configuration file.
@@ -586,26 +571,17 @@
# define __glibcpp_double_tinyness_before false
#endif
-#ifndef __glibcpp_double_round_style
-# define __glibcpp_double_round_style round_toward_zero
-#endif
-
// long double
#if __LONG_DOUBLE_BIT__ == 32
-# define __glibcpp_long_double_round_error __glibcpp_f32_round_error
# define __glibcpp_long_double_is_iec559 __glibcpp_f32_is_iec559
#elif __LONG_DOUBLE_BIT__ == 64
-# define __glibcpp_long_double_round_error __glibcpp_f64_round_error
# define __glibcpp_long_double_is_iec559 __glibcpp_f64_is_iec559
#elif __LONG_DOUBLE_BIT__ == 80
-# define __glibcpp_long_double_round_error __glibcpp_f80_round_error
# define __glibcpp_long_double_is_iec559 __glibcpp_f80_is_iec559
#elif __LONG_DOUBLE_BIT__ == 96
-# define __glibcpp_long_double_round_error __glibcpp_f96_round_error
# define __glibcpp_long_double_is_iec559 __glibcpp_f96_is_iec559
#elif __LONG_DOUBLE_BIT__ == 128
-# define __glibcpp_long_double_round_error __glibcpp_f128_round_error
# define __glibcpp_long_double_is_iec559 __glibcpp_f128_is_iec559
#else
// You must define these macros in the configuration file.
@@ -637,10 +613,6 @@
# define __glibcpp_long_double_tinyness_before false
#endif
-#ifndef __glibcpp_long_double_round_style
-# define __glibcpp_long_double_round_style round_toward_zero
-#endif
-
namespace std
{
@@ -825,9 +797,9 @@ namespace std
static const bool is_exact = true;
static const int radix = 2;
static char epsilon() throw()
- { return char(); }
+ { return 0; }
static char round_error() throw()
- { return char(); }
+ { return 0; }
static const int min_exponent = 0;
static const int min_exponent10 = 0;
@@ -1505,7 +1477,7 @@ namespace std
static float epsilon() throw()
{ return __FLT_EPSILON__; }
static float round_error() throw()
- { return __glibcpp_float_round_error; }
+ { return 0.5F; }
static const int min_exponent = __FLT_MIN_EXP__;
static const int min_exponent10 = __FLT_MIN_10_EXP__;
@@ -1536,17 +1508,15 @@ namespace std
static const bool traps = __glibcpp_float_traps;
static const bool tinyness_before = __glibcpp_float_tinyness_before;
- static const float_round_style round_style = __glibcpp_float_round_style;
+ static const float_round_style round_style = round_to_nearest;
};
-#undef __glibcpp_float_round_error
#undef __glibcpp_float_has_denorm_loss
#undef __glibcpp_float_is_iec559
#undef __glibcpp_float_is_bounded
#undef __glibcpp_float_is_modulo
#undef __glibcpp_float_traps
#undef __glibcpp_float_tinyness_before
-#undef __glibcpp_float_round_style
template<>
struct numeric_limits<double>
@@ -1567,7 +1537,7 @@ namespace std
static double epsilon() throw()
{ return __DBL_EPSILON__; }
static double round_error() throw()
- { return __glibcpp_double_round_error; }
+ { return 0.5; }
static const int min_exponent = __DBL_MIN_EXP__;
static const int min_exponent10 = __DBL_MIN_10_EXP__;
@@ -1598,18 +1568,15 @@ namespace std
static const bool traps = __glibcpp_double_traps;
static const bool tinyness_before = __glibcpp_double_tinyness_before;
- static const float_round_style round_style =
- __glibcpp_double_round_style;
+ static const float_round_style round_style = round_to_nearest;
};
-#undef __glibcpp_double_round_error
#undef __glibcpp_double_has_denorm_loss
#undef __glibcpp_double_is_iec559
#undef __glibcpp_double_is_bounded
#undef __glibcpp_double_is_modulo
#undef __glibcpp_double_traps
#undef __glibcpp_double_tinyness_before
-#undef __glibcpp_double_round_style
template<>
@@ -1631,7 +1598,7 @@ namespace std
static long double epsilon() throw()
{ return __LDBL_EPSILON__; }
static long double round_error() throw()
- { return __glibcpp_long_double_round_error; }
+ { return 0.5L; }
static const int min_exponent = __LDBL_MIN_EXP__;
static const int min_exponent10 = __LDBL_MIN_10_EXP__;
@@ -1663,19 +1630,16 @@ namespace std
static const bool traps = __glibcpp_long_double_traps;
static const bool tinyness_before = __glibcpp_long_double_tinyness_before;
- static const float_round_style round_style =
- __glibcpp_long_double_round_style;
+ static const float_round_style round_style = round_to_nearest;
};
-#undef __glibcpp_long_double_round_error
#undef __glibcpp_long_double_has_denorm_loss
#undef __glibcpp_long_double_is_iec559
#undef __glibcpp_long_double_is_bounded
#undef __glibcpp_long_double_is_modulo
#undef __glibcpp_long_double_traps
#undef __glibcpp_long_double_tinyness_before
-#undef __glibcpp_long_double_round_style
-
+
} // namespace std
#endif // _CPP_NUMERIC_LIMITS