nicolas cellier uploaded a new version of Math-Number-Extensions to project Math-Number-Extensions:
http://www.squeaksource.com/NumberExtensions/Math-Number-Extensions-nice.6.mcz
==================== Summary ====================
Name: Math-Number-Extensions-nice.6
Author: nice
Time: 1 October 2019, 2:38:18.245496 pm
UUID: d896ff55-132a-b44a-a647-ff57df9ec8db
Ancestors: Math-Number-Extensions-nice.5
Provide a piCos and piSin mathematical function
Conceptually:
x piCos = (x * Float pi) cos.
x piSin= (x * Float pi) sin.
Except that care is taken to be more exact than naive formulation above.
Also care is taken to answer an exact rational when rational fraction of pi takes a rational sine or cosine value.
Thanks to Niven theorem, such rational result can only be among {-1. -1/2. 0. 1/2. 1}.
Note that such exactness is at the price of weak monotonicity.
There is no guaranty that (1/6+eps) piSin >= (1/6 piSin) for small rational eps value.
Example with current implementation:
(1/6+(1<<100) reciprocal) piSin < (1/6) piSin
=============== Diff against Math-Number-Extensions-nice.5 ===============
Item was added:
+ ----- Method: BoxedFloat64>>piCos (in category '*Math-Number-Extensions-mathematical functions') -----
+ piCos
+ self isFinite ifTrue: [^super piCos].
+ ^Float nan!
Item was added:
+ ----- Method: BoxedFloat64>>piSin (in category '*Math-Number-Extensions-mathematical functions') -----
+ piSin
+ self isFinite ifTrue: [^super piSin].
+ ^Float nan!
Item was added:
+ ----- Method: Float>>piCos (in category '*Math-Number-Extensions-mathematical functions') -----
+ piCos
+ self abs >= 9007199254740992.0 "Float maxExactInteger"
+ ifTrue:
+ ["exact value of every such finite big Float is an even Integer"
+ ^1.0].
+ ^super piCos!
Item was added:
+ ----- Method: Float>>piSin (in category '*Math-Number-Extensions-mathematical functions') -----
+ piSin
+ self abs >= 9007199254740992.0 "Float maxExactInteger"
+ ifTrue:
+ ["exact value of every such finite big Float is an even Integer"
+ ^0.0].
+ ^super piSin!
Item was added:
+ ----- Method: Fraction>>piCos (in category '*Math-Number-Extensions-mathematical functions') -----
+ piCos
+ "Note: answer an exact rational when the result is an exact rational.
+ Based on Nivens theorem, see http://mathworld.wolfram.com/NivensTheorem.html"
+ denominator = 2 ifTrue: [^0].
+ ^super piCos!
Item was added:
+ ----- Method: Fraction>>piSin (in category '*Math-Number-Extensions-mathematical functions') -----
+ piSin
+ "Note: answer an exact rational when the result is an exact rational.
+ Based on Nivens theorem, see http://mathworld.wolfram.com/NivensTheorem.html"
+ denominator = 2 ifTrue: [^(numerator - 1 / 2) piCos].
+ (denominator = 6 and: [numerator abs = 1]) ifTrue: [^numerator / 2].
+ ^super piSin!
Item was added:
+ ----- Method: Integer>>piCos (in category '*Math-Number-Extensions-mathematical functions') -----
+ piCos
+ ^self even
+ ifTrue: [1]
+ ifFalse: [-1]!
Item was added:
+ ----- Method: Integer>>piSin (in category '*Math-Number-Extensions-mathematical functions') -----
+ piSin
+ ^0!
Item was added:
+ ----- Method: Number>>piCos (in category '*Math-Number-Extensions-mathematical functions') -----
+ piCos
+ "Return the cosine of receiver multiplied by pi"
+ | a n r |
+ (a := self abs) < 0.25 ifTrue: [^(self * Float pi) cos].
+ n := (self * 2) rounded.
+ r := self - (n / 2).
+ ^(n bitAnd: 3) caseOf: {
+ [0]->[^r piCos].
+ [1]->[^r piSin negated].
+ [2]->[^r piCos negated].
+ [3]->[^r piSin]}!
Item was added:
+ ----- Method: Number>>piSin (in category '*Math-Number-Extensions-mathematical functions') -----
+ piSin
+ "Return the sine of receiver multiplied by pi"
+ | a n r |
+ (a := self abs) <= 0.25 ifTrue: [^(self * Float pi) sin].
+ n := (self * 2) rounded.
+ r := self - (n / 2).
+ ^(n bitAnd: 3) caseOf: {
+ [0]->[^r piSin].
+ [1]->[^r piCos].
+ [2]->[^r piSin negated].
+ [3]->[^r piCos negated]}!