⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 float.c

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 C
📖 第 1 页 / 共 4 页
字号:
		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("integer out of range")));	result = (int32) rint(num);	PG_RETURN_INT32(result);}/* *		ftoi2			- converts a float4 number to an int2 number */Datumftoi2(PG_FUNCTION_ARGS){	float4		num = PG_GETARG_FLOAT4(0);	int16		result;	if ((num < SHRT_MIN) || (num > SHRT_MAX))		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("smallint out of range")));	result = (int16) rint(num);	PG_RETURN_INT16(result);}/* *		i4tof			- converts an int4 number to a float8 number */Datumi4tof(PG_FUNCTION_ARGS){	int32		num = PG_GETARG_INT32(0);	float4		result;	result = num;	PG_RETURN_FLOAT4(result);}/* *		i2tof			- converts an int2 number to a float4 number */Datumi2tof(PG_FUNCTION_ARGS){	int16		num = PG_GETARG_INT16(0);	float4		result;	result = num;	PG_RETURN_FLOAT4(result);}/* *		float8_text		- converts a float8 number to a text string */Datumfloat8_text(PG_FUNCTION_ARGS){	float8		num = PG_GETARG_FLOAT8(0);	text	   *result;	int			len;	char	   *str;	str = DatumGetCString(DirectFunctionCall1(float8out,											  Float8GetDatum(num)));	len = strlen(str) + VARHDRSZ;	result = (text *) palloc(len);	VARATT_SIZEP(result) = len;	memcpy(VARDATA(result), str, (len - VARHDRSZ));	pfree(str);	PG_RETURN_TEXT_P(result);}/* *		text_float8		- converts a text string to a float8 number */Datumtext_float8(PG_FUNCTION_ARGS){	text	   *string = PG_GETARG_TEXT_P(0);	Datum		result;	int			len;	char	   *str;	len = (VARSIZE(string) - VARHDRSZ);	str = palloc(len + 1);	memcpy(str, VARDATA(string), len);	*(str + len) = '\0';	result = DirectFunctionCall1(float8in, CStringGetDatum(str));	pfree(str);	PG_RETURN_DATUM(result);}/* *		float4_text		- converts a float4 number to a text string */Datumfloat4_text(PG_FUNCTION_ARGS){	float4		num = PG_GETARG_FLOAT4(0);	text	   *result;	int			len;	char	   *str;	str = DatumGetCString(DirectFunctionCall1(float4out,											  Float4GetDatum(num)));	len = strlen(str) + VARHDRSZ;	result = (text *) palloc(len);	VARATT_SIZEP(result) = len;	memcpy(VARDATA(result), str, (len - VARHDRSZ));	pfree(str);	PG_RETURN_TEXT_P(result);}/* *		text_float4		- converts a text string to a float4 number */Datumtext_float4(PG_FUNCTION_ARGS){	text	   *string = PG_GETARG_TEXT_P(0);	Datum		result;	int			len;	char	   *str;	len = (VARSIZE(string) - VARHDRSZ);	str = palloc(len + 1);	memcpy(str, VARDATA(string), len);	*(str + len) = '\0';	result = DirectFunctionCall1(float4in, CStringGetDatum(str));	pfree(str);	PG_RETURN_DATUM(result);}/* *		======================= *		RANDOM FLOAT8 OPERATORS *		======================= *//* *		dround			- returns	ROUND(arg1) */Datumdround(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	result = rint(arg1);	PG_RETURN_FLOAT8(result);}/* *		dceil			- returns the smallest integer greater than or *						  equal to the specified float */Datumdceil(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	PG_RETURN_FLOAT8(ceil(arg1));}/* *		dfloor			- returns the largest integer lesser than or *						  equal to the specified float */Datumdfloor(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	PG_RETURN_FLOAT8(floor(arg1));}/* *		dsign			- returns -1 if the argument is less than 0, 0 *						  if the argument is equal to 0, and 1 if the *						  argument is greater than zero. */Datumdsign(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	if (arg1 > 0)		result = 1.0;	else if (arg1 < 0)		result = -1.0;	else		result = 0.0;	PG_RETURN_FLOAT8(result);}/* *		dtrunc			- returns truncation-towards-zero of arg1, *						  arg1 >= 0 ... the greatest integer less *										than or equal to arg1 *						  arg1 < 0	... the least integer greater *										than or equal to arg1 */Datumdtrunc(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	if (arg1 >= 0)		result = floor(arg1);	else		result = -floor(-arg1);	PG_RETURN_FLOAT8(result);}/* *		dsqrt			- returns square root of arg1 */Datumdsqrt(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	if (arg1 < 0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),				 errmsg("cannot take square root of a negative number")));	result = sqrt(arg1);	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dcbrt			- returns cube root of arg1 */Datumdcbrt(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	result = cbrt(arg1);	PG_RETURN_FLOAT8(result);}/* *		dpow			- returns pow(arg1,arg2) */Datumdpow(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		arg2 = PG_GETARG_FLOAT8(1);	float8		result;	/*	 * The SQL spec requires that we emit a particular SQLSTATE error code for	 * certain error conditions.	 */	if ((arg1 == 0 && arg2 < 0) ||		(arg1 < 0 && floor(arg2) != arg2))		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION),				 errmsg("invalid argument for power function")));	/*	 * We must check both for errno getting set and for a NaN result, in order	 * to deal with the vagaries of different platforms...	 */	errno = 0;	result = pow(arg1, arg2);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("result is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dexp			- returns the exponential function of arg1 */Datumdexp(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	/*	 * We must check both for errno getting set and for a NaN result, in order	 * to deal with the vagaries of different platforms. Also, a zero result	 * implies unreported underflow.	 */	errno = 0;	result = exp(arg1);	if (errno != 0 || result == 0.0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("result is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dlog1			- returns the natural logarithm of arg1 */Datumdlog1(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	/*	 * Emit particular SQLSTATE error codes for ln(). This is required by the	 * SQL standard.	 */	if (arg1 == 0.0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),				 errmsg("cannot take logarithm of zero")));	if (arg1 < 0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),				 errmsg("cannot take logarithm of a negative number")));	result = log(arg1);	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dlog10			- returns the base 10 logarithm of arg1 */Datumdlog10(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	/*	 * Emit particular SQLSTATE error codes for log(). The SQL spec doesn't	 * define log(), but it does define ln(), so it makes sense to emit the	 * same error code for an analogous error condition.	 */	if (arg1 == 0.0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),				 errmsg("cannot take logarithm of zero")));	if (arg1 < 0)		ereport(ERROR,				(errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),				 errmsg("cannot take logarithm of a negative number")));	result = log10(arg1);	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dacos			- returns the arccos of arg1 (radians) */Datumdacos(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = acos(arg1);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dasin			- returns the arcsin of arg1 (radians) */Datumdasin(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = asin(arg1);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		datan			- returns the arctan of arg1 (radians) */Datumdatan(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = atan(arg1);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		atan2			- returns the arctan2 of arg1 (radians) */Datumdatan2(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		arg2 = PG_GETARG_FLOAT8(1);	float8		result;	errno = 0;	result = atan2(arg1, arg2);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dcos			- returns the cosine of arg1 (radians) */Datumdcos(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = cos(arg1);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dcot			- returns the cotangent of arg1 (radians) */Datumdcot(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = tan(arg1);	if (errno != 0 || result == 0.0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	result = 1.0 / result;	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/* *		dsin			- returns the sine of arg1 (radians) */Datumdsin(PG_FUNCTION_ARGS){	float8		arg1 = PG_GETARG_FLOAT8(0);	float8		result;	errno = 0;	result = sin(arg1);	if (errno != 0#ifdef HAVE_FINITE		|| !finite(result)#endif		)		ereport(ERROR,				(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),				 errmsg("input is out of range")));	CheckFloat8Val(result);	PG_RETURN_FLOAT8(result);}/*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -