*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.81 2002/09/04 20:31:27 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.82 2002/10/19 02:08:17 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
- check to see if a float4 val is outside of
- the FLOAT4_MIN, FLOAT4_MAX bounds.
-
- raise an elog warning if it is
+ * check to see if a float4 val is outside of
+ * the FLOAT4_MIN, FLOAT4_MAX bounds.
+ *
+ * raise an elog warning if it is
*/
static void
CheckFloat4Val(double val)
}
/*
- check to see if a float8 val is outside of
- the FLOAT8_MIN, FLOAT8_MAX bounds.
-
- raise an elog warning if it is
-*/
+ * check to see if a float8 val is outside of
+ * the FLOAT8_MIN, FLOAT8_MAX bounds.
+ *
+ * raise an elog error if it is
+ */
static void
CheckFloat8Val(double val)
{
elog(ERROR, "Bad float8 input format -- overflow");
if (val != 0.0 && fabs(val) < FLOAT8_MIN)
elog(ERROR, "Bad float8 input format -- underflow");
- return;
#endif /* UNSAFE_FLOATS */
}
PG_RETURN_FLOAT8(result);
}
+/*
+ * dceil - returns the smallest integer greater than or
+ * equal to the specified float
+ */
+Datum
+dceil(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
+ */
+Datum
+dfloor(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.
+ */
+Datum
+dsign(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,
*
* 1998 Jan Wieck
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.55 2002/10/02 19:21:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.56 2002/10/19 02:08:17 momjian Exp $
*
* ----------
*/
PG_RETURN_NUMERIC(res);
}
-
+/* ----------
+ * numeric_sign() -
+ *
+ * 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.
+ * ----------
+ */
Datum
numeric_sign(PG_FUNCTION_ARGS)
{
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: catversion.h,v 1.161 2002/10/14 22:14:35 tgl Exp $
+ * $Id: catversion.h,v 1.162 2002/10/19 02:08:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200210141
+#define CATALOG_VERSION_NO 200210181
#endif
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_proc.h,v 1.273 2002/09/22 17:27:23 tgl Exp $
+ * $Id: pg_proc.h,v 1.274 2002/10/19 02:08:18 momjian Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
DESCR("round to nearest integer");
DATA(insert OID = 229 ( dtrunc PGNSP PGUID 12 f f t f i 1 701 "701" dtrunc - _null_ ));
DESCR("truncate to integer");
+DATA(insert OID = 2308 ( ceil PGNSP PGUID 12 f f t f i 1 701 "701" dceil - _null_ ));
+DESCR("smallest integer >= value");
+DATA(insert OID = 2309 ( floor PGNSP PGUID 12 f f t f i 1 701 "701" dfloor - _null_ ));
+DESCR("largest integer <= value");
+DATA(insert OID = 2310 ( sign PGNSP PGUID 12 f f t f i 1 701 "701" dsign - _null_ ));
+DESCR("sign of value");
DATA(insert OID = 230 ( dsqrt PGNSP PGUID 12 f f t f i 1 701 "701" dsqrt - _null_ ));
DESCR("square root");
DATA(insert OID = 231 ( dcbrt PGNSP PGUID 12 f f t f i 1 701 "701" dcbrt - _null_ ));
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: builtins.h,v 1.202 2002/09/22 17:27:25 tgl Exp $
+ * $Id: builtins.h,v 1.203 2002/10/19 02:08:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern Datum float8_text(PG_FUNCTION_ARGS);
extern Datum float4_text(PG_FUNCTION_ARGS);
extern Datum dround(PG_FUNCTION_ARGS);
+extern Datum dceil(PG_FUNCTION_ARGS);
+extern Datum dfloor(PG_FUNCTION_ARGS);
+extern Datum dsign(PG_FUNCTION_ARGS);
extern Datum dtrunc(PG_FUNCTION_ARGS);
extern Datum dsqrt(PG_FUNCTION_ARGS);
extern Datum dcbrt(PG_FUNCTION_ARGS);
| 1.2345678901234e-200 | 0
(5 rows)
+-- ceil
+select ceil(f1) as ceil_f1 from float8_tbl f;
+ ceil_f1
+----------------------
+ 0
+ 1005
+ -34
+ 1.2345678901234e+200
+ 1
+(5 rows)
+
+-- floor
+select floor(f1) as floor_f1 from float8_tbl f;
+ floor_f1
+----------------------
+ 0
+ 1004
+ -35
+ 1.2345678901234e+200
+ 0
+(5 rows)
+
+-- sign
+select sign(f1) as sign_f1 from float8_tbl f;
+ sign_f1
+---------
+ 0
+ 1
+ -1
+ 1
+ 1
+(5 rows)
+
+-- square root
SELECT sqrt(float8 '64') AS eight;
eight
-------
8
(1 row)
--- square root
SELECT |/ float8 '64' AS eight;
eight
-------
SELECT '' AS five, f.f1, f.f1 % AS round_f1
FROM FLOAT8_TBL f;
-SELECT sqrt(float8 '64') AS eight;
+-- ceil
+select ceil(f1) as ceil_f1 from float8_tbl f;
+
+-- floor
+select floor(f1) as floor_f1 from float8_tbl f;
+
+-- sign
+select sign(f1) as sign_f1 from float8_tbl f;
-- square root
+SELECT sqrt(float8 '64') AS eight;
+
SELECT |/ float8 '64' AS eight;
SELECT '' AS three, f.f1, |/f.f1 AS sqrt_f1