From 4be5cd1f35431496edb9355a446d5960a9fdfbc0 Mon Sep 17 00:00:00 2001 From: iNaKoll Date: Thu, 10 Nov 2016 20:54:35 +0100 Subject: [PATCH] Fixes #12599: real_generator failure --- .../home/karma/numeric/detail/numeric_utils.hpp | 42 ++++++++++++++++++++++ .../home/karma/numeric/detail/real_utils.hpp | 2 +- .../boost/spirit/home/support/numeric_traits.hpp | 3 ++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp b/include/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp index a36893e57e..3ecd5e3f03 100644 --- a/include/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp +++ b/include/boost/spirit/home/karma/numeric/detail/numeric_utils.hpp @@ -237,6 +237,48 @@ namespace boost { namespace spirit { namespace traits /////////////////////////////////////////////////////////////////////// template + struct is_subnormal + { + static bool call(T) + { + return false; + } + }; + + template <> + struct is_subnormal + { + static bool call(float n) + { + return (math::fpclassify)(n) == FP_SUBNORMAL; + } + }; + + template <> + struct is_subnormal + { + static bool call(double n) + { + return (math::fpclassify)(n) == FP_SUBNORMAL; + } + }; + + template <> + struct is_subnormal + { + static bool call(long double n) + { + return (math::fpclassify)(n) == FP_SUBNORMAL; + } + }; + + template + inline bool test_subnormal(T n) + { + return is_subnormal::call(n); + } + /////////////////////////////////////////////////////////////////////// + template struct is_nan { static bool call(T n) diff --git a/include/boost/spirit/home/karma/numeric/detail/real_utils.hpp b/include/boost/spirit/home/karma/numeric/detail/real_utils.hpp index 526985d280..f8e263d839 100644 --- a/include/boost/spirit/home/karma/numeric/detail/real_utils.hpp +++ b/include/boost/spirit/home/karma/numeric/detail/real_utils.hpp @@ -95,7 +95,7 @@ namespace boost { namespace spirit { namespace karma using namespace std; U dim = 0; - if (0 == (Policies::fmtflags::fixed & flags) && !traits::test_zero(n)) + if (0 == (Policies::fmtflags::fixed & flags) && !traits::test_zero(n) && !traits::test_subnormal(n)) { dim = log10(n); if (dim > 0) diff --git a/include/boost/spirit/home/support/numeric_traits.hpp b/include/boost/spirit/home/support/numeric_traits.hpp index 01771dd982..82bdfe6c4b 100644 --- a/include/boost/spirit/home/support/numeric_traits.hpp +++ b/include/boost/spirit/home/support/numeric_traits.hpp @@ -108,6 +108,9 @@ namespace boost { namespace spirit { namespace traits struct is_zero; template + struct is_subnormal; + + template struct pow10_helper; template