Skip to content

Commit b8000c6

Browse files
committed
Use the smallest number provided by Pharo
1 parent 7cd9144 commit b8000c6

File tree

3 files changed

+4
-61
lines changed

3 files changed

+4
-61
lines changed

src/Math-Helpers/PMFloatingPointMachine.class.st

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Class {
2222
'defaultNumericalPrecision',
2323
'machinePrecision',
2424
'negativeMachinePrecision',
25-
'smallestNumber',
2625
'smallNumber',
2726
'largestExponentArgument'
2827
],
@@ -72,25 +71,6 @@ PMFloatingPointMachine >> computeNegativeMachinePrecision [
7271
tmp - one = zero ] whileFalse: [ negativeMachinePrecision := negativeMachinePrecision * inverseRadix ]
7372
]
7473

75-
{ #category : #information }
76-
PMFloatingPointMachine >> computeSmallestNumber [
77-
78-
| one floatingRadix inverseRadix fullMantissaNumber |
79-
one := 1 asFloat.
80-
floatingRadix := Float radix asFloat.
81-
inverseRadix := one / floatingRadix.
82-
fullMantissaNumber := one - (floatingRadix * self negativeMachinePrecision).
83-
smallestNumber := fullMantissaNumber.
84-
[
85-
[
86-
fullMantissaNumber := fullMantissaNumber * inverseRadix.
87-
fullMantissaNumber = 0.0 ifTrue: [ Error signal ].
88-
smallestNumber := fullMantissaNumber.
89-
true ] whileTrue: [ ] ]
90-
on: Error
91-
do: [ :signal | signal return: nil ]
92-
]
93-
9474
{ #category : #information }
9575
PMFloatingPointMachine >> defaultNumericalPrecision [
9676

@@ -125,40 +105,9 @@ PMFloatingPointMachine >> negativeMachinePrecision [
125105
^ negativeMachinePrecision
126106
]
127107

128-
{ #category : #display }
129-
PMFloatingPointMachine >> showParameters [
130-
131-
Transcript
132-
cr;
133-
cr;
134-
nextPutAll: 'Floating-point machine parameters';
135-
cr;
136-
nextPutAll: '---------------------------------'.
137-
Transcript
138-
cr;
139-
nextPutAll: 'Machine precision: '.
140-
self machinePrecision printOn: Transcript.
141-
Transcript
142-
cr;
143-
nextPutAll: 'Negative machine precision: '.
144-
self negativeMachinePrecision printOn: Transcript.
145-
Transcript
146-
cr;
147-
nextPutAll: 'Smallest number: '.
148-
self smallestNumber printOn: Transcript.
149-
Transcript flush
150-
]
151-
152108
{ #category : #information }
153109
PMFloatingPointMachine >> smallNumber [
154110

155-
smallNumber ifNil: [ smallNumber := self smallestNumber sqrt ].
111+
smallNumber ifNil: [ smallNumber := Float fmin sqrt ].
156112
^ smallNumber
157113
]
158-
159-
{ #category : #information }
160-
PMFloatingPointMachine >> smallestNumber [
161-
162-
smallestNumber ifNil: [ self computeSmallestNumber ].
163-
^ smallestNumber
164-
]

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ PMFloatingPointMachineTestCase >> testMachinePrecisionLargestNumberIsLargest [
4444

4545
{ #category : #precision }
4646
PMFloatingPointMachineTestCase >> testMachinePrecisionSmallNumberLargerThanSmallestNumber [
47+
4748
| mach |
4849
mach := PMFloatingPointMachine new.
49-
self assert: mach smallestNumber < mach smallNumber
50+
self assert: Float fmin < mach smallNumber
5051
]
5152

5253
{ #category : #precision }
@@ -56,13 +57,6 @@ PMFloatingPointMachineTestCase >> testMachinePrecisionSmallNumberNotZero [
5657
self assert: mach smallNumber > 0.0
5758
]
5859

59-
{ #category : #precision }
60-
PMFloatingPointMachineTestCase >> testMachinePrecisionSmallestNumberNotZero [
61-
| mach |
62-
mach := PMFloatingPointMachine new.
63-
self assert: mach smallestNumber > 0.0
64-
]
65-
6660
{ #category : #precision }
6761
PMFloatingPointMachineTestCase >> testUniqueInstance [
6862

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PMNumericalMethodsTestCase >> testErrorFunction [
9898
self assert: Float fmax errorFunction > (1 - PMFloatingPointMachine new machinePrecision).
9999
"add some code to require initialize to run"
100100
PMErfApproximation reset.
101-
self assert: Float fmax negated errorFunction < PMFloatingPointMachine new smallestNumber
101+
self assert: Float fmax negated errorFunction < Float fmin
102102
]
103103

104104
{ #category : #estimation }

0 commit comments

Comments
 (0)