Skip to content

Commit c9f0dda

Browse files
committed
Start to remove the users of defaultNumericalPrecision to use Float defaultComparisonPrecision
1 parent 9c2d253 commit c9f0dda

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

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

src/Math-Polynomials/PMPolynomial.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ PMPolynomial >> reciprocal [
234234
{ #category : #information }
235235
PMPolynomial >> roots [
236236

237-
^self roots: PMFloatingPointMachine new defaultNumericalPrecision
237+
^ self roots: Float defaultComparisonPrecision
238238
]
239239

240240
{ #category : #information }

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,20 @@ PMNumericalMethodsTestCase >> testLineSearch3 [
454454
455455
This case does not require line search, should return 1.
456456
"
457+
457458
| xOld eps p functionBlock g0 g1 dg0 lineSearch xAnswer |
458-
eps := PMFloatingPointMachine new defaultNumericalPrecision.
459+
eps := Float defaultComparisonPrecision.
459460
xOld := -1.0 + eps.
460461
p := eps.
461-
functionBlock := [ :t | 0.5 * ((t * p + xOld) + 1) squared ].
462+
functionBlock := [ :t | 0.5 * (t * p + xOld + 1) squared ].
462463
g0 := functionBlock value: 0.
463464
g1 := functionBlock value: 1.
464465
dg0 := 2.0 * g0 negated.
465-
lineSearch := PMLineSearch function: functionBlock valueAtZero: g0 derivativeAtZero: dg0 valueAtOne: g1.
466+
lineSearch := PMLineSearch
467+
function: functionBlock
468+
valueAtZero: g0
469+
derivativeAtZero: dg0
470+
valueAtOne: g1.
466471
lineSearch desiredPrecision: eps.
467472
xAnswer := lineSearch evaluate.
468473
self assert: xAnswer equals: 1.0

src/Math-Tests-Polynomials/PMPolynomialTest.class.st

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,12 @@ PMPolynomialTest >> testPolynomialRoots [
234234
"Code Example 5.5"
235235

236236
| polynomial roots |
237-
polynomial := PMPolynomial coefficients: #(-10 -13 -2 1).
237+
polynomial := PMPolynomial coefficients: #( -10 -13 -2 1 ).
238238
roots := polynomial roots asSortedCollection asArray.
239239
self assert: roots size equals: 3.
240-
self
241-
assert:
242-
((roots at: 1) + 2) abs
243-
< PMFloatingPointMachine new defaultNumericalPrecision.
244-
self
245-
assert:
246-
((roots at: 2) + 1) abs
247-
< PMFloatingPointMachine new defaultNumericalPrecision.
248-
self
249-
assert:
250-
((roots at: 3) - 5) abs
251-
< PMFloatingPointMachine new defaultNumericalPrecision
240+
self assert: (roots at: 1) + 2 closeTo: 0.
241+
self assert: (roots at: 2) + 1 closeTo: 0.
242+
self assert: (roots at: 3) - 5 closeTo: 0
252243
]
253244

254245
{ #category : #'function evaluation' }

0 commit comments

Comments
 (0)