Skip to content

Commit ce92f8d

Browse files
authored
Merge pull request #317 from jecisc/use-pharo-constants
Use pharo constants
2 parents 7ce07d6 + 3612a46 commit ce92f8d

18 files changed

+356
-666
lines changed

src/BaselineOfPolyMath/BaselineOfPolyMath.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ BaselineOfPolyMath >> baseline: spec [
3939
package: 'Math-Complex' with: [ spec requires: #( 'Math-Numerical' 'Math-Polynomials' ) ];
4040
package: 'Math-Helpers';
4141
package: 'Math-Distributions' with: [ spec requires: #( 'MathVectorMatrix' 'Math-Quantile' 'Math-Core-Process' ) ];
42-
package: 'Math-Core-Process' with: [ spec requires: #( 'Math-Helpers' ) ];
42+
package: 'Math-Core-Process';
4343
package: 'Math-Numerical'
44-
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Helpers' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
44+
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
4545
'Math-Series' ) ];
4646
package: 'Math-Polynomials'
47-
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Helpers' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
47+
with: [ spec requires: #( 'MathVectorMatrix' 'Math-Core-Process' 'Math-Distributions' 'Math-StatisticalMoments'
4848
'Math-Series' ) ];
4949
package: 'Math-FastFourierTransform' with: [ spec requires: #( 'Math-Complex' ) ];
5050
package: 'Math-FunctionFit'

src/Math-CompatibilityUpToPharo11/Float.extension.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Extension { #name : #Float }
22

3+
{ #category : #'*Math-CompatibilityUpToPharo11' }
4+
Float class >> defaultComparisonPrecision [
5+
6+
^ self machineEpsilon sqrt
7+
]
8+
39
{ #category : #'*Math-CompatibilityUpToPharo11' }
410
Float class >> machineEpsilon [
511
"Answer the machine epsilon or macheps, defined by wikipedia asCalypsoItemContext

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ PMIterativeProcess class >> defaultMaximumIterations [
3333
{ #category : #default }
3434
PMIterativeProcess class >> defaultPrecision [
3535
"Private - Answers the default precision for newly created instances."
36-
^PMFloatingPointMachine new defaultNumericalPrecision
36+
37+
self flag: #todo. "In Pharo 12 the default comparision precision of Float will be improved. When Pharo 12 will be the minimal version of Polymath we can use `Float defaultComparisonPrecision"
38+
^ Float machineEpsilon sqrt
3739
]
3840

3941
{ #category : #initialization }
@@ -98,10 +100,13 @@ PMIterativeProcess >> iterations [
98100

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

107112
{ #category : #initialization }
@@ -121,9 +126,9 @@ PMIterativeProcess >> precision [
121126
{ #category : #information }
122127
PMIterativeProcess >> precisionOf: aNumber1 relativeTo: aNumber2 [
123128

124-
^aNumber2 > PMFloatingPointMachine new defaultNumericalPrecision
125-
ifTrue: [ aNumber1 / aNumber2]
126-
ifFalse:[ aNumber1]
129+
^ aNumber2 > Float defaultComparisonPrecision
130+
ifTrue: [ aNumber1 / aNumber2 ]
131+
ifFalse: [ aNumber1 ]
127132
]
128133

129134
{ #category : #information }

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-Distributions/PMIncompleteBetaFunction.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PMIncompleteBetaFunction >> evaluateFraction: aNumber [
2626
fraction setParameter: alpha1 second: alpha2 ].
2727
fraction setArgument: aNumber.
2828
^ (PMContinuedFraction server: fraction)
29-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
29+
desiredPrecision: Float defaultComparisonPrecision;
3030
evaluate
3131
]
3232

@@ -38,7 +38,7 @@ PMIncompleteBetaFunction >> evaluateInverseFraction: aNumber [
3838
inverseFraction setParameter: alpha2 second: alpha1 ].
3939
inverseFraction setArgument: 1 - aNumber.
4040
^ (PMContinuedFraction server: inverseFraction)
41-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
41+
desiredPrecision: Float defaultComparisonPrecision;
4242
evaluate
4343
]
4444

src/Math-Distributions/PMIncompleteGammaFunction.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PMIncompleteGammaFunction >> evaluateFraction: aNumber [
2424
fraction setParameter: alpha ].
2525
fraction setArgument: aNumber.
2626
^ (PMContinuedFraction server: fraction)
27-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
27+
desiredPrecision: Float defaultComparisonPrecision;
2828
evaluate
2929
]
3030

@@ -36,7 +36,7 @@ PMIncompleteGammaFunction >> evaluateSeries: aNumber [
3636
series setParameter: alpha ].
3737
series setArgument: aNumber.
3838
^ (PMInfiniteSeries server: series)
39-
desiredPrecision: PMFloatingPointMachine new defaultNumericalPrecision;
39+
desiredPrecision: Float defaultComparisonPrecision;
4040
evaluate
4141
]
4242

src/Math-FunctionFit/PMAnotherGeneticOptimizer.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Class {
1919

2020
{ #category : #information }
2121
PMAnotherGeneticOptimizer class >> defaultPrecision [
22-
^PMFloatingPointMachine new machinePrecision
22+
23+
^ Float machineEpsilon
2324
]
2425

2526
{ #category : #'instance creation' }

src/Math-FunctionFit/PMGeneralFunctionFit.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ PMGeneralFunctionFit >> evaluate [
100100
ff parameters ] onErrorDo: [
101101
verbose ifTrue: [ self inform: 'ErrorMinimizer was not successful' ].
102102
nil ].
103+
103104
firstResult ifNotNil: [ geneticOptimizer addPointAt: firstResult ].
104105
firstResult := geneticOptimizer evaluate.
105106
self errorType = #squared ifTrue: [ ff := PMFunctionFit function: errorFunction function data: errorFunction data ].
106107
ff parameters: firstResult.
107-
ff desiredPrecision: PMFloatingPointMachine new machinePrecision.
108+
ff desiredPrecision: Float machineEpsilon.
108109
ff maximumIterations: 1000.
109110
result := [
110111
ff evaluate.

src/Math-Helpers/PMFloatingPointMachine.class.st

Lines changed: 0 additions & 198 deletions
This file was deleted.

src/Math-Numerical/Number.extension.st

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ Number >> logGamma [
6262
]
6363
]
6464

65-
{ #category : #'*Math-Numerical' }
66-
Number >> relativelyEqualsTo: aNumber upTo: aSmallNumber [
67-
"compare to Float>>closeTo:
68-
generally called from Number>>equalsTo:"
69-
| norm |
70-
norm := self abs max: aNumber abs.
71-
^norm <= PMFloatingPointMachine new defaultNumericalPrecision
72-
or: [ (self - aNumber) abs < ( aSmallNumber * norm)]
73-
]
74-
7565
{ #category : #'*Math-Numerical' }
7666
Number >> subtractToPolynomial: aPolynomial [
7767
^aPolynomial addNumber: self negated

0 commit comments

Comments
 (0)