allow for degenerate float to be read
(.xxx and -.xxx - i.e. without pre-decimalPoint digits)
is this a good idea ?
--- a/Number.st Thu Aug 26 12:16:54 1999 +0200
+++ b/Number.st Thu Aug 26 12:18:21 1999 +0200
@@ -103,21 +103,27 @@
nextChar := str peekOrNil
]
].
- nextChar isDigit ifFalse:[
+ (nextChar isDigit or:[nextChar == $.]) ifFalse:[
^ exceptionBlock value.
"/ value := super readFrom:str.
"/ negative ifTrue:[value := value negated].
"/ ^ value
].
- value := Integer readFrom:str radix:10.
- nextChar := str peekOrNil.
- ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
- str next.
- radix := value.
- value := Integer readFrom:str radix:radix.
+ nextChar == $. ifTrue:[
+ radix := 10.
+ value := 0.0.
] ifFalse:[
- radix := 10
+ value := Integer readFrom:str radix:10.
+ nextChar := str peekOrNil.
+ ((nextChar == $r) or:[ nextChar == $R]) ifTrue:[
+ str next.
+ radix := value.
+ value := Integer readFrom:str radix:radix.
+ ] ifFalse:[
+ radix := 10
+ ].
].
+
(nextChar == $.) ifTrue:[
str next.
nextChar := str peekOrNil.
@@ -624,5 +630,5 @@
!Number class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.50 1999-08-04 19:34:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.51 1999-08-26 10:18:21 cg Exp $'
! !
--- a/SFloat.st Thu Aug 26 12:16:54 1999 +0200
+++ b/SFloat.st Thu Aug 26 12:18:21 1999 +0200
@@ -201,6 +201,28 @@
!
+readFrom:aStringOrStream
+ "read a shortFloat from a string"
+
+ |num|
+
+ num := super readFrom:aStringOrStream onError:[self error:'conversion error for: ' , self name].
+ num notNil ifTrue:[
+ num := num asShortFloat
+ ].
+ ^ num
+
+ "
+ ShortFloat readFrom:'0.1'
+ ShortFloat readFrom:'0'
+ ShortFloat readFrom:'.123'
+ ShortFloat readFrom:'-.123'
+ ShortFloat readFrom:'1e4'
+ "
+
+ "Modified: / 7.1.1998 / 16:17:59 / cg"
+!
+
readFrom:aStringOrStream onError:exceptionBlock
"read a shortFloat from a string"
@@ -208,13 +230,14 @@
num := super readFrom:aStringOrStream onError:nil.
num isNil ifTrue:[
- ^ exceptionBlock value
+ ^ exceptionBlock value
].
^ num asShortFloat
"
ShortFloat readFrom:'0.1'
ShortFloat readFrom:'0'
+ ShortFloat readFrom:'.123'
"
"Modified: / 7.1.1998 / 16:17:59 / cg"
@@ -964,5 +987,5 @@
!ShortFloat class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/SFloat.st,v 1.52 1999-08-19 01:19:54 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/SFloat.st,v 1.53 1999-08-26 10:17:59 cg Exp $'
! !
--- a/ShortFloat.st Thu Aug 26 12:16:54 1999 +0200
+++ b/ShortFloat.st Thu Aug 26 12:18:21 1999 +0200
@@ -201,6 +201,28 @@
!
+readFrom:aStringOrStream
+ "read a shortFloat from a string"
+
+ |num|
+
+ num := super readFrom:aStringOrStream onError:[self error:'conversion error for: ' , self name].
+ num notNil ifTrue:[
+ num := num asShortFloat
+ ].
+ ^ num
+
+ "
+ ShortFloat readFrom:'0.1'
+ ShortFloat readFrom:'0'
+ ShortFloat readFrom:'.123'
+ ShortFloat readFrom:'-.123'
+ ShortFloat readFrom:'1e4'
+ "
+
+ "Modified: / 7.1.1998 / 16:17:59 / cg"
+!
+
readFrom:aStringOrStream onError:exceptionBlock
"read a shortFloat from a string"
@@ -208,13 +230,14 @@
num := super readFrom:aStringOrStream onError:nil.
num isNil ifTrue:[
- ^ exceptionBlock value
+ ^ exceptionBlock value
].
^ num asShortFloat
"
ShortFloat readFrom:'0.1'
ShortFloat readFrom:'0'
+ ShortFloat readFrom:'.123'
"
"Modified: / 7.1.1998 / 16:17:59 / cg"
@@ -964,5 +987,5 @@
!ShortFloat class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.52 1999-08-19 01:19:54 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.53 1999-08-26 10:17:59 cg Exp $'
! !