File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.123 2006/03/11 01:19:22 neilc Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.124 2006/04/24 20:36:32 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -2373,11 +2373,22 @@ float84ge(PG_FUNCTION_ARGS)
23732373/* ========== PRIVATE ROUTINES ========== */
23742374
23752375#ifndef HAVE_CBRT
2376+
23762377static double
23772378cbrt (double x )
23782379{
23792380 int isneg = (x < 0.0 );
2380- double tmpres = pow (fabs (x ), (double ) 1.0 / (double ) 3.0 );
2381+ double absx = fabs (x );
2382+ double tmpres = pow (absx , (double ) 1.0 / (double ) 3.0 );
2383+
2384+ /*
2385+ * The result is somewhat inaccurate --- not really pow()'s fault,
2386+ * as the exponent it's handed contains roundoff error. We can improve
2387+ * the accuracy by doing one iteration of Newton's formula. Beware of
2388+ * zero input however.
2389+ */
2390+ if (tmpres > 0.0 )
2391+ tmpres -= (tmpres - absx /(tmpres * tmpres )) / (double ) 3.0 ;
23812392
23822393 return isneg ? - tmpres : tmpres ;
23832394}
You can’t perform that action at this time.
0 commit comments