Nicolas Cellier uploaded a new version of Kernel to project The Trunk: http://source.squeak.org/trunk/Kernel-nice.510.mcz
==================== Summary ====================
Name: Kernel-nice.510 Author: nice Time: 31 October 2010, 10:25:03.794 pm UUID: 80b9fa44-3abc-4414-adae-10f3f03b0420 Ancestors: Kernel-ul.509
Provide an implementation of #degreeCos and #degreeSin such that results are exact for any multiple of 90.
Care is also taken to evaluate the sine between -90° and 90°, this will avoid #degreesToRadians and i386 FPU sine fonction to accumulate round off errors due to approximate representation of pi. We can thus evaluate 240 degreeCos with at most 1 ulp error. It's not perfect, but better than previous implementation.
For cosine, we know that: cosd(x)=cosd(abs(x)) cosd(x)=sind(90-x) thus the trick is to evaluate: cosd(x)=sind(90-abs(x)) after appropriate modulo in [-180,180[ This way, we are sure to evaluate the sine between -90° and 90° The #degreesToRadians and #sin are used rather than #degreeSin to avoid cycles.
For sine, it would be necessary to evaluate either sind(x) if abs(x) <=90 or sind(180-x) if abs(x) >= 90 A possible implementation would be: | x | x := 90 + self \ 360 - 90. x >= 180 ifTrue: [x := 180 - x]. ^x degreesToRadians sin We prefer evaluating cosd(90-x) thus providing a branch free implementation.
=============== Diff against Kernel-ul.509 ===============
Item was changed: ----- Method: Float>>degreeCos (in category 'mathematical functions') ----- degreeCos + "Take care of exceptional values" + + self isFinite ifTrue: [^super degreeCos]. + ^self radiansToDegrees cos! - "Answer the cosine of the receiver taken as an angle in degrees." - - ^ self degreesToRadians cos!
Item was changed: ----- Method: Float>>degreeSin (in category 'mathematical functions') ----- degreeSin + "Take care of exceptional values" + + self isFinite ifTrue: [^super degreeSin]. + ^self radiansToDegrees sin! - "Answer the sine of the receiver taken as an angle in degrees." - - ^ self degreesToRadians sin!
Item was changed: ----- Method: Number>>degreeCos (in category 'mathematical functions') ----- degreeCos "Answer the cosine of the receiver taken as an angle in degrees." + ^ (90 - (180 + self \ 360 - 180) abs) degreesToRadians sin! - ^ (90 + self) degreeSin!
Item was changed: ----- Method: Number>>degreeSin (in category 'mathematical functions') ----- degreeSin "Answer the sine of the receiver taken as an angle in degrees." + ^(90 - self) degreeCos! - ^ self asFloat degreesToRadians sin!
squeak-dev@lists.squeakfoundation.org