Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 400f169

Browse files
committed
In dpow(), remove redundant check for whether y is an integer.
I failed to notice that we don't really need to check for y being an integer in the code path where x = -inf; we already did. Also make some further cosmetic rearrangements in that spot in hopes of dodging the seeming compiler bug that buildfarm member fossa is hitting. And be consistent about declaring variables as "float8" not "double", since the pre-existing variables in this function are like that. Discussion: https://postgr.es/m/E1jkyFX-0005RR-1Q@gemulon.postgresql.org
1 parent 4dd804a commit 400f169

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/backend/utils/adt/float.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ dpow(PG_FUNCTION_ARGS)
15461546
*/
15471547
if (isinf(arg2))
15481548
{
1549-
double absx = fabs(arg1);
1549+
float8 absx = fabs(arg1);
15501550

15511551
if (absx == 1.0)
15521552
result = 1.0;
@@ -1578,16 +1578,15 @@ dpow(PG_FUNCTION_ARGS)
15781578
}
15791579
else /* x = -Inf */
15801580
{
1581-
bool yisoddinteger = false;
1582-
1583-
if (arg2 == floor(arg2))
1584-
{
1585-
/* y is integral; it's odd if y/2 is not integral */
1586-
double halfy = arg2 / 2; /* should be computed exactly */
1581+
/*
1582+
* Per POSIX, the sign of the result depends on whether y is an
1583+
* odd integer. Since x < 0, we already know from the previous
1584+
* domain check that y is an integer. It is odd if y/2 is not
1585+
* also an integer.
1586+
*/
1587+
float8 halfy = arg2 / 2; /* should be computed exactly */
1588+
bool yisoddinteger = (floor(halfy) != halfy);
15871589

1588-
if (halfy != floor(halfy))
1589-
yisoddinteger = true;
1590-
}
15911590
if (arg2 > 0.0)
15921591
result = yisoddinteger ? arg1 : -arg1;
15931592
else
@@ -1622,7 +1621,7 @@ dpow(PG_FUNCTION_ARGS)
16221621
result = 0.0; /* we already verified y is positive */
16231622
else
16241623
{
1625-
double absx = fabs(arg1);
1624+
float8 absx = fabs(arg1);
16261625

16271626
if (absx == 1.0)
16281627
result = 1.0;

0 commit comments

Comments
 (0)