From e19948daa72491d33cd5aa9b8619b7e093a16615 Mon Sep 17 00:00:00 2001 From: iNaKoll Date: Thu, 10 Nov 2016 22:16:47 +0100 Subject: [PATCH] Fixes #5983: real_generator failure --- include/boost/spirit/home/karma/numeric/detail/real_utils.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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..84ea67dd4b 100644 --- a/include/boost/spirit/home/karma/numeric/detail/real_utils.hpp +++ b/include/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(-exp); - n *= spirit::traits::pow10(exp); + // detect and handle denormalized numbers to prevent overflow in pow10 + if (exp > std::numeric_limits::max_exponent10) + { + n *= spirit::traits::pow10(std::numeric_limits::max_exponent10); + n *= spirit::traits::pow10(exp - std::numeric_limits::max_exponent10); + } else + n *= spirit::traits::pow10(exp); } }