Skip to content

Commit f14aad5

Browse files
committed
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
1 parent 0fe954c commit f14aad5

File tree

26 files changed

+54
-49
lines changed

26 files changed

+54
-49
lines changed

contrib/btree_gist/btree_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ gdb_date_dist(const void *a, const void *b, FmgrInfo *flinfo)
9595
DateADTGetDatum(*((const DateADT *) a)),
9696
DateADTGetDatum(*((const DateADT *) b)));
9797

98-
return (float8) Abs(DatumGetInt32(diff));
98+
return (float8) abs(DatumGetInt32(diff));
9999
}
100100

101101

@@ -123,7 +123,7 @@ date_dist(PG_FUNCTION_ARGS)
123123
PG_GETARG_DATUM(0),
124124
PG_GETARG_DATUM(1));
125125

126-
PG_RETURN_INT32(Abs(DatumGetInt32(diff)));
126+
PG_RETURN_INT32(abs(DatumGetInt32(diff)));
127127
}
128128

129129

contrib/btree_gist/btree_float8.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
7979
r = arg1 - arg2;
8080
if (unlikely(isinf(r)) && !isinf(arg1) && !isinf(arg2))
8181
float_overflow_error();
82-
return Abs(r);
82+
return fabs(r);
8383
}
8484

8585

@@ -110,7 +110,7 @@ float8_dist(PG_FUNCTION_ARGS)
110110
if (unlikely(isinf(r)) && !isinf(a) && !isinf(b))
111111
float_overflow_error();
112112

113-
PG_RETURN_FLOAT8(Abs(r));
113+
PG_RETURN_FLOAT8(fabs(r));
114114
}
115115

116116
/**************************************************

contrib/btree_gist/btree_int2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int2_dist(PG_FUNCTION_ARGS)
105105
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
106106
errmsg("smallint out of range")));
107107

108-
ra = Abs(r);
108+
ra = abs(r);
109109

110110
PG_RETURN_INT16(ra);
111111
}

contrib/btree_gist/btree_int4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int4_dist(PG_FUNCTION_ARGS)
106106
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
107107
errmsg("integer out of range")));
108108

109-
ra = Abs(r);
109+
ra = abs(r);
110110

111111
PG_RETURN_INT32(ra);
112112
}

contrib/btree_gist/btree_interval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ intr2num(const Interval *i)
8383
static float8
8484
gbt_intv_dist(const void *a, const void *b, FmgrInfo *flinfo)
8585
{
86-
return (float8) Abs(intr2num((const Interval *) a) - intr2num((const Interval *) b));
86+
return fabs(intr2num((const Interval *) a) - intr2num((const Interval *) b));
8787
}
8888

8989
/*

contrib/btree_gist/btree_time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ gbt_time_dist(const void *a, const void *b, FmgrInfo *flinfo)
118118
i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
119119
TimeADTGetDatumFast(*aa),
120120
TimeADTGetDatumFast(*bb)));
121-
return (float8) Abs(INTERVAL_TO_SEC(i));
121+
return fabs(INTERVAL_TO_SEC(i));
122122
}
123123

124124

contrib/btree_gist/btree_ts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
123123
i = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
124124
TimestampGetDatumFast(*aa),
125125
TimestampGetDatumFast(*bb)));
126-
return (float8) Abs(INTERVAL_TO_SEC(i));
126+
return fabs(INTERVAL_TO_SEC(i));
127127
}
128128

129129

contrib/btree_gist/btree_utils_num.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef struct
8787
(ivp)->day * (24.0 * SECS_PER_HOUR) + \
8888
(ivp)->month * (30.0 * SECS_PER_DAY))
8989

90-
#define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
90+
#define GET_FLOAT_DISTANCE(t, arg1, arg2) fabs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
9191

9292

9393
extern Interval *abs_interval(Interval *a);

contrib/btree_gist/btree_utils_var.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
426426
tmp[1] = (unsigned char) (((VARSIZE(uk.lower) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.lower)[ul]));
427427
tmp[2] = (unsigned char) (((VARSIZE(ok.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(ok.upper)[ul]));
428428
tmp[3] = (unsigned char) (((VARSIZE(uk.upper) - VARHDRSZ) <= ul) ? 0 : (VARDATA(uk.upper)[ul]));
429-
dres = Abs(tmp[0] - tmp[1]) + Abs(tmp[3] - tmp[2]);
429+
dres = abs(tmp[0] - tmp[1]) + abs(tmp[3] - tmp[2]);
430430
dres /= 256.0;
431431
}
432432

contrib/cube/cube.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ rt_cube_size(NDBOX *a, double *size)
925925
{
926926
result = 1.0;
927927
for (i = 0; i < DIM(a); i++)
928-
result *= Abs(UR_COORD(a, i) - LL_COORD(a, i));
928+
result *= fabs(UR_COORD(a, i) - LL_COORD(a, i));
929929
}
930930
*size = result;
931931
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy