reading signed radix numbers
authorClaus Gittinger <cg@exept.de>
Fri, 17 Feb 2006 16:23:53 +0100
changeset 1679 c568383eb5ec
parent 1678 edd3a6b568c7
child 1680 6ba154c6ae8f
reading signed radix numbers
Scanner.st
--- a/Scanner.st	Fri Feb 17 15:46:31 2006 +0100
+++ b/Scanner.st	Fri Feb 17 16:23:53 2006 +0100
@@ -2307,9 +2307,11 @@
     "scan a number; handles radix prefix, mantissa and exponent.
      Allows for e, d or q to be used as exponent limiter."
 
-    |pos1 nextChar value integerPart s tokenRadix mantissaAndScaledPart d type exp scale|
+    |pos1 nextChar value integerPart sign 
+     expSign tokenRadix mantissaAndScaledPart d type exp scale|
 
     tokenRadix := 10.
+    sign := 1.
     type := #Integer.
     pos1 := source position1Based.
 
@@ -2323,13 +2325,11 @@
             self syntaxError:'bad radix (must be 2 .. 36)'
                     position:tokenPosition to:(source position1Based - 1).
         ].
-        s := 1.
         source peekOrNil == $- ifTrue:[
             source next.
-            s := -1
+            sign := -1
         ].
         value := Integer readFrom:source radix:tokenRadix.
-        value := value * s.
         nextChar := source peekOrNil.
     ].
 
@@ -2367,16 +2367,16 @@
         type := #Float.
         nextChar := source nextPeek.
         (nextChar notNil and:[(nextChar isDigit"Radix:tokenRadix") or:['+-' includes:nextChar]]) ifTrue:[
-            s := 1.
+            expSign := 1.
             (nextChar == $+) ifTrue:[
                 nextChar := source nextPeek
             ] ifFalse:[
                 (nextChar == $-) ifTrue:[
                     nextChar := source nextPeek.
-                    s := s negated
+                    expSign := -1
                 ]
             ].
-            exp := (Integer readFrom:source) * s.
+            exp := (Integer readFrom:source) * expSign.
             value := value * ((value class unity * tokenRadix) raisedToInteger:exp).
             nextChar := source peek.
         ].
@@ -2418,7 +2418,7 @@
             position:(source position1Based) to:(source position1Based).
     ].
 
-    tokenValue := token := value.
+    tokenValue := token := value * sign.
     tokenType := type.
     (tokenValue isLimitedPrecisionReal) ~~ (tokenType == #Float) ifTrue:[
         self halt:'unfinished feature'
@@ -3045,7 +3045,7 @@
 !Scanner class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.213 2006-02-17 14:46:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Scanner.st,v 1.214 2006-02-17 15:23:53 cg Exp $'
 ! !
 
 Scanner initialize!