--- a/Complex.st Wed Jul 05 16:58:15 2017 +0200
+++ b/Complex.st Wed Jul 05 17:00:20 2017 +0200
@@ -224,63 +224,6 @@
^ ComplexZero
! !
-!Complex class methodsFor:'exception handling'!
-
-trapImaginary:aBlock
- "evaluate aBlock; if any DomainError occurs inside, with respect to square roots,
- convert the root to a complex root and proceed.
- This allows for regular (failing) code to transparently convert to complex."
-
- ^ ImaginaryResultError
- handle: [:ex |
- |msgSend selector rcvr|
-
- msgSend := ex parameter.
- selector := msgSend selector.
- rcvr := msgSend receiver.
- (selector = #sqrt or: [selector = #sqrtTruncated]) ifTrue: [
- (rcvr isNumber and:[rcvr isReal]) ifTrue:[
- ex proceedWith:(rcvr abs perform:selector) i
- ] ifFalse:[
- msgSend receiver: rcvr asComplex.
- ex proceedWith: msgSend value
- ].
- ] ifFalse: [
- (selector = #integerSqrt) ifTrue: [
- (rcvr isInteger) ifTrue:[
- ex proceedWith:(rcvr abs integerSqrt) i
- ] ifFalse:[
- ex proceedWith:(rcvr abs asComplex sqrt floor) i
- ].
- ] ifFalse: [
- ex reject
- ]
- ]
- ] do:
- aBlock
-
- "
- Complex trapImaginary: [-2 sqrt]
- "
-
- "failing code:
- |a|
-
- a := -2.
- (a sqrt + 5) * 17.
- "
- "complex code:
- |a|
-
- Complex trapImaginary:[
- a := -2.
- (a sqrt + 5) * 2.
- ]
- "
-
- "Modified: / 01-07-2017 / 20:17:15 / cg"
-! !
-
!Complex methodsFor:'accessing'!
imaginary