1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Remove unnecessary uses of Abs()

Use C standard abs() or fabs() instead.

Reviewed-by: Zhang Mingli <zmlpostgres@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/4beb42b5-216b-bce8-d452-d924d5794c63%40enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-10-07 13:28:38 +02:00
parent 0fe954c285
commit f14aad5169
26 changed files with 54 additions and 49 deletions

View File

@@ -95,7 +95,7 @@ gdb_date_dist(const void *a, const void *b, FmgrInfo *flinfo)
DateADTGetDatum(*((const DateADT *) a)),
DateADTGetDatum(*((const DateADT *) b)));
return (float8) Abs(DatumGetInt32(diff));
return (float8) abs(DatumGetInt32(diff));
}
@@ -123,7 +123,7 @@ date_dist(PG_FUNCTION_ARGS)
PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1));
PG_RETURN_INT32(Abs(DatumGetInt32(diff)));
PG_RETURN_INT32(abs(DatumGetInt32(diff)));
}

View File

@@ -79,7 +79,7 @@ gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
r = arg1 - arg2;
if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
float_overflow_error();
return Abs(r);
return fabs(r);
}
@@ -110,7 +110,7 @@ float8_dist(PG_FUNCTION_ARGS)
if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
float_overflow_error();
PG_RETURN_FLOAT8(Abs(r));
PG_RETURN_FLOAT8(fabs(r));
}
/**************************************************

View File

@@ -105,7 +105,7 @@ int2_dist(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
ra = Abs(r);
ra = abs(r);
PG_RETURN_INT16(ra);
}

View File

@@ -106,7 +106,7 @@ int4_dist(PG_FUNCTION_ARGS)
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
ra = Abs(r);
ra = abs(r);
PG_RETURN_INT32(ra);
}

View File

@@ -83,7 +83,7 @@ intr2num(const Interval *i)
static float8
gbt_intv_dist(const void *a, const void *b, FmgrInfo *flinfo)
{
return (float8) Abs(intr2num((const Interval *) a) - intr2num((const Interval *) b));
return fabs(intr2num((const Interval *) a) - intr2num((const Interval *) b));
}
/*

View File

@@ -118,7 +118,7 @@ gbt_time_dist(const void *a, const void *b, FmgrInfo *flinfo)
i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
TimeADTGetDatumFast(*aa),
TimeADTGetDatumFast(*bb)));
return (float8) Abs(INTERVAL_TO_SEC(i));
return fabs(INTERVAL_TO_SEC(i));
}

View File

@@ -123,7 +123,7 @@ gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
i = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
TimestampGetDatumFast(*aa),
TimestampGetDatumFast(*bb)));
return (float8) Abs(INTERVAL_TO_SEC(i));
return fabs(INTERVAL_TO_SEC(i));
}

View File

@@ -87,7 +87,7 @@ typedef struct
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
(ivp)->month * (30.0 * SECS_PER_DAY))
#define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
#define GET_FLOAT_DISTANCE(t, arg1, arg2) fabs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
extern Interval *abs_interval(Interval *a);

View File

@@ -426,7 +426,7 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
dres = Abs(tmp[0] - tmp[1]) + Abs(tmp[3] - tmp[2]);
dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[2]);
dres /= 256.0;
}

View File

@@ -925,7 +925,7 @@ rt_cube_size(NDBOX *a, double *size)
{
result = 1.0;
for (i = 0; i < DIM(a); i++)
result *= Abs(UR_COORD(a, i) - LL_COORD(a, i));
result *= fabs(UR_COORD(a, i) - LL_COORD(a, i));
}
*size = result;
}

View File

@@ -4,6 +4,7 @@
#include "postgres.h"
#include <limits.h>
#include <math.h>
#include "_int.h"
#include "access/gist.h"
@@ -539,7 +540,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
union_d = inner_int_union(datum_r, datum_alpha);
rt__int_size(union_d, &size_beta);
pfree(union_d);
costvector[i - 1].cost = Abs((size_alpha - size_l) - (size_beta - size_r));
costvector[i - 1].cost = fabs((size_alpha - size_l) - (size_beta - size_r));
}
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);

View File

@@ -3,6 +3,8 @@
*/
#include "postgres.h"
#include <math.h>
#include "_int.h"
#include "access/gist.h"
#include "access/reloptions.h"
@@ -389,7 +391,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
_j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l, _j, siglen);
size_beta = hemdist(datum_r, _j, siglen);
costvector[j - 1].cost = Abs(size_alpha - size_beta);
costvector[j - 1].cost = abs(size_alpha - size_beta);
}
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);

View File

@@ -7,6 +7,8 @@
*/
#include "postgres.h"
#include <math.h>
#include "access/gist.h"
#include "access/reloptions.h"
#include "access/stratnum.h"
@@ -315,7 +317,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
_j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l, _j, siglen);
size_beta = hemdist(datum_r, _j, siglen);
costvector[j - 1].cost = Abs(size_alpha - size_beta);
costvector[j - 1].cost = abs(size_alpha - size_beta);
}
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);

View File

@@ -952,7 +952,7 @@ restore(char *result, float val, int n)
}
else
{
if (Abs(exp) <= 4)
if (abs(exp) <= 4)
{
/*
* remove the decimal point from the mantissa and write the digits
@@ -1039,7 +1039,7 @@ restore(char *result, float val, int n)
}
}
/* do nothing for Abs(exp) > 4; %e must be OK */
/* do nothing for abs(exp) > 4; %e must be OK */
/* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
/* ... this is not done yet. */