[squeak-dev] The Trunk: Kernel-nice.573.mcz
commits at source.squeak.org
commits at source.squeak.org
Sun Apr 24 20:49:13 UTC 2011
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.573.mcz
==================== Summary ====================
Name: Kernel-nice.573
Author: nice
Time: 24 April 2011, 10:48:34.956 pm
UUID: 6467b07b-fb80-8c41-8f33-91c673a57e88
Ancestors: Kernel-nice.572
Arrange arCosh to answer a positive real part.
Arrange arcCos + arcSin to answer halfPi.
Implement sinh cosh without intermediate Complex creation.
=============== Diff against Kernel-nice.572 ===============
Item was changed:
----- Method: Complex>>arCosh (in category 'mathematical functions') -----
arCosh
"Answer receiver's area hyperbolic cosine.
+ That is the inverse function of cosh.
+ Some possible implementations:
- That is the inverse function of cosh."
-
- "Some possible implementation:
-
^imaginary > 0
ifTrue: [(self + (self * self - 1) sqrt) ln]
+ ifFalse: [(self + (self * self - 1) sqrt) ln negated]
+ ^self arcCos i
+ This implementation provides an answer with a positive real part.
+ It also avoids creating intermediate Complex."
+
+ | x y tmp sh2x shx delta ch2x chx |
+ imaginary = 0 ifTrue: [real abs > 1
+ ifTrue:
+ [y := real < 0
+ ifTrue: [Float pi]
+ ifFalse: [0].
+ x := real abs arCosh.
+ ^self class real: x imaginary: y]
+ ifFalse: [^self class real: 0 imaginary: real arcCos]].
+ tmp := self squaredNorm - 1 / 2.
+ delta := tmp squared + imaginary squared.
+ sh2x := tmp + delta sqrt.
+ shx := sh2x sqrt.
+ ch2x := 1 + sh2x.
+ chx := ch2x sqrt.
+ x := shx arSinh.
+ y := imaginary copySignTo: (real / chx) arcCos.
+ ^self class real: x imaginary: y!
- ifFalse: [(self + (self * self - 1) sqrt) ln negated]"
-
- ^self arcCos i negated!
Item was changed:
----- Method: Complex>>arcCos (in category 'mathematical functions') -----
arcCos
"Answer the arc cosine of the receiver.
This is the inverse function of cos."
| x y tmp sh2y shy delta ch2y chy |
imaginary = 0 ifTrue: [real abs > 1
ifTrue:
[x := real < 0
ifTrue: [Float pi]
ifFalse: [0].
+ y := real copySignTo: real abs arCosh.
- y := real abs arCosh.
^self class real: x imaginary: y]
ifFalse: [^self class real: real arcCos imaginary: 0]].
tmp := self squaredNorm - 1 / 2.
delta := tmp squared + imaginary squared.
sh2y := tmp + delta sqrt.
shy := sh2y sqrt.
ch2y := 1 + sh2y.
chy := ch2y sqrt.
y := imaginary copySignTo: shy arSinh.
x := (real / chy) arcCos.
^self class real: x imaginary: y negated!
Item was changed:
----- Method: Complex>>arcSin (in category 'mathematical functions') -----
arcSin
"Answer the arc sine of the receiver.
This is the inverse function of sin."
| x y tmp delta sh2y shy ch2y chy |
imaginary = 0
ifTrue:
[real abs > 1
ifTrue:
[x := Float pi / 2 * real sign.
+ y := (real copySignTo: real abs arCosh) negated.
- y := real abs arCosh * real sign.
^self class real: x imaginary: y]
ifFalse: [^self class real: real arcSin imaginary: 0]].
tmp := (self squaredNorm - 1) / 2.
delta := tmp squared + imaginary squared.
sh2y := tmp + delta sqrt.
shy := sh2y sqrt.
ch2y := 1 + sh2y.
chy := ch2y sqrt.
y := imaginary copySignTo: shy arSinh.
x := (real / chy) arcSin.
^self class real: x imaginary: y!
Item was changed:
----- Method: Complex>>cosh (in category 'mathematical functions') -----
cosh
+ "Answer receiver's hyperbolic cosine.
+ Hyperbolic cosine is defined by same power serie expansion as for real numbers, that is in term of exponential:
+ ^ (self exp + self negated exp) / 2.
+ This implementation avoids creating intermediate objects."
+
+ ^self class
+ real: real cosh * imaginary cos
+ imaginary: real sinh * imaginary sin!
- "Answer receiver's hyperbolic cosine."
-
- ^ (self exp + self negated exp) / 2!
Item was changed:
----- Method: Complex>>sinh (in category 'mathematical functions') -----
sinh
+ "Answer receiver's hyperbolic sine.
+ Hyperbolic sine is defined by same power serie expansion as for real numbers, that is in term of exponential:
+ ^ (self exp - self negated exp) / 2.
+ This implementation avoids creating intermediate objects."
+
+ ^self class
+ real: real sinh * imaginary cos
+ imaginary: real cosh * imaginary sin!
- "Answer receiver's hyperbolic sine."
-
- ^ (self exp - self negated exp) / 2!
More information about the Squeak-dev
mailing list
|