19e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com/*
29e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * Copyright 2012 Google Inc.
39e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com *
49e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * Use of this source code is governed by a BSD-style license that can be
59e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com * found in the LICENSE file.
69e49fb63d355446b91d20ff78ad78b297e89a50dcaryclark@google.com */
7d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com// http://metamerist.com/cbrt/CubeRoot.cpp
8639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com//
9639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
10639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#include <math.h>
1127accef223a27fba437f5e825d99edbae20a045bcaryclark@google.com#include "CubicUtilities.h"
12639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
13639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#define TEST_ALTERNATIVES 0
14639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#if TEST_ALTERNATIVES
15639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comtypedef float  (*cuberootfnf) (float);
16639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comtypedef double (*cuberootfnd) (double);
17639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
18639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// estimate bits of precision (32-bit float case)
19639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.cominline int bits_of_precision(float a, float b)
20639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
21d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const double kd = 1.0 / log(2.0);
22639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
23d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    if (a==b)
24d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        return 23;
25639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
26d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const double kdmin = pow(2.0, -23.0);
27639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
28d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double d = fabs(a-b);
29d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    if (d < kdmin)
30d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        return 23;
31639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
32d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return int(-log(d)*kd);
33639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
34639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
35639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// estiamte bits of precision (64-bit double case)
36639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.cominline int bits_of_precision(double a, double b)
37639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
38d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const double kd = 1.0 / log(2.0);
39639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
40d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    if (a==b)
41d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        return 52;
42639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
43d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const double kdmin = pow(2.0, -52.0);
44639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
45d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double d = fabs(a-b);
46d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    if (d < kdmin)
47d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        return 52;
48639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
49d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return int(-log(d)*kd);
50639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
51639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
52639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root via x^(1/3)
53639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float pow_cbrtf(float x)
54639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
55d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return (float) pow(x, 1.0f/3.0f);
56639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
57639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
58639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root via x^(1/3)
59639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double pow_cbrtd(double x)
60639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
61d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return pow(x, 1.0/3.0);
62639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
63639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
64639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using bit hack for 32-bit float
65639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  float cbrt_5f(float f)
66639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
67d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    unsigned int* p = (unsigned int *) &f;
68d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    *p = *p/3 + 709921077;
69d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return f;
70639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
71639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#endif
72639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
73d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com// cube root approximation using bit hack for 64-bit float
74639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// adapted from Kahan's cbrt
75639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  double cbrt_5d(double d)
76639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
77d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const unsigned int B1 = 715094163;
78d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double t = 0.0;
79d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    unsigned int* pt = (unsigned int*) &t;
80d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    unsigned int* px = (unsigned int*) &d;
81d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    pt[1]=px[1]/3+B1;
82d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return t;
83639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
84639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
85639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#if TEST_ALTERNATIVES
86d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com// cube root approximation using bit hack for 64-bit float
87639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// adapted from Kahan's cbrt
88639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#if 0
89639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  double quint_5d(double d)
90639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
91d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return sqrt(sqrt(d));
92d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
93d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const unsigned int B1 = 71509416*5/3;
94d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double t = 0.0;
95d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    unsigned int* pt = (unsigned int*) &t;
96d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    unsigned int* px = (unsigned int*) &d;
97d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    pt[1]=px[1]/5+B1;
98d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return t;
99639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
100639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#endif
101639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
102639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// iterative cube root approximation using Halley's method (float)
103639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  float cbrta_halleyf(const float a, const float R)
104639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
105d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const float a3 = a*a*a;
106639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com    const float b= a * (a3 + R + R) / (a3 + a3 + R);
107d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return b;
108639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
109639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#endif
110639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
111639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// iterative cube root approximation using Halley's method (double)
112639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  double cbrta_halleyd(const double a, const double R)
113639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
114d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    const double a3 = a*a*a;
115639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com    const double b= a * (a3 + R + R) / (a3 + a3 + R);
116d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return b;
117639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
118639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
119639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#if TEST_ALTERNATIVES
120639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// iterative cube root approximation using Newton's method (float)
121639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  float cbrta_newtonf(const float a, const float x)
122639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
123639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com//    return (1.0 / 3.0) * ((a + a) + x / (a * a));
124d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return a - (1.0f / 3.0f) * (a - x / (a*a));
125639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
126639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
127639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// iterative cube root approximation using Newton's method (double)
128639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic  double cbrta_newtond(const double a, const double x)
129639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
130d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return (1.0/3.0) * (x / (a*a) + 2*a);
131639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
132639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
133639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 1 iteration of Halley's method (double)
134639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double halley_cbrt1d(double d)
135639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
136d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
137d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_halleyd(a, d);
138639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
139639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
140639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 1 iteration of Halley's method (float)
141639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float halley_cbrt1f(float d)
142639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
143d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    float a = cbrt_5f(d);
144d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_halleyf(a, d);
145639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
146639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
147639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 2 iterations of Halley's method (double)
148639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double halley_cbrt2d(double d)
149639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
150d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
151d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_halleyd(a, d);
152d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_halleyd(a, d);
153639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
154639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#endif
155639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
156639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 3 iterations of Halley's method (double)
157639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double halley_cbrt3d(double d)
158639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
159d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
160d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_halleyd(a, d);
161d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_halleyd(a, d);
162d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_halleyd(a, d);
163639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
164639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
165639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com#if TEST_ALTERNATIVES
166639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 2 iterations of Halley's method (float)
167639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float halley_cbrt2f(float d)
168639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
169d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    float a = cbrt_5f(d);
170d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_halleyf(a, d);
171d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_halleyf(a, d);
172639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
173639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
174639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 1 iteration of Newton's method (double)
175639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double newton_cbrt1d(double d)
176639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
177d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
178d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtond(a, d);
179639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
180639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
181639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 2 iterations of Newton's method (double)
182639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double newton_cbrt2d(double d)
183639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
184d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
185d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
186d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtond(a, d);
187639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
188639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
189639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 3 iterations of Newton's method (double)
190639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double newton_cbrt3d(double d)
191639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
192d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
193d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
194d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
195d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtond(a, d);
196639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
197639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
198639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 4 iterations of Newton's method (double)
199639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic double newton_cbrt4d(double d)
200639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
201d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    double a = cbrt_5d(d);
202d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
203d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
204d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtond(a, d);
205d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtond(a, d);
206639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
207639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
208639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 2 iterations of Newton's method (float)
209639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float newton_cbrt1f(float d)
210639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
211d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    float a = cbrt_5f(d);
212d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtonf(a, d);
213639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
214639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
215639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 2 iterations of Newton's method (float)
216639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float newton_cbrt2f(float d)
217639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
218d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    float a = cbrt_5f(d);
219d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    a = cbrta_newtonf(a, d);
220d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    return cbrta_newtonf(a, d);
221639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com}
222639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com
223639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com// cube root approximation using 3 iterations of Newton's method (float)
224639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.comstatic float newton_cbrt3f(float d)
225639df891487e40925a4f8d9a34fd3dc0c18b40a7caryclark@google.com{
226d6176b0