Skip to content

Commit 770f386

Browse files
authored
Merge pull request #316 from jecisc/divers-cleanings
Divers cleanings
2 parents dd08cad + bea3974 commit 770f386

File tree

242 files changed

+3272
-3435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+3272
-3435
lines changed

src/BaselineOfPolyMath/BaselineOfPolyMath.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BaselineOfPolyMath >> baseline: spec [
2525
xmlWriter: spec;
2626
vectorMatrix: spec;
2727
randomNumbers: spec.
28-
28+
2929
spec
3030
package: 'ExtendedNumberParser';
3131
package: 'Math-Accuracy-Core';

src/ExtendedNumberParser/ExtendedNumberParser.class.st

Lines changed: 83 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ An ExtendedNumberParser is extending Squeak number syntax with these rules
1010
Class {
1111
#name : #ExtendedNumberParser,
1212
#superclass : #NumberParser,
13-
#category : 'ExtendedNumberParser'
13+
#category : #ExtendedNumberParser
1414
}
1515

1616
{ #category : #accessing }
@@ -21,7 +21,7 @@ ExtendedNumberParser >> allowPlusSign [
2121
{ #category : #accessing }
2222
ExtendedNumberParser >> exponentLetters [
2323
"Allow uppercase exponent letter."
24-
24+
2525
^'edqEDQ'
2626
]
2727

@@ -76,135 +76,131 @@ ExtendedNumberParser >> nextFraction [
7676
ExtendedNumberParser >> nextNumber [
7777
"main method for reading a number.
7878
This one can read Float Integer and ScaledDecimal"
79-
79+
8080
| numberOfTrailingZeroInIntegerPart |
8181
base := 10.
8282
neg := self peekSignIsMinus.
8383
integerPart := self nextUnsignedIntegerOrNilBase: base.
84-
integerPart ifNil: [(sourceStream peekFor: $.)
85-
ifTrue: [
86-
"Try .1 syntax"
87-
^self readNumberWithoutIntegerPart]
88-
ifFalse: [
89-
"This is not a regular number beginning with a digit
84+
integerPart ifNil: [
85+
^ (sourceStream peekFor: $.)
86+
ifTrue: [ "Try .1 syntax" self readNumberWithoutIntegerPart ]
87+
ifFalse: [ "This is not a regular number beginning with a digit
9088
It is time to check for exceptional condition NaN and Infinity"
91-
^self readNamedFloatOrFail]].
89+
self readNamedFloatOrFail ] ].
9290
numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero.
93-
(sourceStream peekFor: $r)
94-
ifTrue: ["<base>r<integer>"
95-
| oldNeg pos |
96-
pos := sourceStream position.
97-
(base := integerPart) < 2
98-
ifTrue: ["A radix currently need to be greater than 1, ungobble the r and return the integer part"
99-
sourceStream skip: -1.
100-
^neg
101-
ifTrue: [base negated]
102-
ifFalse: [base]].
103-
oldNeg := neg.
104-
self peekSignIsMinus ifTrue: [neg := neg not].
105-
integerPart := self nextUnsignedIntegerOrNilBase: base.
106-
integerPart ifNil: [
107-
(sourceStream peekFor: $.) ifTrue: [self readNumberWithoutIntegerPartOrNil ifNotNil: [:aNumber | ^aNumber]].
108-
sourceStream position: pos.
109-
^oldNeg
110-
ifTrue: [base negated]
111-
ifFalse: [base]].
112-
numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero].
91+
(sourceStream peekFor: $r) ifTrue: [ "<base>r<integer>"
92+
| oldNeg pos |
93+
pos := sourceStream position.
94+
(base := integerPart) < 2 ifTrue: [ "A radix currently need to be greater than 1, ungobble the r and return the integer part"
95+
sourceStream skip: -1.
96+
^ neg
97+
ifTrue: [ base negated ]
98+
ifFalse: [ base ] ].
99+
oldNeg := neg.
100+
self peekSignIsMinus ifTrue: [ neg := neg not ].
101+
integerPart := self nextUnsignedIntegerOrNilBase: base.
102+
integerPart ifNil: [
103+
(sourceStream peekFor: $.) ifTrue: [ self readNumberWithoutIntegerPartOrNil ifNotNil: [ :aNumber | ^ aNumber ] ].
104+
sourceStream position: pos.
105+
^ oldNeg
106+
ifTrue: [ base negated ]
107+
ifFalse: [ base ] ].
108+
numberOfTrailingZeroInIntegerPart := nDigits - lastNonZero ].
113109
^ (sourceStream peekFor: $.)
114-
ifTrue: [self readNumberWithFractionPartNumberOfTrailingZeroInIntegerPart: numberOfTrailingZeroInIntegerPart]
115-
ifFalse: [self makeIntegerOrScaledInteger]
110+
ifTrue: [ self readNumberWithFractionPartNumberOfTrailingZeroInIntegerPart: numberOfTrailingZeroInIntegerPart ]
111+
ifFalse: [ self makeIntegerOrScaledInteger ]
116112
]
117113

118114
{ #category : #'parsing-private' }
119115
ExtendedNumberParser >> readFractionPartNumberOfTrailingZeroInIntegerPart: numberOfTrailingZeroInIntegerPart [
120116
"at this stage, sign integerPart and a fraction point have been read.
121117
try and form a number with a fractionPart"
122-
118+
123119
| numberOfNonZeroFractionDigits numberOfTrailingZeroInFractionPart mantissa value |
124120
fractionPart := self nextUnsignedIntegerOrNilBase: base.
125-
fractionPart
126-
ifNil: [
127-
"No fractionPart found, but can be an extended 1.e2 syntax"
128-
integerPart ifNil: ["No integerPart, nor fractionPart found, ungobble the fraction point and raise an error"
129-
sourceStream skip: -1.
130-
^self expected: 'a digit'].
131-
fractionPart := 0.
132-
numberOfNonZeroFractionDigits := 0.
133-
numberOfTrailingZeroInFractionPart := 0]
134-
ifNotNil: [.
135-
numberOfNonZeroFractionDigits := lastNonZero.
136-
numberOfTrailingZeroInFractionPart := nDigits - lastNonZero].
121+
numberOfTrailingZeroInFractionPart := fractionPart
122+
ifNil: [ "No fractionPart found, but can be an extended 1.e2 syntax"
123+
integerPart ifNil: [ "No integerPart, nor fractionPart found, ungobble the fraction point and raise an error"
124+
sourceStream skip: -1.
125+
^ self expected: 'a digit' ].
126+
fractionPart := 0.
127+
numberOfNonZeroFractionDigits := 0.
128+
0 ]
129+
ifNotNil: [
130+
numberOfNonZeroFractionDigits := lastNonZero.
131+
nDigits - lastNonZero ].
137132
self readExponent.
138-
integerPart ifNil: [integerPart := 0].
139-
140-
fractionPart isZero
141-
ifTrue: [mantissa := integerPart
142-
// (base raisedToInteger: numberOfTrailingZeroInIntegerPart).
143-
exponent := exponent + numberOfTrailingZeroInIntegerPart]
144-
ifFalse: [mantissa := integerPart
145-
* (base raisedToInteger: numberOfNonZeroFractionDigits) + (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)).
146-
exponent := exponent - numberOfNonZeroFractionDigits].
133+
integerPart ifNil: [ integerPart := 0 ].
134+
exponent := fractionPart isZero
135+
ifTrue: [
136+
mantissa := integerPart // (base raisedToInteger: numberOfTrailingZeroInIntegerPart).
137+
exponent + numberOfTrailingZeroInIntegerPart ]
138+
ifFalse: [
139+
mantissa := integerPart * (base raisedToInteger: numberOfNonZeroFractionDigits)
140+
+ (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)).
141+
exponent - numberOfNonZeroFractionDigits ].
147142

148143
value := exponent positive
149-
ifTrue: [mantissa * (base raisedToInteger: exponent)]
150-
ifFalse: [mantissa / (base raisedToInteger: exponent negated)].
144+
ifTrue: [ mantissa * (base raisedToInteger: exponent) ]
145+
ifFalse: [ mantissa / (base raisedToInteger: exponent negated) ].
151146
^ neg
152-
ifTrue: [value negated]
153-
ifFalse: [value]
147+
ifTrue: [ value negated ]
148+
ifFalse: [ value ]
154149
]
155150

156151
{ #category : #'parsing-private' }
157152
ExtendedNumberParser >> readNumberWithFractionPartNumberOfTrailingZeroInIntegerPart: numberOfTrailingZeroInIntegerPart [
158153
"at this stage, sign integerPart and a decimal point have been read.
159154
try and form a number with a fractionPart"
160-
155+
161156
| numberOfNonZeroFractionDigits numberOfTrailingZeroInFractionPart mantissa value |
162157
fractionPart := self nextUnsignedIntegerOrNilBase: base.
163-
fractionPart
164-
ifNil: [
165-
"No fractionPart found, but can be a 1.e2 syntax"
166-
fractionPart := 0.
167-
numberOfNonZeroFractionDigits := 0.
168-
numberOfTrailingZeroInFractionPart := 0]
169-
ifNotNil: [
170-
numberOfNonZeroFractionDigits := lastNonZero.
171-
numberOfTrailingZeroInFractionPart := nDigits - lastNonZero].
172-
self readExponent
173-
ifFalse: [self readScale
174-
ifTrue: [^self makeScaledDecimalWithNumberOfNonZeroFractionDigits: numberOfNonZeroFractionDigits
175-
andNumberOfTrailingZeroInFractionPart: numberOfTrailingZeroInFractionPart]].
176-
177-
fractionPart isZero
178-
ifTrue: [mantissa := integerPart
179-
// (base raisedToInteger: numberOfTrailingZeroInIntegerPart).
180-
exponent := exponent + numberOfTrailingZeroInIntegerPart]
181-
ifFalse: [mantissa := integerPart
182-
* (base raisedToInteger: numberOfNonZeroFractionDigits) + (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)).
183-
exponent := exponent - numberOfNonZeroFractionDigits].
158+
numberOfTrailingZeroInFractionPart := fractionPart
159+
ifNil: [ "No fractionPart found, but can be a 1.e2 syntax"
160+
fractionPart := 0.
161+
numberOfNonZeroFractionDigits := 0.
162+
0 ]
163+
ifNotNil: [
164+
numberOfNonZeroFractionDigits := lastNonZero.
165+
nDigits - lastNonZero ].
166+
self readExponent ifFalse: [
167+
self readScale ifTrue: [
168+
^ self
169+
makeScaledDecimalWithNumberOfNonZeroFractionDigits: numberOfNonZeroFractionDigits
170+
andNumberOfTrailingZeroInFractionPart: numberOfTrailingZeroInFractionPart ] ].
171+
exponent := fractionPart isZero
172+
ifTrue: [
173+
mantissa := integerPart // (base raisedToInteger: numberOfTrailingZeroInIntegerPart).
174+
exponent + numberOfTrailingZeroInIntegerPart ]
175+
ifFalse: [
176+
mantissa := integerPart * (base raisedToInteger: numberOfNonZeroFractionDigits)
177+
+ (fractionPart // (base raisedToInteger: numberOfTrailingZeroInFractionPart)).
178+
exponent - numberOfNonZeroFractionDigits ].
184179

185180
value := self makeFloatFromMantissa: mantissa exponent: exponent base: base.
186181
^ neg
187-
ifTrue: [value isZero
188-
ifTrue: [Float negativeZero]
189-
ifFalse: [value negated]]
190-
ifFalse: [value]
182+
ifTrue: [
183+
value isZero
184+
ifTrue: [ Float negativeZero ]
185+
ifFalse: [ value negated ] ]
186+
ifFalse: [ value ]
191187
]
192188

193189
{ #category : #'parsing-private' }
194190
ExtendedNumberParser >> readNumberWithoutIntegerPart [
195191
"at this stage, sign followed by a decimal point have been read, but no intergerPart
196192
try and form a number with a fractionPart"
197-
193+
198194
^self readNumberWithoutIntegerPartOrNil ifNil: [
199195
"No integer part, no fractionPart, this does not look like a number..."
200-
^self expected: 'a digit between 0 and 9'].
196+
^self expected: 'a digit between 0 and 9']
201197
]
202198

203199
{ #category : #'parsing-private' }
204200
ExtendedNumberParser >> readNumberWithoutIntegerPartOrNil [
205201
"at this stage, sign followed by a decimal point have been read, but no intergerPart
206202
try and form a number with a fractionPart"
207-
203+
208204
| numberOfNonZeroFractionDigits numberOfTrailingZeroInFractionPart mantissa value |
209205
integerPart := 0.
210206
fractionPart := self nextUnsignedIntegerOrNilBase: base.

0 commit comments

Comments
 (0)