$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54859 - trunk/boost/spirit/home/karma/numeric/detail
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-10 10:57:19
Author: hkaiser
Date: 2009-07-10 10:57:18 EDT (Fri, 10 Jul 2009)
New Revision: 54859
URL: http://svn.boost.org/trac/boost/changeset/54859
Log:
Spirit: massive speedup fix for karma real generators (for built in floating point types)
Text files modified: 
   trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp |    54 +++++++++++++++++++++++++++++++++++++++ 
   1 files changed, 53 insertions(+), 1 deletions(-)
Modified: trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp	(original)
+++ trunk/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp	2009-07-10 10:57:18 EDT (Fri, 10 Jul 2009)
@@ -412,7 +412,6 @@
         typedef detail::divide<Radix> divide_type;
         typedef detail::remainder<Radix> remainder_type;
 
-        //  Common code for integer string representations
         template <typename OutputIterator, typename T>
         static bool
         call(OutputIterator& sink, T n, T& num, int exp)
@@ -444,6 +443,59 @@
         {
             return call(sink, n, n, 0);
         }
+
+        // helper function returning the biggest number representable either in
+        // a boost::long_long_type (if this does exist) or in a plain long
+        // otherwise
+#if defined(BOOST_HAS_LONG_LONG)
+        static std::size_t max_long()
+        {
+            return (std::numeric_limits<boost::long_long_type>::max)();
+        }
+#else
+        static std::size_t max_long()
+        {
+            return (std::numeric_limits<long>::max)();
+        }
+#endif
+
+        // Specialization for doubles and floats, falling back to long integers 
+        // for representable values. These specializations speed up formatting
+        // of floating point numbers considerably as all the required 
+        // arithmetics will be executed using integral data types.
+        template <typename OutputIterator>
+        static bool
+        call(OutputIterator& sink, long double n)
+        {
+            if (std::fabs(n) < max_long())
+            {
+                boost::long_long_type l(n);
+                return call(sink, l, l, 0);
+            }
+            return call(sink, n, n, 0);
+        }
+        template <typename OutputIterator>
+        static bool
+        call(OutputIterator& sink, double n)
+        {
+            if (std::fabs(n) < max_long())
+            {
+                boost::long_long_type l(n);
+                return call(sink, l, l, 0);
+            }
+            return call(sink, n, n, 0);
+        }
+        template <typename OutputIterator>
+        static bool
+        call(OutputIterator& sink, float n)
+        {
+            if (std::fabs(n) < max_long())
+            {
+                long l(n);
+                return call(sink, l, l, 0);
+            }
+            return call(sink, n, n, 0);
+        }
     };
 
 #undef BOOST_KARMA_NUMERICS_INNER_LOOP_PREFIX