Skip to content

Commit 92e3d4d

Browse files
The implementation of asInteger doing truncation instead of the ansi way of doing rounded is taken over from Squeak. It seems like the morphic system is depending on asInteger doing truncation instead of rounding. I added a comment in asInteger to warn about the fact that we are not ansi compliant.
1 parent 29b5711 commit 92e3d4d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Kernel-Tests/NumberTest.class.st

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ Class {
99

1010
{ #category : #test }
1111
NumberTest >> testAsInteger [
12-
self assert: 0.5 asInteger equals: 1.
13-
self assert: (1/2) asInteger equals: 1
12+
"ensure we keep using truncated in asInteger"
13+
self assert: 0.5 asInteger equals: 0.
14+
self assert: (1/2) asInteger equals: 0
1415

1516
]
1617

@@ -173,3 +174,12 @@ NumberTest >> testReciprocal [
173174

174175
self should: [ 0 reciprocal ] raise: ZeroDivide
175176
]
177+
178+
{ #category : #test }
179+
NumberTest >> testRounded [
180+
181+
self assert: 0 rounded equals: 0.
182+
self assert: 1 rounded equals: 1.
183+
self assert: (1/2) rounded equals: 1.
184+
self assert: ((1/2) - Float epsilon) rounded equals: 0.
185+
]

src/Kernel/Number.class.st

+3-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ Number >> asFloat [
264264

265265
{ #category : #converting }
266266
Number >> asInteger [
267-
"Answer the result of sending #rounded to the receiver"
267+
"Round me towards nearest integer closer to zero."
268+
"This violates the ANSI standard, but the system depends on this"
268269

269-
^self rounded
270+
^self truncated
270271
]
271272

272273
{ #category : #converting }

0 commit comments

Comments
 (0)