diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-08-01 18:29:35 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-08-01 18:29:35 +0000 |
commit | 463f1f5cdaecf229dcd1d3d16e969bf3a7aa9a73 (patch) | |
tree | e212492457fbf4f54cb12c160cc3f8a602256871 /src/backend/utils/adt/cash.c | |
parent | 92bd532c1e8b65f4f4d09ffb453782b29d6d1e42 (diff) |
Convert all remaining float4 and float8 functions to new fmgr style.
At this point I think it'd be possible to make float4 be pass-by-value
without too much work --- and float8 too on machines where Datum is
8 bytes. Something to try when the mood strikes, anyway.
Diffstat (limited to 'src/backend/utils/adt/cash.c')
-rw-r--r-- | src/backend/utils/adt/cash.c | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index b85f37942c1..e1a68940a84 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -9,7 +9,7 @@ * workings can be found in the book "Software Solutions in C" by * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.43 2000/07/07 18:49:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.44 2000/08/01 18:29:35 tgl Exp $ */ #include <limits.h> @@ -425,31 +425,31 @@ cash_mi(Cash *c1, Cash *c2) /* cash_mul_flt8() * Multiply cash by float8. */ -Cash * -cash_mul_flt8(Cash *c, float8 *f) +Datum +cash_mul_flt8(PG_FUNCTION_ARGS) { - Cash *result; - - if (!PointerIsValid(f) || !PointerIsValid(c)) - return NULL; - - if (!PointerIsValid(result = palloc(sizeof(Cash)))) - elog(ERROR, "Memory allocation failed, can't multiply cash"); - - *result = ((*f) * (*c)); + Cash c = PG_GETARG_CASH(0); + float8 f = PG_GETARG_FLOAT8(1); + Cash result; - return result; -} /* cash_mul_flt8() */ + result = c * f; + PG_RETURN_CASH(result); +} /* flt8_mul_cash() * Multiply float8 by cash. */ -Cash * -flt8_mul_cash(float8 *f, Cash *c) +Datum +flt8_mul_cash(PG_FUNCTION_ARGS) { - return cash_mul_flt8(c, f); -} /* flt8_mul_cash() */ + float8 f = PG_GETARG_FLOAT8(0); + Cash c = PG_GETARG_CASH(1); + Cash result; + + result = f * c; + PG_RETURN_CASH(result); +} /* cash_div_flt8() @@ -458,53 +458,48 @@ flt8_mul_cash(float8 *f, Cash *c) * XXX Don't know if rounding or truncating is correct behavior. * Round for now. - tgl 97/04/15 */ -Cash * -cash_div_flt8(Cash *c, float8 *f) +Datum +cash_div_flt8(PG_FUNCTION_ARGS) { - Cash *result; - - if (!PointerIsValid(f) || !PointerIsValid(c)) - return NULL; - - if (!PointerIsValid(result = palloc(sizeof(Cash)))) - elog(ERROR, "Memory allocation failed, can't divide cash"); + Cash c = PG_GETARG_CASH(0); + float8 f = PG_GETARG_FLOAT8(1); + Cash result; - if (*f == 0.0) + if (f == 0.0) elog(ERROR, "cash_div: divide by 0.0 error"); - *result = rint(*c / *f); - - return result; -} /* cash_div_flt8() */ + result = rint(c / f); + PG_RETURN_CASH(result); +} /* cash_mul_flt4() * Multiply cash by float4. */ -Cash * -cash_mul_flt4(Cash *c, float4 *f) +Datum +cash_mul_flt4(PG_FUNCTION_ARGS) { - Cash *result; - - if (!PointerIsValid(f) || !PointerIsValid(c)) - return NULL; - - if (!PointerIsValid(result = palloc(sizeof(Cash)))) - elog(ERROR, "Memory allocation failed, can't multiply cash"); - - *result = ((*f) * (*c)); + Cash c = PG_GETARG_CASH(0); + float4 f = PG_GETARG_FLOAT4(1); + Cash result; - return result; -} /* cash_mul_flt4() */ + result = c * f; + PG_RETURN_CASH(result); +} /* flt4_mul_cash() - * Multiply float4 by float4. + * Multiply float4 by cash. */ -Cash * -flt4_mul_cash(float4 *f, Cash *c) +Datum +flt4_mul_cash(PG_FUNCTION_ARGS) { - return cash_mul_flt4(c, f); -} /* flt4_mul_cash() */ + float4 f = PG_GETARG_FLOAT4(0); + Cash c = PG_GETARG_CASH(1); + Cash result; + + result = f * c; + PG_RETURN_CASH(result); +} /* cash_div_flt4() @@ -513,24 +508,19 @@ flt4_mul_cash(float4 *f, Cash *c) * XXX Don't know if rounding or truncating is correct behavior. * Round for now. - tgl 97/04/15 */ -Cash * -cash_div_flt4(Cash *c, float4 *f) +Datum +cash_div_flt4(PG_FUNCTION_ARGS) { - Cash *result; - - if (!PointerIsValid(f) || !PointerIsValid(c)) - return NULL; - - if (!PointerIsValid(result = palloc(sizeof(Cash)))) - elog(ERROR, "Memory allocation failed, can't divide cash"); + Cash c = PG_GETARG_CASH(0); + float4 f = PG_GETARG_FLOAT4(1); + Cash result; - if (*f == 0.0) + if (f == 0.0) elog(ERROR, "cash_div: divide by 0.0 error"); - *result = rint(*c / *f); - - return result; -} /* cash_div_flt4() */ + result = rint(c / f); + PG_RETURN_CASH(result); +} /* cash_mul_int4() |