From 643c7beddfed0d56c6969acc9c521d022044e770 Mon Sep 17 00:00:00 2001 From: "Thomas G. Lockhart" Date: Tue, 17 Nov 1998 14:36:51 +0000 Subject: Add text<->float8 and text<->float4 conversion functions. This will fix the problem reported by Jose' Soares when trying to cast a float to text. --- src/backend/utils/adt/float.c | 92 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/float.c') diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index b1de92f643e..0bf5ebff472 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33 1998/09/01 04:32:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.34 1998/11/17 14:36:44 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -926,6 +926,96 @@ i2tof(int16 num) } +/* + * float8_text - converts a float8 number to a text string + */ +text * +float8_text(float64 num) +{ + text *result; + int len; + char *str; + + str = float8out(num); + len = (strlen(str)+VARHDRSZ); + + result = palloc(len); + + VARSIZE(result) = len; + memmove(VARDATA(result), str, (len - VARHDRSZ)); + + pfree(str); + return result; +} /* float8_text() */ + + +/* + * text_float8 - converts a text string to a float8 number + */ +float64 +text_float8(text *string) +{ + float64 result; + int len; + char *str; + + len = (VARSIZE(string) - VARHDRSZ); + str = palloc(len + 1); + memmove(str, VARDATA(string), len); + *(str + len) = '\0'; + + result = float8in(str); + pfree(str); + + return result; +} /* text_float8() */ + + +/* + * float4_text - converts a float4 number to a text string + */ +text * +float4_text(float32 num) +{ + text *result; + int len; + char *str; + + str = float4out(num); + len = (strlen(str)+VARHDRSZ); + + result = palloc(len); + + VARSIZE(result) = len; + memmove(VARDATA(result), str, (len - VARHDRSZ)); + + pfree(str); + return result; +} /* float4_text() */ + + +/* + * text_float4 - converts a text string to a float4 number + */ +float32 +text_float4(text *string) +{ + float32 result; + int len; + char *str; + + len = (VARSIZE(string) - VARHDRSZ); + str = palloc(len + 1); + memmove(str, VARDATA(string), len); + *(str + len) = '\0'; + + result = float4in(str); + pfree(str); + + return result; +} /* text_float4() */ + + /* * ======================= * RANDOM FLOAT8 OPERATORS -- cgit v1.2.3