1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 The algorithm is based in part on "Optimal Partitioning of
9 Newton's Method for Calculating Roots", by Gunter Meinardus
10 and G. D. Taylor, Mathematics of Computation © 1980 American
12 (http://www.jstor.org/stable/2006387?seq=9, accessed 11-Feb-2010)
15 // Cbrt returns the cube root of x.
21 func Cbrt(x
float64) float64 {
38 case x
== 0 ||
IsNaN(x
) ||
IsInf(x
, 0):
46 // Reduce argument and estimate cube root
47 f
, e
:= Frexp(x
) // 0.5 <= f < 1.0
51 e
-= m
// e is multiple of 3
54 case 0: // 0.5 <= f < 1.0
55 f
= A1
*f
+ A2
- A3
/(A4
+f
)
57 f
*= 0.5 // 0.25 <= f < 0.5
58 f
= B1
*f
+ B2
- B3
/(B4
+f
)
60 f
*= 0.25 // 0.125 <= f < 0.25
61 f
= C1
*f
+ C2
- C3
/(C4
+f
)
63 y
:= Ldexp(f
, e
/3) // e/3 = exponent of cube root
68 y
*= (t
+ x
) / (s
+ t
)
71 y
-= y
* (((14.0/81.0)*s
-(2.0/9.0))*s
+ (1.0 / 3.0)) * s