#BUGFIX by Stefan Reise
class: Number class
changed:
#readFrom:decimalPointCharacters:onError:
#readFrom:decimalPointCharacters:thousandsSeparator:allowCStyle:onError:
0xXXX reading
--- a/Number.st Tue Dec 17 00:58:50 2019 +0100
+++ b/Number.st Tue Dec 17 14:30:23 2019 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -430,7 +428,7 @@
it allows for prefixed + and also allows missing fractional part after eE.
It supports 0x, 0o and 0b prefixes (hex, octal and binary)
and the regular Smalltalk radix prefix xr.
- If also allows for strings like '1.0×1015' to be read (as 1E+15).
+ If also allows for strings like '1.0×1015' to be read (as 1E+15).
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
@@ -476,7 +474,7 @@
readFrom:aStringOrStream
decimalPointCharacters:decimalPointCharacters
thousandsSeparator:nil
- allowCStyle:false
+ allowCStyle:true
onError:exceptionBlock
"
@@ -497,7 +495,7 @@
Number readFrom:(ReadStream on:'12345678901234567890')
Number readFrom:(ReadStream on:'12345678901234567890.0')
Number readFrom:(ReadStream on:'12345678901234567890.012345678901234567890')
- Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
+ Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
Number readFrom:'16rAAAAFFFFAAAAFFFF'
Number readFrom:'16r100A'
Number readFrom:'16r100a'
@@ -536,6 +534,7 @@
"Modified: / 17-07-2017 / 15:18:03 / cg"
"Modified: / 21-07-2019 / 13:05:19 / Claus Gittinger"
+ "Modified: / 17-12-2019 / 14:19:54 / Stefan Reise"
!
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters thousandsSeparator:thousandsSeparator allowCStyle:allowCStyle onError:exceptionBlock
@@ -546,7 +545,7 @@
it allows for prefixed + and also allows missing fractional part after eE.
It supports 0x, 0o and 0b prefixes (hex, octal and binary)
and the regular Smalltalk radix prefix xr.
- If also allows for strings like '1.0×1015' to be read (as 1E+15).
+ If also allows for strings like '1.0×1015' to be read (as 1E+15).
It also allows garbage after the number - i.e. it reads what it can.
See #fromString: , which is more strict and does not allow garbage at the end.
@@ -615,14 +614,18 @@
(allowCStyle and:[nextChar == $0]) ifTrue:[
nextChar := str nextPeekOrNil.
nextChar isNil ifTrue:[^ 0].
- nextChar == $x ifTrue:[ str next. radix := 16 ]
- ifFalse:[ nextChar == $b ifTrue:[ str next. radix := 2 ]
- ifFalse:[ nextChar == $o ifTrue:[ str next. radix := 8 ]
+ ((nextChar == $x) or:[nextChar == $X]) ifTrue:[ str next. radix := 16 ]
+ ifFalse:[ ((nextChar == $b) or:[nextChar == $B]) ifTrue:[ str next. radix := 2 ]
+ ifFalse:[ ((nextChar == $o) or:[nextChar == $O]) ifTrue:[ str next. radix := 8 ]
ifFalse:[
nextChar isDigit ifFalse:[
^ 0
].
]]].
+ str peek == $- ifTrue:[
+ sign := -1.
+ str next
+ ].
value := Integer readFrom:str radix:radix.
nextChar := str peekOrNil.
] ifFalse:[
@@ -639,6 +642,10 @@
].
((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
str next.
+ str peek == $- ifTrue:[
+ sign := -1.
+ str next
+ ].
radix := value.
value := Integer readFrom:str radix:radix.
nextChar := str peekOrNil.
@@ -743,7 +750,7 @@
scale:(scale ? mantissaAndScale third).
].
] ifFalse:[
- (nextChar == $×) ifTrue:[
+ (nextChar == $×) ifTrue:[
(((nextChar := str nextPeek) == $1)
and:[ ((nextChar := str nextPeek) == $0) ]
) ifTrue:[
@@ -792,7 +799,12 @@
Number readFrom:(ReadStream on:'16rAAAAFFFFAAAAFFFF')
Number readFrom:'16rAAAAFFFFAAAAFFFF'
Number readFrom:'16r100A'
- Number readFrom:'16r100a'
+ Number readFrom:'16r100a'
+ Number readFrom:'16r-100A'
+ Number readFrom:'-16r100A'
+ Number readFrom:'0x100A'
+ Number readFrom:'-0x100A'
+ Number readFrom:'0x-100A'
Number readFrom:'0.000001'
'+00000123.45' asNumber
Number readFrom:'(1/3)'
@@ -828,6 +840,7 @@
"Created: / 21-07-2019 / 13:05:04 / Claus Gittinger"
"Modified: / 21-07-2019 / 19:40:34 / Claus Gittinger"
+ "Modified (comment): / 17-12-2019 / 14:28:03 / Stefan Reise"
!
readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters thousandsSeparator:thousandsSeparator onError:exceptionBlock
@@ -1252,6 +1265,7 @@
"
! !
+
!Number class methodsFor:'private'!
readMantissaAndScaleFrom:aStream radix:radix
@@ -1366,6 +1380,7 @@
^ self == Number
! !
+
!Number methodsFor:'Compatibility-Squeak'!
asSmallAngleDegrees
@@ -4042,6 +4057,7 @@
"
! !
+
!Number class methodsFor:'documentation'!
version