From f90d9b80d1c25339be7da015b985706ac8e4d13e Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 24 Apr 2013 21:47:16 +0000 Subject: [PATCH] [Test] Fixed calculation of precision for string representations This corrects the calculation of the least significant digit for all string representations of for numbers where no decimal point was printed, e.g. "123" and "45e+06". --- site_scons/buildutils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index dd4cab520..0141e3ec8 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -247,15 +247,22 @@ def getPrecision(x): the number represented by the string 'x'. """ x = x.lower() + # Patterns to consider: + # 123 + # 123.45 + # 123.45e6 + # 123e4 + if 'e' in x: + x, exponent = x.split('e') + exponent = int(exponent) + else: + exponent = 0 + decimalPt = x.find('.') if decimalPt == -1: - decimalPt = 0 + decimalPt = len(x) - 1 - if x.find('e') != -1: - precision = decimalPt - x.find('e') + 1 - precision += int(x[x.find('e')+1:]) - else: - precision = decimalPt - len(x) + 1 + precision = decimalPt + exponent - len(x) + 1 return 10**precision