[ENH] Case independent numbers
Bert Freudenberg
bert at isgnw.CS.Uni-Magdeburg.De
Mon Feb 28 16:55:22 UTC 2000
Hi,
who of you really would expect that 16r1e5 equals 1048576 while 16r1E5 is
485? If not too many, I propose to make hex numbers case independent, and
exponent notation, too.
Changeset is attached.
-Bert-
-------------- next part --------------
'From Squeak2.8alpha of 18 January 2000 [latest update: #1873] on 28 February 2000 at 5:49:31 pm'!
"Change Set: numcase-bf
Date: 28 February 2000
Author: Bert Freudenberg
Makes number reading independent of case"!
!Character methodsFor: 'accessing' stamp: 'bf 2/28/2000 17:42'!
digitValue
"Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z or $a-$z, and < 0 otherwise. This is used to parse literal numbers of radix 2-36."
value <= $9 asciiValue
ifTrue: [^value - $0 asciiValue].
(value between: $A asciiValue and: $Z asciiValue)
ifTrue: [^value - $A asciiValue + 10].
(value between: $a asciiValue and: $z asciiValue)
ifTrue: [^value - $a asciiValue + 10].
^ -1! !
!Number class methodsFor: 'instance creation' stamp: 'bf 2/28/2000 17:39'!
readRemainderOf: integerPart from: aStream base: base withSign: sign
"Read optional fractional part and exponent, and return the final result"
| value fraction fracpos |
value _ integerPart.
(aStream peekFor: $.)
ifTrue:
["<integer>.<fraction>"
(aStream atEnd not and: [aStream peek digitValue between: 0 and: base - 1])
ifTrue:
[fracpos _ aStream position.
fraction _ Integer readFrom: aStream base: base.
fraction _
fraction asFloat / (base raisedTo: aStream position - fracpos).
value _ value asFloat + fraction]
ifFalse:
["oops - just <integer>."
aStream skip: -1. "un-gobble the period"
^ value * sign
"Number readFrom: '3r-22.2'"]].
((aStream peekFor: $e) or: [aStream peekFor: $E])
ifTrue:
["<integer>e<exponent>"
value _ value * (base raisedTo: (Integer readFrom: aStream))].
(value isFloat and: [value = 0.0 and: [sign = -1]])
ifTrue: [^ Float negativeZero]
ifFalse: [^ value * sign]! !
More information about the Squeak-dev
mailing list
|