summaryrefslogtreecommitdiff
path: root/boost/spirit/home/karma/numeric/detail/real_utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/spirit/home/karma/numeric/detail/real_utils.hpp')
-rw-r--r--boost/spirit/home/karma/numeric/detail/real_utils.hpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/boost/spirit/home/karma/numeric/detail/real_utils.hpp b/boost/spirit/home/karma/numeric/detail/real_utils.hpp
index 526985d280..84ea67dd4b 100644
--- a/boost/spirit/home/karma/numeric/detail/real_utils.hpp
+++ b/boost/spirit/home/karma/numeric/detail/real_utils.hpp
@@ -105,7 +105,13 @@ namespace boost { namespace spirit { namespace karma
if (exp != -dim)
++exp;
dim = static_cast<U>(-exp);
- n *= spirit::traits::pow10<U>(exp);
+ // detect and handle denormalized numbers to prevent overflow in pow10
+ if (exp > std::numeric_limits<U>::max_exponent10)
+ {
+ n *= spirit::traits::pow10<U>(std::numeric_limits<U>::max_exponent10);
+ n *= spirit::traits::pow10<U>(exp - std::numeric_limits<U>::max_exponent10);
+ } else
+ n *= spirit::traits::pow10<U>(exp);
}
}