From 7c630f4ce46b1c1e02259720ea11fd3a3a005f05 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 17 May 2022 13:34:40 +0200 Subject: [PATCH] Fix crash in conversion to string for floats < 1e-13 Fixes part of #17. Reported by SaladDais@users.noreply.github.com, thanks! --- lslopt/lslbasefuncs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index af3fc6d..1ba0908 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -386,6 +386,10 @@ def f2s(val, DP=6): sgn = u'-' if s[0] == u'-' else u'' if sgn: s = s[1:] + # If we don't have significant digits, return zero + if s == '0.' + '0'*(DP+7): + return sgn + s[:DP+2] + # Look for position of first nonzero from the left i = 0 while s[i] in u'0.':