From 6521e12aaf99543a1ace887f9e10a884f62bff2d Mon Sep 17 00:00:00 2001 From: robocop Date: Tue, 7 Dec 2004 00:29:40 +0000 Subject: [PATCH] Slavomir Skopalik contributed IB_UDF_frac. --- src/extlib/ib_udf.cpp | 15 +++++++++++---- src/extlib/ib_udf2.sql | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/extlib/ib_udf.cpp b/src/extlib/ib_udf.cpp index 3b9aa04b6d..e0d66703da 100644 --- a/src/extlib/ib_udf.cpp +++ b/src/extlib/ib_udf.cpp @@ -18,8 +18,10 @@ * Changes made by Claudio Valderrama for the Firebird project * changes to substr and added substrlen * 2004.9.1 Claudio Valderrama, change some UDF's to be able to detect NULL. + * 2004.12.5 Slavomir Skopalik contributed IB_UDF_frac. * */ + #include "firebird.h" #include #include @@ -150,6 +152,15 @@ double EXPORT IB_UDF_floor( double *a) return (floor(*a)); } +double EXPORT IB_UDF_frac(const double* x) +{ + if (*x > 0) + return *x - floor(*x); + if (*x < 0) + return *x - ceil(*x); + return 0; +} + double EXPORT IB_UDF_ln( double *a) { return (log(*a)); @@ -263,10 +274,6 @@ double EXPORT IB_UDF_rand() return ((float) rand() / (float) RAND_MAX); } - - - - char *EXPORT IB_UDF_rpad( const char *s, long *a, const char *c) { if (!s || !c) diff --git a/src/extlib/ib_udf2.sql b/src/extlib/ib_udf2.sql index 4a6fe311c7..0037570d5d 100644 --- a/src/extlib/ib_udf2.sql +++ b/src/extlib/ib_udf2.sql @@ -15,7 +15,7 @@ * * All Rights Reserved. * Contributor(s): ______________________________________. - * $Id: ib_udf2.sql,v 1.3 2004-11-03 14:16:57 fsg Exp $ + * $Id: ib_udf2.sql,v 1.4 2004-12-07 00:29:40 robocop Exp $ * Revision 1.2 2000/11/28 06:47:52 fsg * Changed declaration of ascii_char in ib_udf.sql * to get correct result as proposed by Claudio Valderrama @@ -298,6 +298,21 @@ DECLARE EXTERNAL FUNCTION floor RETURNS DOUBLE PRECISION BY VALUE ENTRY_POINT 'IB_UDF_floor' MODULE_NAME 'ib_udf'; +/***************************************** + * + * f r a c + * + ***************************************** + * + * Functional description: + * Returns the fractional part of the argument. + * + *****************************************/ +DECLARE EXTERNAL FUNCTION frac + DOUBLE PRECISION + RETURNS DOUBLE PRECISION BY VALUE + ENTRY_POINT 'IB_UDF_frac' MODULE_NAME 'ib_udf'; + /***************************************** * * l n