diff --git a/src/script_opt/CPP/Util.cc b/src/script_opt/CPP/Util.cc index 5ad4846aa3..15fc981ede 100644 --- a/src/script_opt/CPP/Util.cc +++ b/src/script_opt/CPP/Util.cc @@ -17,6 +17,16 @@ string Fmt(double d) { if ( d == 0.0 && signbit(d) ) return "-0.0"; + if ( isinf(d) ) { + string infty = "std::numeric_limits::infinity()"; + if ( d < 0.0 ) + infty = "-" + infty; + return infty; + } + + if ( isnan(d) ) + return "std::numeric_limits::quiet_NaN()"; + // Unfortunately, to_string(double) is hardwired to use %f with // default of 6 digits precision. char buf[8192];