Don't use is_infinite() where isinf() will do.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Oct 2018 17:18:38 +0000 (13:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Oct 2018 17:18:38 +0000 (13:18 -0400)
Places that aren't testing for sign should not use the more expensive
function; it's just wasteful, not to mention being a cognitive load
for readers who may know what isinf() is but not is_infinite().

As things stand, we actually don't need is_infinite() anyplace except
float4out/float8out, which means it could potentially go away altogether
after the changes I proposed in <13178.1538794717@sss.pgh.pa.us>.

src/backend/utils/adt/formatting.c
src/backend/utils/adt/rangetypes_selfuncs.c

index 0ed59f1c347fbf5ed3dfad9747d8b8620de34955..5d472d01133e641fd8bce643e44d629f15ee327e 100644 (file)
@@ -5731,7 +5731,7 @@ float4_to_char(PG_FUNCTION_ARGS)
        numstr = orgnum = int_to_roman((int) rint(value));
    else if (IS_EEEE(&Num))
    {
-       if (isnan(value) || is_infinite(value))
+       if (isnan(value) || isinf(value))
        {
            /*
             * Allow 6 characters for the leading sign, the decimal point,
@@ -5835,7 +5835,7 @@ float8_to_char(PG_FUNCTION_ARGS)
        numstr = orgnum = int_to_roman((int) rint(value));
    else if (IS_EEEE(&Num))
    {
-       if (isnan(value) || is_infinite(value))
+       if (isnan(value) || isinf(value))
        {
            /*
             * Allow 6 characters for the leading sign, the decimal point,
index f9a511749271af2c5129197b622b66123c2d4656..32c493309596a61064e6f77f9ec108db826d2499 100644 (file)
@@ -17,6 +17,8 @@
  */
 #include "postgres.h"
 
+#include <math.h>
+
 #include "access/htup_details.h"
 #include "catalog/pg_operator.h"
 #include "catalog/pg_statistic.h"
@@ -750,19 +752,19 @@ get_position(TypeCacheEntry *typcache, RangeBound *value, RangeBound *hist1,
 static double
 get_len_position(double value, double hist1, double hist2)
 {
-   if (!is_infinite(hist1) && !is_infinite(hist2))
+   if (!isinf(hist1) && !isinf(hist2))
    {
        /*
         * Both bounds are finite. The value should be finite too, because it
         * lies somewhere between the bounds. If it doesn't, just return
         * something.
         */
-       if (is_infinite(value))
+       if (isinf(value))
            return 0.5;
 
        return 1.0 - (hist2 - value) / (hist2 - hist1);
    }
-   else if (is_infinite(hist1) && !is_infinite(hist2))
+   else if (isinf(hist1) && !isinf(hist2))
    {
        /*
         * Lower bin boundary is -infinite, upper is finite. Return 1.0 to
@@ -770,7 +772,7 @@ get_len_position(double value, double hist1, double hist2)
         */
        return 1.0;
    }
-   else if (is_infinite(hist1) && is_infinite(hist2))
+   else if (isinf(hist1) && isinf(hist2))
    {
        /* same as above, but in reverse */
        return 0.0;
@@ -851,7 +853,7 @@ calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
        return 0.0;             /* shouldn't happen, but doesn't hurt to check */
 
    /* All lengths in the table are <= infinite. */
-   if (is_infinite(length2) && equal)
+   if (isinf(length2) && equal)
        return 1.0;
 
    /*----------
@@ -978,7 +980,7 @@ calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
     * length2 is infinite. It's not clear what the correct value would be in
     * that case, so 0.5 seems as good as any value.
     */
-   if (is_infinite(area) && is_infinite(length2))
+   if (isinf(area) && isinf(length2))
        frac = 0.5;
    else
        frac = area / (length2 - length1);