161 " |
161 " |
162 ! ! |
162 ! ! |
163 |
163 |
164 !FixedPoint class methodsFor:'instance creation'! |
164 !FixedPoint class methodsFor:'instance creation'! |
165 |
165 |
166 fromSchemaString: aString |
|
167 "Answer an instance. (keeping the scale)" |
|
168 |
|
169 #swAdded. |
|
170 |
|
171 Smalltalk isSmalltalkX ifTrue:[ |
|
172 ^super fromString: aString |
|
173 ]. |
|
174 ^super fromString: aString , 's' |
|
175 ! |
|
176 |
|
177 numerator:n denominator:d |
166 numerator:n denominator:d |
178 "redefined to block the inherited instance creation method from fraction. |
167 "redefined to block the inherited instance creation method from fraction. |
179 Raises an error - you must give a scale" |
168 Raises an error - you must give a scale" |
180 |
169 |
181 self shouldNotImplement. "use #numerator:denominator:scale" |
170 self shouldNotImplement. "use #numerator:denominator:scale" |
204 - depending on the upcoming ANSI standard, this may change." |
193 - depending on the upcoming ANSI standard, this may change." |
205 |
194 |
206 ^ self readFrom:aStringOrStream onError:0 |
195 ^ self readFrom:aStringOrStream onError:0 |
207 |
196 |
208 " |
197 " |
|
198 FixedPoint readFrom:'.456' |
209 FixedPoint readFrom:'123.456' |
199 FixedPoint readFrom:'123.456' |
210 FixedPoint readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788' |
200 FixedPoint readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788' |
211 FixedPoint readFrom:(ReadStream on:'foobar') |
201 FixedPoint readFrom:(ReadStream on:'foobar') |
212 FixedPoint readFrom:(ReadStream on:'foobar') onError:nil |
202 FixedPoint readFrom:(ReadStream on:'foobar') onError:nil |
213 |
203 |
214 FixedPoint readFrom:'1' |
204 FixedPoint readFrom:'1' |
215 FixedPoint readFrom:'2' |
205 FixedPoint readFrom:'2' |
216 FixedPoint readFrom:'1.5' |
206 FixedPoint readFrom:'1.5' |
217 " |
207 " |
218 |
208 |
219 "Modified: / 25.10.1997 / 15:30:29 / cg" |
209 "Modified: / 23-11-2010 / 14:39:29 / cg" |
220 ! |
210 ! |
221 |
211 |
222 readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock |
212 readFrom:aStringOrStream decimalPointCharacters:decimalPointCharacters onError:exceptionBlock |
223 "return an instance of me as described on the string or stream, aStringOrStream. |
213 "return an instance of me as described on the string or stream, aStringOrStream. |
224 If an error occurs during conversion, return the result |
214 If an error occurs during conversion, return the result |
234 ] ifFalse:[ |
224 ] ifFalse:[ |
235 sign := 1 |
225 sign := 1 |
236 ]. |
226 ]. |
237 |
227 |
238 (aStream atEnd or:[aStream peek isLetter]) ifTrue: [^ exceptionBlock value]. |
228 (aStream atEnd or:[aStream peek isLetter]) ifTrue: [^ exceptionBlock value]. |
239 |
229 (decimalPointCharacters includes:aStream peek) ifTrue:[ |
240 integerPart := Number readFromString:(aStream upToAny:decimalPointCharacters). |
230 "/ no integer part |
|
231 integerPart := 0. |
|
232 aStream next. |
|
233 ] ifFalse:[ |
|
234 integerPart := Number readFromString:(aStream upToAny:decimalPointCharacters). |
|
235 ]. |
241 (aStream atEnd or: [aStream peek isLetter]) ifTrue: [ |
236 (aStream atEnd or: [aStream peek isLetter]) ifTrue: [ |
242 fractionPart := 0. |
237 fractionPart := 0. |
243 scale := 1. |
238 scale := 1. |
244 ] ifFalse:[ |
239 ] ifFalse:[ |
245 fractionStream := ReadWriteStream on:(String new: 10). |
240 fractionStream := ReadWriteStream on:(String new: 10). |
269 FixedPoint readFrom:'-123.abcd' onError:[47.5] |
264 FixedPoint readFrom:'-123.abcd' onError:[47.5] |
270 FixedPoint readFrom:'-1a.bcd' onError:[47.5] |
265 FixedPoint readFrom:'-1a.bcd' onError:[47.5] |
271 FixedPoint readFrom:'foot' onError:['bad fixedpoint'] |
266 FixedPoint readFrom:'foot' onError:['bad fixedpoint'] |
272 " |
267 " |
273 |
268 |
274 "Created: / 25.10.1997 / 15:28:59 / cg" |
269 "Created: / 25-10-1997 / 15:28:59 / cg" |
275 "Modified: / 25.10.1997 / 15:31:47 / cg" |
270 "Modified: / 23-11-2010 / 14:38:12 / cg" |
276 ! ! |
271 ! ! |
277 |
272 |
278 !FixedPoint class methodsFor:'constants'! |
273 !FixedPoint class methodsFor:'constants'! |
279 |
274 |
280 pi |
275 pi |