index 3382b86ba0dcb2a33397856e0ef573057c4b5d29..b5147c9aa451ed303b8bdfd11a30fbe737f0778b 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.123 2006年03月11日 01:19:22 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.124 2006年04月24日 20:36:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* ========== PRIVATE ROUTINES ========== */
#ifndef HAVE_CBRT
+
static double
cbrt(double x)
{
int isneg = (x < 0.0);
- double tmpres = pow(fabs(x), (double) 1.0 / (double) 3.0);
+ double absx = fabs(x);
+ double tmpres = pow(absx, (double) 1.0 / (double) 3.0);
+
+ /*
+ * The result is somewhat inaccurate --- not really pow()'s fault,
+ * as the exponent it's handed contains roundoff error. We can improve
+ * the accuracy by doing one iteration of Newton's formula. Beware of
+ * zero input however.
+ */
+ if (tmpres > 0.0)
+ tmpres -= (tmpres - absx/(tmpres*tmpres)) / (double) 3.0;
return isneg ? -tmpres : tmpres;
}