Skip to content

Commit d7bc47a

Browse files
committed
Remove more floating point constants
1 parent b8000c6 commit d7bc47a

File tree

4 files changed

+19
-55
lines changed

4 files changed

+19
-55
lines changed

src/Math-Core-Process/PMIterativeProcess.class.st

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ PMIterativeProcess >> iterations [
9999

100100
{ #category : #private }
101101
PMIterativeProcess >> limitedSmallValue: aNumber [
102-
"Private - prevent aNumber from being smaller in absolute value than a small number."
103-
^aNumber abs < PMFloatingPointMachine new smallNumber
104-
ifTrue: [ PMFloatingPointMachine new smallNumber]
105-
ifFalse:[ aNumber]
102+
"Private - prevent aNumber from being smaller in absolute value than a small."
103+
104+
| smallestAccepted |
105+
smallestAccepted := Float fmin sqrt.
106+
^ aNumber abs < smallestAccepted
107+
ifTrue: [ smallestAccepted ]
108+
ifFalse: [ aNumber ]
106109
]
107110

108111
{ #category : #initialization }

src/Math-Distributions/PMFisherTippettDistribution.class.st

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ PMFisherTippettDistribution >> distributionValue: aNumber [
6060
the receiver with a value lower than or equal to aNumber."
6161
| arg |
6262
arg := ( aNumber - alpha) / beta.
63-
arg := arg < PMFloatingPointMachine new largestExponentArgument negated
63+
arg := arg < Float fmax ln negated
6464
ifTrue: [ ^0]
6565
ifFalse:[arg negated exp].
6666
^arg negated exp
@@ -126,14 +126,17 @@ PMFisherTippettDistribution >> standardDeviation [
126126

127127
{ #category : #information }
128128
PMFisherTippettDistribution >> value: aNumber [
129-
"Answers the probability that a random variable distributed according to the receiver
129+
"Answers the probability that a random variable distributed according to the receiver
130130
gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
131+
131132
| arg |
132-
arg := ( aNumber - alpha) / beta.
133-
arg := arg > PMFloatingPointMachine new largestExponentArgument ifTrue: [ ^0]
134-
ifFalse:[arg negated exp + arg].
135-
^arg > PMFloatingPointMachine new largestExponentArgument ifTrue: [ 0]
136-
ifFalse:[ arg negated exp / beta]
133+
arg := aNumber - alpha / beta.
134+
arg := arg > Float fmax ln
135+
ifTrue: [ ^ 0 ]
136+
ifFalse: [ arg negated exp + arg ].
137+
^ arg > Float fmax ln
138+
ifTrue: [ 0 ]
139+
ifFalse: [ arg negated exp / beta ]
137140
]
138141

139142
{ #category : #information }

src/Math-Helpers/PMFloatingPointMachine.class.st

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ A `PMFloatingPointMachine` represents the numerical precision of this system.
44
##Instance Variables
55
66
- `defaultNumericalPrecision` The relative numerical precision that can be expected for a general numerical computation. One should consider to numbers a and b equal if the relative difference between them is less than the default machine precision,
7-
- `largestExponentArgument` Natural logarithm of largest number,
8-
- `largestNumber` The largest positive number that can be represented in the machine,
97
- `machinePrecision` $r^{-(n+1)}$, with the largest n such that $(1 + r^{-n}) - 1$ != 0,
10-
- `negativeMachinePrecision` $r^{-(n+1)}$, with the largest n such that $(1 - r^{-n}) - 1$ != 0,
11-
- `radix` The radix of the floating point representation. This is often 2,
12-
- `smallNumber` A number that can be added to some value without noticeably changing the result of the computation,
13-
- `smallestNumber` The smallest positive number different from 0.
8+
- `negativeMachinePrecision` $r^{-(n+1)}$, with the largest n such that $(1 - r^{-n}) - 1$ != 0
149
1510
This class is detailed in Object Oriented Implementation of Numerical Methods, Section 1.4.1 and 1.4.2.
1611
@@ -21,9 +16,7 @@ Class {
2116
#instVars : [
2217
'defaultNumericalPrecision',
2318
'machinePrecision',
24-
'negativeMachinePrecision',
25-
'smallNumber',
26-
'largestExponentArgument'
19+
'negativeMachinePrecision'
2720
],
2821
#classVars : [
2922
'UniqueInstance'
@@ -78,19 +71,6 @@ PMFloatingPointMachine >> defaultNumericalPrecision [
7871
^ defaultNumericalPrecision
7972
]
8073

81-
{ #category : #information }
82-
PMFloatingPointMachine >> largestExponentArgument [
83-
84-
largestExponentArgument ifNil: [ largestExponentArgument := Float fmax ln ].
85-
^ largestExponentArgument
86-
]
87-
88-
{ #category : #information }
89-
PMFloatingPointMachine >> largestNumber [
90-
91-
^ Float fmax
92-
]
93-
9474
{ #category : #information }
9575
PMFloatingPointMachine >> machinePrecision [
9676

@@ -104,10 +84,3 @@ PMFloatingPointMachine >> negativeMachinePrecision [
10484
negativeMachinePrecision ifNil: [ self computeNegativeMachinePrecision ].
10585
^ negativeMachinePrecision
10686
]
107-
108-
{ #category : #information }
109-
PMFloatingPointMachine >> smallNumber [
110-
111-
smallNumber ifNil: [ smallNumber := Float fmin sqrt ].
112-
^ smallNumber
113-
]

src/Math-Tests-Numerical/PMFloatingPointMachineTestCase.class.st

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ PMFloatingPointMachineTestCase >> testMachinePrecisionLargestNumberIsLargest [
4242
self assert: Float fmax * (1 + mach defaultNumericalPrecision) equals: Float infinity
4343
]
4444

45-
{ #category : #precision }
46-
PMFloatingPointMachineTestCase >> testMachinePrecisionSmallNumberLargerThanSmallestNumber [
47-
48-
| mach |
49-
mach := PMFloatingPointMachine new.
50-
self assert: Float fmin < mach smallNumber
51-
]
52-
53-
{ #category : #precision }
54-
PMFloatingPointMachineTestCase >> testMachinePrecisionSmallNumberNotZero [
55-
| mach |
56-
mach := PMFloatingPointMachine new.
57-
self assert: mach smallNumber > 0.0
58-
]
59-
6045
{ #category : #precision }
6146
PMFloatingPointMachineTestCase >> testUniqueInstance [
6247

0 commit comments

Comments
 (0)