Subject Re: [firebird-support] Problem Using MOD
Author Helen Borrie
At 03:54 PM 18/07/2003 +0000, you wrote:
>Hi All,
>
>I'm using the function MOD in a stored procedure in Firebird 1.5 to
>get the remainder of a division but the operation get the wrong
>result.
>
>For Example
>A = MOD(2000, 19);
>The result is 105 instead of 5.
>
>I don't know why is this happen. Somebody could help me???
>
>This is the UDF function
>
>DECLARE EXTERNAL FUNCTION MOD
> INTEGER,
> INTEGER
> RETURNS INTEGER
> ENTRY_POINT 'IB_UDF_mod' MODULE_NAME 'ib_udf';

As Ivan pointed out, your declaration is wrong. You can't change the data
type of the return value by altering the declaration.

Use the declarations in the ib_udf.sql script that should be in your /UDF
directory. In case the script is missing from your installation, here's
the declaration for MOD:
*****************************************/
DECLARE EXTERNAL FUNCTION mod
INTEGER, INTEGER
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'IB_UDF_mod' MODULE_NAME 'ib_udf';

/*****************************************

If you want to get an integer rather than a double, use CAST, e.g.
SELECT CAST (MOD(2000,19) AS INTEGER) AS A
FROM RDB$DATABASE;

heLen