Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit332ea60

Browse files
committed
Improve our private implementation of cbrt() to give results of the
accuracy expected by the regression tests. Per suggestion fromMartijn van Oosterhout.
1 parent7e97b41 commit332ea60

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

‎src/backend/utils/adt/float.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
#ifndefHAVE_CBRT
2376+
23762377
staticdouble
23772378
cbrt(doublex)
23782379
{
23792380
intisneg= (x<0.0);
2380-
doubletmpres=pow(fabs(x), (double)1.0 / (double)3.0);
2381+
doubleabsx=fabs(x);
2382+
doubletmpres=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
returnisneg ?-tmpres :tmpres;
23832394
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp