mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +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:
@ -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)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user