File tree Expand file tree Collapse file tree 4 files changed +13
-27
lines changed
Expand file tree Collapse file tree 4 files changed +13
-27
lines changed Original file line number Diff line number Diff 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' }
7666Number >> subtractToPolynomial: aPolynomial [
7767 ^ aPolynomial addNumber: self negated
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ PMPolynomial >> reciprocal [
234234{ #category : #information }
235235PMPolynomial >> roots [
236236
237- ^ self roots: PMFloatingPointMachine new defaultNumericalPrecision
237+ ^ self roots: Float defaultComparisonPrecision
238238]
239239
240240{ #category : #information }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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' }
You can’t perform that action at this time.
0 commit comments