summary refs log tree commit diff stats
path: root/lib/system/strmantle.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-06-12 08:35:32 +0200
committerGitHub <noreply@github.com>2019-06-12 08:35:32 +0200
commit572b7c37a5e537ecf198b2761c7c0a7b2e2400f6 (patch)
tree1fec5b9b9611e2f3fd4525dfb6e8adec21de5d4d /lib/system/strmantle.nim
parentc7e1c665a1d399272bef35395a6c364b9f98d64a (diff)
downloadNim-572b7c37a5e537ecf198b2761c7c0a7b2e2400f6.tar.gz
[other] preparations for --styleCheck:error for the Nim compiler (#11478)
Diffstat (limited to 'lib/system/strmantle.nim')
-rw-r--r--lib/system/strmantle.nim63
1 files changed, 33 insertions, 30 deletions
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim
index 457e0eab5..66477923c 100644
--- a/lib/system/strmantle.nim
+++ b/lib/system/strmantle.nim
@@ -149,14 +149,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     kdigits, fdigits = 0
     exponent: int
     integer: uint64
-    frac_exponent = 0
-    exp_sign = 1
-    first_digit = -1
-    has_sign = false
+    fracExponent = 0
+    expSign = 1
+    firstDigit = -1
+    hasSign = false
 
   # Sign?
   if i < s.len and (s[i] == '+' or s[i] == '-'):
-    has_sign = true
+    hasSign = true
     if s[i] == '-':
       sign = -1.0
     inc(i)
@@ -180,7 +180,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     return 0
 
   if i < s.len and s[i] in {'0'..'9'}:
-    first_digit = (s[i].ord - '0'.ord)
+    firstDigit = (s[i].ord - '0'.ord)
   # Integer part?
   while i < s.len and s[i] in {'0'..'9'}:
     inc(kdigits)
@@ -194,16 +194,16 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     # if no integer part, Skip leading zeros
     if kdigits <= 0:
       while i < s.len and s[i] == '0':
-        inc(frac_exponent)
+        inc(fracExponent)
         inc(i)
         while i < s.len and s[i] == '_': inc(i)
 
-    if first_digit == -1 and i < s.len and s[i] in {'0'..'9'}:
-      first_digit = (s[i].ord - '0'.ord)
+    if firstDigit == -1 and i < s.len and s[i] in {'0'..'9'}:
+      firstDigit = (s[i].ord - '0'.ord)
     # get fractional part
     while i < s.len and s[i] in {'0'..'9'}:
       inc(fdigits)
-      inc(frac_exponent)
+      inc(fracExponent)
       integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64
       inc(i)
       while i < s.len and s[i] == '_': inc(i)
@@ -211,14 +211,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
   # if has no digits: return error
   if kdigits + fdigits <= 0 and
      (i == start or # no char consumed (empty string).
-     (i == start + 1 and has_sign)): # or only '+' or '-
+     (i == start + 1 and hasSign)): # or only '+' or '-
     return 0
 
   if i+1 < s.len and s[i] in {'e', 'E'}:
     inc(i)
     if s[i] == '+' or s[i] == '-':
       if s[i] == '-':
-        exp_sign = -1
+        expSign = -1
 
       inc(i)
     if s[i] notin {'0'..'9'}:
@@ -228,13 +228,13 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
       inc(i)
       while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
 
-  var real_exponent = exp_sign*exponent - frac_exponent
-  let exp_negative = real_exponent < 0
-  var abs_exponent = abs(real_exponent)
+  var realExponent = expSign*exponent - fracExponent
+  let expNegative = realExponent < 0
+  var absExponent = abs(realExponent)
 
   # if exponent greater than can be represented: +/- zero or infinity
-  if abs_exponent > 999:
-    if exp_negative:
+  if absExponent > 999:
+    if expNegative:
       number = 0.0*sign
     else:
       number = Inf*sign
@@ -243,20 +243,20 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
   # if integer is representable in 53 bits:  fast path
   # max fast path integer is  1<<53 - 1 or  8999999999999999 (16 digits)
   let digits = kdigits + fdigits
-  if digits <= 15 or (digits <= 16 and first_digit <= 8):
+  if digits <= 15 or (digits <= 16 and firstDigit <= 8):
     # max float power of ten with set bits above the 53th bit is 10^22
-    if abs_exponent <= 22:
-      if exp_negative:
-        number = sign * integer.float / powtens[abs_exponent]
+    if absExponent <= 22:
+      if expNegative:
+        number = sign * integer.float / powtens[absExponent]
       else:
-        number = sign * integer.float * powtens[abs_exponent]
+        number = sign * integer.float * powtens[absExponent]
       return i - start
 
     # if exponent is greater try to fit extra exponent above 22 by multiplying
     # integer part is there is space left.
     let slop = 15 - kdigits - fdigits
-    if  abs_exponent <= 22 + slop and not exp_negative:
-      number = sign * integer.float * powtens[slop] * powtens[abs_exponent-slop]
+    if  absExponent <= 22 + slop and not expNegative:
+      number = sign * integer.float * powtens[slop] * powtens[absExponent-slop]
       return i - start
 
   # if failed: slow path with strtod.
@@ -276,14 +276,17 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
       inc(i)
 
   # insert exponent
-  t[ti] = 'E'; inc(ti)
-  t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
-  inc(ti, 3)
+  t[ti] = 'E'
+  inc(ti)
+  t[ti] = if expNegative: '-' else: '+'
+  inc(ti, 4)
 
   # insert adjusted exponent
-  t[ti-1] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
-  t[ti-2] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
-  t[ti-3] = ('0'.ord + abs_exponent mod 10).char
+  t[ti-1] = ('0'.ord + absExponent mod 10).char
+  absExponent = absExponent div 10
+  t[ti-2] = ('0'.ord + absExponent mod 10).char
+  absExponent = absExponent div 10
+  t[ti-3] = ('0'.ord + absExponent mod 10).char
 
   when defined(nimNoArrayToCstringConversion):
     number = c_strtod(addr t, nil)