Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Math-Complex/PMComplex.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ PMComplex >> sign [
^ real sign
]

{ #category : #testing }
PMComplex >> signBit [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, as this is a one line block, we might inline this,

PMComplex >> signBit [ ^ self real signBit ]

unless what you've done is the idiomatic way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand ? This is not a block. You are looking at Tonel files, the real method is :
MComplex >> signBit
^ self real signBit

^self real signBit
]

{ #category : #'mathematical functions' }
PMComplex >> sin [
"Answer receiver's sine."
Expand Down
14 changes: 7 additions & 7 deletions src/Math-Complex/PMComplex.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ PMComplex >> productWithVector: aVector [
^ aVector collect: [ :each | each * self ]
]

{ #category : #'*Math-Complex' }
PMComplex class >> random [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education, what drives the need for this method?

"Answers a random number with abs between 0 and 1."

^ self abs: 1.0 random arg: 2 * Float pi random
]

{ #category : #'*Math-Complex' }
PMComplex >> random [
"analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced."
^ self class random * self

]

{ #category : #'*Math-Complex' }
PMComplex classSide >> random [
"Answers a random number with abs between 0 and 1."

^ self abs: 1.0 random arg: 2 * Float pi random
]

{ #category : #'*Math-Complex' }
PMComplex >> subtractToPolynomial: aPolynomial [
^ aPolynomial addNumber: self negated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Class {
#category : 'Math-Tests-ArbitraryPrecisionFloat'
}

{ #category : #accessing }
ArbitraryPrecisionFloatTest class >> defaultTimeLimit [
^60 seconds
]

{ #category : #private }
ArbitraryPrecisionFloatTest >> checkDoublePrecision: y forFunction: func nBits: n [
"Check that doubling the precision, then rounding would lead to the same result"
Expand Down Expand Up @@ -645,27 +650,37 @@ ArbitraryPrecisionFloatTest >> testPositive [

{ #category : #'testing-converting' }
ArbitraryPrecisionFloatTest >> testPrintAndEvaluate [
<timeout: 50 "seconds">
"seconds"

<timeout: 50>
| emax emin leadingOne significands |
significands := 0 to: 1<<10-1.
leadingOne := 1<<10.
significands := 0 to: (1 << 10) - 1.
leadingOne := 1 << 10.
emin := -14.
emax := 15.

"Test all normal finite half precision float"
emin to: emax do: [:e |
significands do: [:s |
| f |
f := (leadingOne + s asArbitraryPrecisionFloatNumBits: 11) timesTwoPower: e - 10.
self assert: (Compiler evaluate: f storeString) = f.
self assert: (Compiler evaluate: f printString) = f.]].

emin to: emax do: [ :e |
significands
do: [ :s |
| f |
f := (leadingOne + s asArbitraryPrecisionFloatNumBits: 11)
timesTwoPower: e - 10.
self
assert: (Smalltalk compiler evaluate: f storeString)
equals: f.
self
assert: (Smalltalk compiler evaluate: f printString)
equals: f ] ].

"Test all subnormal finite half precision float"
significands do: [:s |
| f |
f := (s asArbitraryPrecisionFloatNumBits: s highBit) timesTwoPower: emin - 10.
self assert: (Compiler evaluate: f storeString) = f.
self assert: (Compiler evaluate: f printString) = f].
significands
do: [ :s |
| f |
f := (s asArbitraryPrecisionFloatNumBits: s highBit)
timesTwoPower: emin - 10.
self assert: (Smalltalk compiler evaluate: f storeString) equals: f.
self assert: (Smalltalk compiler evaluate: f printString) equals: f ]
]

{ #category : #'testing-arithmetic' }
Expand Down