345 In addition, the scale (number of postDecimalPoint digits) is returned |
345 In addition, the scale (number of postDecimalPoint digits) is returned |
346 (to support reading fixedPoint numbers). |
346 (to support reading fixedPoint numbers). |
347 No whitespace is skipped. |
347 No whitespace is skipped. |
348 Errs if no number is available on aStream." |
348 Errs if no number is available on aStream." |
349 |
349 |
350 |nextChar value factor intMantissa scale| |
350 |nextChar value factor intMantissa scale highPrecision| |
351 |
351 |
|
352 highPrecision := false. |
352 value := 0.0. |
353 value := 0.0. |
353 factor := 1.0 / radix. |
354 factor := 1.0 asLongFloat / radix. |
354 scale := 0. |
355 scale := 0. |
355 intMantissa := 0. |
356 intMantissa := 0. |
356 nextChar := aStream peekOrNil. |
357 nextChar := aStream peekOrNil. |
357 [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[ |
358 [nextChar notNil and:[nextChar isDigitRadix:radix]] whileTrue:[ |
358 value := value + (nextChar digitValue * factor). |
359 value := value + (nextChar digitValue * factor). |
359 intMantissa := (intMantissa * radix) + nextChar digitValue. |
360 intMantissa := (intMantissa * radix) + nextChar digitValue. |
360 factor := factor / radix. |
361 factor := factor / radix. |
361 scale := scale + 1. |
362 scale := scale + 1. |
362 factor < (Float epsilon * 2) ifTrue:[ |
|
363 value := value asLongFloat |
|
364 ]. |
|
365 aStream next. |
363 aStream next. |
366 nextChar := aStream peekOrNil |
364 nextChar := aStream peekOrNil |
367 ]. |
365 ]. |
|
366 |
368 ^ (Array with:value with:intMantissa with:scale). |
367 ^ (Array with:value with:intMantissa with:scale). |
369 |
368 |
370 " |
369 " |
371 Number readMantissaAndScaleFrom:'234' readStream radix:10. |
370 Number readMantissaAndScaleFrom:'234' readStream radix:10. |
372 Number readMantissaAndScaleFrom:'2' readStream radix:10. |
371 Number readMantissaAndScaleFrom:'2' readStream radix:10. |
604 |
603 |
605 degreesToRadians |
604 degreesToRadians |
606 "interpreting the receiver as radians, return the degrees" |
605 "interpreting the receiver as radians, return the degrees" |
607 |
606 |
608 ^ (self * (Float pi)) / 180.0 |
607 ^ (self * (Float pi)) / 180.0 |
|
608 |
|
609 " |
|
610 180 degreesToRadians |
|
611 Float pi radiansToDegrees |
|
612 " |
609 ! |
613 ! |
610 |
614 |
611 literalArrayEncoding |
615 literalArrayEncoding |
612 "encode myself as an array literal, from which a copy of the receiver |
616 "encode myself as an array literal, from which a copy of the receiver |
613 can be reconstructed with #decodeAsLiteralArray." |
617 can be reconstructed with #decodeAsLiteralArray." |
620 |
624 |
621 radiansToDegrees |
625 radiansToDegrees |
622 "interpreting the receiver as degrees, return the radians" |
626 "interpreting the receiver as degrees, return the radians" |
623 |
627 |
624 ^ (self * 180.0) / (Float pi) |
628 ^ (self * 180.0) / (Float pi) |
|
629 |
|
630 " |
|
631 180 degreesToRadians |
|
632 Float pi radiansToDegrees |
|
633 " |
625 ! |
634 ! |
626 |
635 |
627 withScale:newScale |
636 withScale:newScale |
628 "return a fixedPoint number representing the same valie as the receiver, |
637 "return a fixedPoint number representing the same valie as the receiver, |
629 with newScale number of post-decimal digits" |
638 with newScale number of post-decimal digits" |