Status: Fixed
Owner: stephane.ducasse Labels: Milestone-1.2 Type-Squeak New issue 3244 by stephane.ducasse: Correct the confusion radiansToDegrees/degreesToRadians http://code.google.com/p/pharo/issues/detail?id=3244 I integrated the first enh so we should fix it with this change now. Nicolas Cellier uploaded a new version of Kernel to project The Trunk: http://source.squeak.org/trunk/Kernel-nice.511.mcz ==================== Summary ==================== Name: Kernel-nice.511 Author: nice Time: 1 November 2010, 11:59:51.145 am UUID: 4f6eaafc-6665-4092-ac07-d87ecb2b5d30 Ancestors: Kernel-nice.510 Correct the confusion radiansToDegrees/degreesToRadians Thanks Bert =============== Diff against Kernel-nice.510 =============== Item was changed: ----- Method: Float>>degreeCos (in category 'mathematical functions') ----- degreeCos "Take care of exceptional values" self isFinite ifTrue: [^super degreeCos]. + ^self degreesToRadians cos! - ^self radiansToDegrees cos! Item was changed: ----- Method: Float>>degreeSin (in category 'mathematical functions') ----- degreeSin "Take care of exceptional values" self isFinite ifTrue: [^super degreeSin]. + ^self degreesToRadians sin! - ^self radiansToDegrees sin! |
Comment #1 on issue 3244 by stephane.ducasse: Correct the confusion radiansToDegrees/degreesToRadians http://code.google.com/p/pharo/issues/detail?id=3244 Nicolas Cellier uploaded a new version of KernelTests to project The Trunk: http://source.squeak.org/trunk/KernelTests-nice.167.mcz ==================== Summary ==================== Name: KernelTests-nice.167 Author: nice Time: 31 October 2010, 9:55:18.943 pm UUID: 669b4442-43de-4da0-83d3-649e77bca967 Ancestors: KernelTests-nice.166 Assert that #degreeCos and #degreeSin are exact for any multiple of 90. This is a nice property to have that radianCos and radianSin cannot afford due to approximate floating point representation of pi. =============== Diff against KernelTests-nice.166 =============== Item was added: + ----- Method: FloatTest>>testDegreeCos (in category 'test - mathematical functions') ----- + testDegreeCos + self shouldnt: [ 45.0 degreeCos] raise: Error. + "Following tests use approximate equality, because cosine are generally evaluated using inexact Floating point arithmetic" + self assert: (45.0 degreeCos squared - 0.5) abs <= Float epsilon. + self assert: (60.0 degreeCos - 0.5) abs <= Float epsilon. + self assert: (120.0 degreeCos + 0.5) abs <= Float epsilon. + -360.0 to: 360.0 do: [:i | + self assert: (i degreeCos closeTo: i degreesToRadians cos)]. + + "Following tests use strict equality which is a requested property of degreeCos" + -10.0 to: 10.0 do: [:k | + self assert: (k*360 + 90) degreeCos = 0. + self assert: (k*360 - 90) degreeCos = 0. + self assert: (k*360 + 180) degreeCos + 1 = 0. + self assert: (k*360) degreeCos - 1 = 0.].! Item was added: + ----- Method: FloatTest>>testDegreeCosForExceptionalValues (in category 'test - mathematical functions') ----- + testDegreeCosForExceptionalValues + self assert: Float nan degreeCos isNaN. + self assert: Float infinity degreeCos isNaN. + self assert: Float infinity negated degreeCos isNaN.! Item was added: + ----- Method: FloatTest>>testDegreeSin (in category 'test - mathematical functions') ----- + testDegreeSin + self shouldnt: [ 45.0 degreeSin] raise: Error. + "Following tests use approximate equality, because sine are generally evaluated using inexact Floating point arithmetic" + self assert: (45.0 degreeSin squared - 0.5) abs <= Float epsilon. + self assert: (30.0 degreeSin - 0.5) abs <= Float epsilon. + self assert: (-30.0 degreeSin + 0.5) abs <= Float epsilon. + -360.0 to: 360.0 do: [:i | + self assert: (i degreeSin closeTo: i degreesToRadians sin)]. + + "Following tests use strict equality which is a requested property of degreeSin" + -10.0 to: 10.0 do: [:k | + self assert: (k*360 + 90) degreeSin - 1 = 0. + self assert: (k*360 - 90) degreeSin + 1= 0. + self assert: (k*360 + 180) degreeSin = 0. + self assert: (k*360) degreeSin = 0.].! Item was added: + ----- Method: FloatTest>>testDegreeSinForExceptionalValues (in category 'test - mathematical functions') ----- + testDegreeSinForExceptionalValues + self assert: Float nan degreeSin isNaN. + self assert: Float infinity degreeSin isNaN. + self assert: Float infinity negated degreeSin isNaN.! Item was changed: + ----- Method: FractionTest>>testDegreeCos (in category 'tests - mathematical functions') ----- - ----- Method: FractionTest>>testDegreeCos (in category 'tests - sinuses') ----- testDegreeCos "self run: #testDegreeCos" self shouldnt: [ (4/3) degreeCos] raise: Error. + -361/3 to: 359/3 do: [:i | + self assert: (i degreeCos closeTo: i degreesToRadians cos)].! - self assert: (1/3) degreeCos printString = '0.999983076857744'! Item was changed: + ----- Method: FractionTest>>testDegreeSin (in category 'tests - mathematical functions') ----- - ----- Method: FractionTest>>testDegreeSin (in category 'tests - sinuses') ----- testDegreeSin "self run: #testDegreeSin" self shouldnt: [ (4/3) degreeSin] raise: Error. + -361/3 to: 359/3 do: [:i | + self assert: (i degreeSin closeTo: i degreesToRadians sin)].! - self assert: (1/3) degreeSin printString = '0.005817731354993834'.! Item was changed: + ----- Method: IntegerTest>>testDegreeCos (in category 'tests - mathematical functions') ----- - ----- Method: IntegerTest>>testDegreeCos (in category 'tests - basic') ----- testDegreeCos "self run: #testDegreeCos" self shouldnt: [ 45 degreeCos] raise: Error. + "Following tests use approximate equality, because cosine are generally evaluated using inexact Floating point arithmetic" + self assert: (45 degreeCos squared - (1/2)) abs <= Float epsilon. + self assert: (60 degreeCos - (1/2)) abs <= Float epsilon. + self assert: (120 degreeCos + (1/2)) abs <= Float epsilon. + -360 to: 360 do: [:i | + self assert: (i degreeCos closeTo: i degreesToRadians cos)]. + + "Following tests use strict equality which is a requested property of degreeCos" + -10 to: 10 do: [:k | + self assert: (k*360 + 90) degreeCos = 0. + self assert: (k*360 - 90) degreeCos = 0. + self assert: (k*360 + 180) degreeCos + 1 = 0. + self assert: (k*360) degreeCos - 1 = 0.].! - self assert: 45 degreeCos printString = (2 sqrt / 2) asFloat printString ! Item was added: + ----- Method: IntegerTest>>testDegreeSin (in category 'tests - mathematical functions') ----- + testDegreeSin + "self run: #testDegreeSin" + + self shouldnt: [ 45 degreeSin] raise: Error. + + "Following tests use approximate equality, because sine are generally evaluated using inexact Floating point arithmetic" + self assert: (45 degreeSin squared - (1/2)) abs <= Float epsilon. + self assert: (30 degreeSin - (1/2)) abs <= Float epsilon. + self assert: (-30 degreeSin + (1/2)) abs <= Float epsilon. + -360 to: 360 do: [:i | + self assert: (i degreeSin closeTo: i degreesToRadians sin)]. + + "Following tests use strict equality which is a requested property of degreeSin" + -10 to: 10 do: [:k | + self assert: (k*360 + 90) degreeSin - 1 = 0. + self assert: (k*360 - 90) degreeSin + 1= 0. + self assert: (k*360 + 180) degreeSin = 0. + self assert: (k*360) degreeSin = 0].! |
Updates:
Status: closed Comment #2 on issue 3244 by stephane.ducasse: Correct the confusion radiansToDegrees/degreesToRadians http://code.google.com/p/pharo/issues/detail?id=3244 in 12234 |
Updates:
Status: Closed Comment #3 on issue 3244 by stephane.ducasse: Correct the confusion radiansToDegrees/degreesToRadians http://code.google.com/p/pharo/issues/detail?id=3244 (No comment was entered for this change.) |
Free forum by Nabble | Edit this page |