From 6daf9d5b8836db2e59886fba5bdc30d057bb8ec3 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Tue, 13 Aug 2024 14:42:25 -0700 Subject: [PATCH] fixes for -O gen-C++ generation of floating point constants --- src/script_opt/CPP/Util.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) 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];