@@ -20,7 +20,6 @@ Class {
2020 #superclass : #Object ,
2121 #instVars : [
2222 ' defaultNumericalPrecision' ,
23- ' radix' ,
2423 ' machinePrecision' ,
2524 ' negativeMachinePrecision' ,
2625 ' smallestNumber' ,
@@ -42,6 +41,8 @@ PMFloatingPointMachine class >> new [
4241
4342{ #category : #accessing }
4443PMFloatingPointMachine class >> reset [
44+
45+ < script>
4546 UniqueInstance := nil
4647]
4748
@@ -50,14 +51,17 @@ PMFloatingPointMachine >> computeLargestNumber [
5051
5152 | one floatingRadix fullMantissaNumber |
5253 one := 1.0 .
53- floatingRadix := self radix asFloat.
54- fullMantissaNumber := one - ( floatingRadix * self negativeMachinePrecision).
54+ floatingRadix := Float radix asFloat.
55+ fullMantissaNumber := one - (floatingRadix * self negativeMachinePrecision).
5556 largestNumber := fullMantissaNumber.
56- [ [ fullMantissaNumber := fullMantissaNumber * floatingRadix.
57- fullMantissaNumber isInfinite ifTrue: [^ nil ].
58- largestNumber := fullMantissaNumber.
59- true ] whileTrue: [ ].
60- ] on: Error do: [ :signal | signal return: nil ]
57+ [
58+ [
59+ fullMantissaNumber := fullMantissaNumber * floatingRadix.
60+ fullMantissaNumber isInfinite ifTrue: [ ^ nil ].
61+ largestNumber := fullMantissaNumber.
62+ true ] whileTrue: [ ] ]
63+ on: Error
64+ do: [ :signal | signal return: nil ]
6165]
6266
6367{ #category : #information }
@@ -66,11 +70,11 @@ PMFloatingPointMachine >> computeMachinePrecision [
6670 | one zero inverseRadix tmp |
6771 one := 1.0 .
6872 zero := 0.0 .
69- inverseRadix := one / self radix asFloat.
73+ inverseRadix := one / Float radix asFloat.
7074 machinePrecision := one.
71- [ tmp := one + machinePrecision.
72- tmp - one = zero]
73- whileFalse: [ machinePrecision := machinePrecision * inverseRadix]
75+ [
76+ tmp := one + machinePrecision.
77+ tmp - one = zero ] whileFalse: [ machinePrecision := machinePrecision * inverseRadix ]
7478]
7579
7680{ #category : #information }
@@ -79,47 +83,31 @@ PMFloatingPointMachine >> computeNegativeMachinePrecision [
7983 | one zero floatingRadix inverseRadix tmp |
8084 one := 1.0 .
8185 zero := 0.0 .
82- floatingRadix := self radix asFloat.
86+ floatingRadix := Float radix asFloat.
8387 inverseRadix := one / floatingRadix.
8488 negativeMachinePrecision := one.
85- [ tmp := one - negativeMachinePrecision.
86- tmp - one = zero]
87- whileFalse: [ negativeMachinePrecision := negativeMachinePrecision * inverseRadix]
88- ]
89-
90- { #category : #information }
91- PMFloatingPointMachine >> computeRadix [
92-
93- | one zero a b tmp1 tmp2 |
94- one := 1.0 .
95- zero := 0.0 .
96- a := one.
97- [ a := a + a.
98- tmp1 := a + one.
99- tmp2 := tmp1 - a.
100- tmp2 - one = zero] whileTrue: [].
101- b := one.
102- [ b := b + b.
103- tmp1 := a + b.
104- radix := ( tmp1 - a) truncated.
105- radix = 0 ] whileTrue: []
89+ [
90+ tmp := one - negativeMachinePrecision.
91+ tmp - one = zero ] whileFalse: [ negativeMachinePrecision := negativeMachinePrecision * inverseRadix ]
10692]
10793
10894{ #category : #information }
10995PMFloatingPointMachine >> computeSmallestNumber [
11096
11197 | one floatingRadix inverseRadix fullMantissaNumber |
11298 one := 1 asFloat.
113- floatingRadix := self radix asFloat.
99+ floatingRadix := Float radix asFloat.
114100 inverseRadix := one / floatingRadix.
115101 fullMantissaNumber := one - (floatingRadix * self negativeMachinePrecision).
116102 smallestNumber := fullMantissaNumber.
117- [[fullMantissaNumber := fullMantissaNumber * inverseRadix.
118- fullMantissaNumber = 0.0 ifTrue: [Error signal ].
103+ [
104+ [
105+ fullMantissaNumber := fullMantissaNumber * inverseRadix.
106+ fullMantissaNumber = 0.0 ifTrue: [ Error signal ].
119107 smallestNumber := fullMantissaNumber.
120- true ]
121- whileTrue: []]
122- on: Error do: [:signal | signal return: nil ]
108+ true ] whileTrue: [ ] ]
109+ on: Error
110+ do: [ :signal | signal return: nil ]
123111]
124112
125113{ #category : #information }
@@ -157,21 +145,12 @@ PMFloatingPointMachine >> negativeMachinePrecision [
157145 ^ negativeMachinePrecision
158146]
159147
160- { #category : #information }
161- PMFloatingPointMachine >> radix [
162-
163- radix ifNil: [ self computeRadix ].
164- ^ radix
165- ]
166-
167148{ #category : #display }
168149PMFloatingPointMachine >> showParameters [
169150
170151 Transcript cr; cr;
171152 nextPutAll: ' Floating-point machine parameters' ; cr;
172- nextPutAll: ' ---------------------------------' ;cr;
173- nextPutAll: ' Radix: ' .
174- self radix printOn: Transcript .
153+ nextPutAll: ' ---------------------------------' .
175154 Transcript cr; nextPutAll: ' Machine precision: ' .
176155 self machinePrecision printOn: Transcript .
177156 Transcript cr; nextPutAll: ' Negative machine precision: ' .
0 commit comments