From b39b54a92ed92f6501934bf3e1de1e875b964e40 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 6 May 2024 12:59:05 -0700 Subject: [PATCH] Fallback to scientific notation when fixed-point is long Fixed point output can create arbitrarily long string representations of floating points. When this happens, we would like to just represent the scientific notation to a limited precision Fixes https://gitlab.com/kicad/code/kicad/-/issues/17890 (cherry picked from commit 24f02e72d0c2f107b79f0bedd60d183964ab1565) --- eeschema/sim/spice_value.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eeschema/sim/spice_value.cpp b/eeschema/sim/spice_value.cpp index 4cdb995b69..dc6aeb90fb 100644 --- a/eeschema/sim/spice_value.cpp +++ b/eeschema/sim/spice_value.cpp @@ -262,6 +262,11 @@ wxString SPICE_VALUE::ToString( const SPICE_VALUE_FORMAT& aFormat ) mantissa *= std::pow( 10, scale - aFormat.Precision + 1 ); wxString res = wxString::FromCDouble( mantissa, std::max( 0, aFormat.Precision - scale - 1 ) ); + + // If we have an excessively long number, switch to scientific notation + if( ssize_t( res.length() ) > aFormat.Precision + scale + 1 ) + res = wxString::FromCDouble( mantissa ); + return res + range; }