lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] add mc_enum<rounding_style>


From: Vaclav Slavik
Subject: [lmi] add mc_enum<rounding_style>
Date: Thu, 25 Feb 2010 18:45:42 +0100

Hi,

this patch adds mc_enum<rounding_style>. rounding_style is still used as
"raw" enum elsewhere. This is used by upcoming XML serialization
patches.

rounding_style_strings uses human-readable forms for consistency with
other mc_enum<> strings.

Thanks,
Vaclav

--- mc_enum_type_enums.hpp    (revision 4777)
+++ mc_enum_type_enums.hpp        (working copy)
@@ -72,6 +72,24 @@ enum mcenum_mode
     ,mce_monthly    = 12
     };
 
+// See HTML documentation.
+enum rounding_style
+    {r_indeterminate = -1
+    ,r_toward_zero   =  0
+    ,r_to_nearest    =  1 // See note below.
+    ,r_upward        =  2
+    ,r_downward      =  3
+    ,r_current       =  4
+    ,r_not_at_all    =  5
+
+    // Note: 'r_to_nearest' means bankers rounding, which
+    // rounds halfway cases to even:
+    //   x - (x REM 1.0)
+    // as in the C99 remainder() function [7.12.10.2/2], instead of
+    // rounding halfway cases away from zero, as the C99 round()
+    // function does [7.12.9.6/2]. See the HTML documentation.
+    };
+
 #include "mc_enum_types.xpp"
 
 #define MC_DEFINE_ENUMS(TYPE) \
--- mc_enum_types.cpp    (revision 4777)
+++ mc_enum_types.cpp        (working copy)
@@ -84,6 +84,26 @@ extern char const*const emission_strings[] =
     };
 template class mc_enum<mcenum_emission>;
 
+extern rounding_style const rounding_style_enums[] =
+    {r_indeterminate
+    ,r_toward_zero
+    ,r_to_nearest
+    ,r_upward
+    ,r_downward
+    ,r_current
+    ,r_not_at_all
+    };
+extern char const*const rounding_style_strings[] =
+    {"Indeterminate"
+    ,"Toward zero"
+    ,"To nearest"
+    ,"Upward"
+    ,"Downward"
+    ,"Current"
+    ,"Not at all"
+    };
+template class mc_enum<rounding_style>;
+
 #include "mc_enum_types.xpp"
 
 #define MC_DEFINE(TYPE) \
--- mc_enum_types.hpp    (revision 4777)
+++ mc_enum_types.hpp        (working copy)
@@ -45,6 +45,12 @@ template<> struct mc_enum_key<mcenum_emission>
   :public mc_enum_data<mcenum_emission, 11, emission_enums, emission_strings> 
{};
 typedef mc_enum<mcenum_emission> e_emission;
 
+extern rounding_style const rounding_style_enums[7];
+extern char const*const rounding_style_strings[7];
+template<> struct mc_enum_key<rounding_style>
+  :public mc_enum_data<rounding_style, 7, rounding_style_enums, 
rounding_style_strings> {};
+typedef mc_enum<rounding_style> mce_rounding_style;
+
 #define MC_DECLARE(TYPE,NUMBER) \
 extern mcenum_##TYPE const TYPE##_enums[NUMBER]; \
 extern char const*const TYPE##_strings[NUMBER]; \
--- round_to.hpp    (revision 4777)
+++ round_to.hpp        (working copy)
@@ -26,6 +26,8 @@
 
 #include "config.hpp"
 
+#include "mc_enum_types.hpp"
+
 #if !defined __BORLANDC__
 #   include <boost/static_assert.hpp>
 #   include <boost/type_traits/arithmetic_traits.hpp>
@@ -193,24 +195,6 @@ inline RealType perform_floor(RealType r)
 } // namespace detail
 
 // See HTML documentation.
-enum rounding_style
-    {r_indeterminate = -1
-    ,r_toward_zero   =  0
-    ,r_to_nearest    =  1 // See note below.
-    ,r_upward        =  2
-    ,r_downward      =  3
-    ,r_current       =  4
-    ,r_not_at_all    =  5
-
-    // Note: 'r_to_nearest' means bankers rounding, which
-    // rounds halfway cases to even:
-    //   x - (x REM 1.0)
-    // as in the C99 remainder() function [7.12.10.2/2], instead of
-    // rounding halfway cases away from zero, as the C99 round()
-    // function does [7.12.9.6/2]. See the HTML documentation.
-    };
-
-// See HTML documentation.
 inline rounding_style& default_rounding_style()
 {
     static rounding_style default_style = r_to_nearest;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]