--- a/Number.st Tue Feb 13 12:01:48 2018 +0100
+++ b/Number.st Thu Feb 15 19:03:54 2018 +0100
@@ -592,6 +592,7 @@
"Modified (comment): / 08-06-2017 / 13:58:36 / mawalch"
! !
+
!Number class methodsFor:'constants'!
e
@@ -835,6 +836,7 @@
"
! !
+
!Number class methodsFor:'private'!
readMantissaAndScaleFrom:aStream radix:radix
@@ -929,6 +931,7 @@
^ self == Number
! !
+
!Number methodsFor:'Compatibility-Squeak'!
asSmallAngleDegrees
@@ -1087,6 +1090,7 @@
"Modified: / 25-07-2017 / 15:58:46 / cg"
! !
+
!Number methodsFor:'coercing & converting'!
i
@@ -2791,7 +2795,7 @@
"/ 3 15 315 2835 (2n)!!
"/ where Bi is the ith bernoulli number.
- |factors idx x2 num t approx lastApprox delta|
+ |factors idx x2 num t approx lastApprox delta nFactors|
"/ (1 to:20) collect:[:n| |num den|
"/ num := (2 raisedTo:(2*n)) * ((2 raisedTo:(2*n))-1) * ((n*2) bernoulli).
@@ -2799,49 +2803,50 @@
"/ num / den
"/ ]
factors := #(
- (1 3)
- (2 15)
- (17 315)
- (62 2835)
- (1382 155925)
- (21844 6081075)
- (929569 638512875)
- (6404582 10854718875)
- (443861162 1856156927625)
- (18888466084 194896477400625)
- (113927491862 2900518163668125)
- (58870668456604 3698160658676859375)
- (8374643517010684 1298054391195577640625)
- (689005380505609448 263505041412702261046875)
- (129848163681107301953 122529844256906551386796875)
- (1736640792209901647222 4043484860477916195764296875)
- (418781231495293038913922 2405873491984360136479756640625)
- (56518638202982204522669764 801155872830791925447758961328125)
- (32207686319158956594455462 1126482925555250126673224649609375)).
-
+ (1 3)
+ (2 15)
+ (17 315)
+ (62 2835)
+ (1382 155925)
+ (21844 6081075)
+ (929569 638512875)
+ (6404582 10854718875)
+ (443861162 1856156927625)
+ (18888466084 194896477400625)
+ (113927491862 2900518163668125)
+ (58870668456604 3698160658676859375)
+ (8374643517010684 1298054391195577640625)
+ (689005380505609448 263505041412702261046875)
+ (129848163681107301953 122529844256906551386796875)
+ (1736640792209901647222 4043484860477916195764296875)
+ (418781231495293038913922 2405873491984360136479756640625)
+ (56518638202982204522669764 801155872830791925447758961328125)
+ (32207686319158956594455462 1126482925555250126673224649609375)).
+
+ nFactors := factors size.
x2 := self * self.
-
num := x2 * self. "/ = x^3
approx := self + (num / 3). "/ do the first iteration
lastApprox := self.
idx := 2.
[
- t := factors at:idx ifAbsent:[].
- t isNil ifTrue:[
- self error:'too many iterations'.
+ idx > nFactors ifTrue:[
+ ArithmeticError raiseErrorString:'too many iterations'.
"/ Not enough bernoulli numbers for now...
"/ |tempNum tempDen|
"/ tempNum := 2 raisedTo:(2*idx).
"/ tempNum := tempNum * (tempNum-1) * ((2*idx) bernoulli).
"/ tempDen := (2*idx) factorial.
"/ t := Array with:tempNum with:tempDen.
- ].
- idx := idx + 1.
- num := num * x2.
-
- delta := num * t first / t second.
- approx := approx + delta.
- ] doUntil:[delta abs <= epsilon].
+ ].
+ t := factors at:idx.
+ idx := idx + 1.
+ num := num * x2.
+
+ delta := num * t first / t second.
+ approx := approx + delta.
+ delta abs > epsilon
+ ] whileTrue.
^ approx
"
@@ -2856,6 +2861,8 @@
0.5q tan_withAccuracy:1e-40 -- too many iterations
"
+
+ "Modified: / 15-02-2018 / 18:53:37 / stefan"
! !
!Number methodsFor:'testing'!
@@ -3369,6 +3376,7 @@
"Modified: / 5.11.2001 / 17:54:22 / cg"
! !
+
!Number class methodsFor:'documentation'!
version