mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
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.
This commit is contained in:
@@ -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;
|
||||
Cash c = PG_GETARG_CASH(0);
|
||||
float8 f = PG_GETARG_FLOAT8(1);
|
||||
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));
|
||||
|
||||
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;
|
||||
Cash c = PG_GETARG_CASH(0);
|
||||
float8 f = PG_GETARG_FLOAT8(1);
|
||||
Cash result;
|
||||
|
||||
if (!PointerIsValid(f) || !PointerIsValid(c))
|
||||
return NULL;
|
||||
|
||||
if (!PointerIsValid(result = palloc(sizeof(Cash))))
|
||||
elog(ERROR, "Memory allocation failed, can't divide cash");
|
||||
|
||||
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;
|
||||
Cash c = PG_GETARG_CASH(0);
|
||||
float4 f = PG_GETARG_FLOAT4(1);
|
||||
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));
|
||||
|
||||
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;
|
||||
Cash c = PG_GETARG_CASH(0);
|
||||
float4 f = PG_GETARG_FLOAT4(1);
|
||||
Cash result;
|
||||
|
||||
if (!PointerIsValid(f) || !PointerIsValid(c))
|
||||
return NULL;
|
||||
|
||||
if (!PointerIsValid(result = palloc(sizeof(Cash))))
|
||||
elog(ERROR, "Memory allocation failed, can't divide cash");
|
||||
|
||||
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()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.41 2000/07/17 03:05:17 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.42 2000/08/01 18:29:35 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ int2out(PG_FUNCTION_ARGS)
|
||||
int16 arg1 = PG_GETARG_INT16(0);
|
||||
char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
|
||||
|
||||
itoa((int) arg1, result);
|
||||
pg_itoa(arg1, result);
|
||||
PG_RETURN_CSTRING(result);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ int2vectorout(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (num != 0)
|
||||
*rp++ = ' ';
|
||||
ltoa(int2Array[num], rp);
|
||||
pg_itoa(int2Array[num], rp);
|
||||
while (*++rp != '\0')
|
||||
;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ int44out(PG_FUNCTION_ARGS)
|
||||
walk = result;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
itoa(an_array[i], walk);
|
||||
pg_ltoa(an_array[i], walk);
|
||||
while (*++walk != '\0')
|
||||
;
|
||||
*walk++ = ' ';
|
||||
@@ -221,7 +221,7 @@ int4out(PG_FUNCTION_ARGS)
|
||||
int32 arg1 = PG_GETARG_INT32(0);
|
||||
char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
|
||||
|
||||
ltoa(arg1, result);
|
||||
pg_ltoa(arg1, result);
|
||||
PG_RETURN_CSTRING(result);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ int2_text(PG_FUNCTION_ARGS)
|
||||
int16 arg1 = PG_GETARG_INT16(0);
|
||||
text *result = (text *) palloc(7+VARHDRSZ); /* sign,5 digits, '\0' */
|
||||
|
||||
itoa((int) arg1, VARDATA(result));
|
||||
pg_itoa(arg1, VARDATA(result));
|
||||
VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
@@ -290,7 +290,7 @@ int4_text(PG_FUNCTION_ARGS)
|
||||
int32 arg1 = PG_GETARG_INT32(0);
|
||||
text *result = (text *) palloc(12+VARHDRSZ); /* sign,10 digits,'\0' */
|
||||
|
||||
ltoa(arg1, VARDATA(result));
|
||||
pg_ltoa(arg1, VARDATA(result));
|
||||
VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* 1998 Jan Wieck
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.33 2000/07/29 03:26:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.34 2000/08/01 18:29:35 tgl Exp $
|
||||
*
|
||||
* ----------
|
||||
*/
|
||||
@@ -1766,17 +1766,19 @@ numeric_float8(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Numeric num = PG_GETARG_NUMERIC(0);
|
||||
char *tmp;
|
||||
float64 result;
|
||||
Datum result;
|
||||
|
||||
if (NUMERIC_IS_NAN(num))
|
||||
PG_RETURN_FLOAT8(NAN);
|
||||
|
||||
tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
|
||||
NumericGetDatum(num)));
|
||||
result = float8in(tmp);
|
||||
|
||||
result = DirectFunctionCall1(float8in, CStringGetDatum(tmp));
|
||||
|
||||
pfree(tmp);
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1809,17 +1811,19 @@ numeric_float4(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Numeric num = PG_GETARG_NUMERIC(0);
|
||||
char *tmp;
|
||||
float32 result;
|
||||
Datum result;
|
||||
|
||||
if (NUMERIC_IS_NAN(num))
|
||||
PG_RETURN_FLOAT4(NAN);
|
||||
PG_RETURN_FLOAT4((float4) NAN);
|
||||
|
||||
tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
|
||||
NumericGetDatum(num)));
|
||||
result = float4in(tmp);
|
||||
|
||||
result = DirectFunctionCall1(float4in, CStringGetDatum(tmp));
|
||||
|
||||
pfree(tmp);
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* numutils.c
|
||||
* utility functions for I/O of built-in numeric types.
|
||||
*
|
||||
* integer: itoa, ltoa
|
||||
* integer: pg_itoa, pg_ltoa
|
||||
* floating point: ftoa, atof1
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.41 2000/07/12 22:59:09 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.42 2000/08/01 18:29:35 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -116,27 +116,27 @@ pg_atoi(char *s, int size, int c)
|
||||
}
|
||||
|
||||
/*
|
||||
* itoa - converts a short int to its string represention
|
||||
* pg_itoa - converts a short int to its string represention
|
||||
*
|
||||
* Note:
|
||||
* previously based on ~ingres/source/gutil/atoi.c
|
||||
* now uses vendor's sprintf conversion
|
||||
*/
|
||||
void
|
||||
itoa(int i, char *a)
|
||||
pg_itoa(int16 i, char *a)
|
||||
{
|
||||
sprintf(a, "%hd", (short) i);
|
||||
}
|
||||
|
||||
/*
|
||||
* ltoa - converts a long int to its string represention
|
||||
* pg_ltoa - converts a long int to its string represention
|
||||
*
|
||||
* Note:
|
||||
* previously based on ~ingres/source/gutil/atoi.c
|
||||
* now uses vendor's sprintf conversion
|
||||
*/
|
||||
void
|
||||
ltoa(int32 l, char *a)
|
||||
pg_ltoa(int32 l, char *a)
|
||||
{
|
||||
sprintf(a, "%d", l);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.37 2000/07/03 23:09:52 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.38 2000/08/01 18:29:35 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -79,7 +79,7 @@ oidvectorout(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (num != 0)
|
||||
*rp++ = ' ';
|
||||
ltoa(oidArray[num], rp);
|
||||
pg_ltoa((int32) oidArray[num], rp);
|
||||
while (*++rp != '\0')
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user