Subject | Re: [firebird-support] ROUND(ABS(-1.4)) returns NULL |
---|---|
Author | Helen Borrie |
Post date | 2003-07-15T05:01:31Z |
Hello Tsutomu,
At 11:24 AM 15/07/2003 +0900, you wrote:
SELECT
ROUND(-1.4),
ROUND((-1.4)),
ABS(ROUND(-1.4))
FROM
RDB$DATABASE;
ROUND ROUND ROUND
============ ============ ============
-1 -1 1
There is probably something "funny" about the arithmetic, though. fbudf
passes parameters by descriptor, whereas ib_udf passes them by
C-datatype. Somehow, it works OK when passing the output from a descriptor
to the ABS() function (which expects a double precision number) but not OK
when passing the output of ABS (double precision) to ROUND.
I seem to recall Claudio stating that these "by descriptor" numeric
functions only work with scaled numbers. You will find that this produces
the expected result:
SELECT
ROUND(-1.4),
ROUND((-1.4)),
ROUND(cast (ABS(-1.4) as numeric (18,0)))
FROM
RDB$DATABASE
ROUND ROUND ROUND
============ ============ ============
-1 -1 1
I guess it's just one of those things one needs to be aware of.
heLen
At 11:24 AM 15/07/2003 +0900, you wrote:
>Hi allThis gives you the expected result:
>
>SELECT
> ROUND(-1.4),
> ROUND((-1.4)),
> ROUND(ABS(-1.4))
>FROM
> RDB$DATABASE
>;
>
> ROUND ROUND ROUND
>============ ============ ============
> -1 -1 <null>
SELECT
ROUND(-1.4),
ROUND((-1.4)),
ABS(ROUND(-1.4))
FROM
RDB$DATABASE;
ROUND ROUND ROUND
============ ============ ============
-1 -1 1
>I think it is caused by ABS() is in ib_udf and ROUND() is in fbudf. IsNot by any rule about UDFs. You can use UDFs from any number of libraries.
>this correct? Is this bug?
There is probably something "funny" about the arithmetic, though. fbudf
passes parameters by descriptor, whereas ib_udf passes them by
C-datatype. Somehow, it works OK when passing the output from a descriptor
to the ABS() function (which expects a double precision number) but not OK
when passing the output of ABS (double precision) to ROUND.
I seem to recall Claudio stating that these "by descriptor" numeric
functions only work with scaled numbers. You will find that this produces
the expected result:
SELECT
ROUND(-1.4),
ROUND((-1.4)),
ROUND(cast (ABS(-1.4) as numeric (18,0)))
FROM
RDB$DATABASE
ROUND ROUND ROUND
============ ============ ============
-1 -1 1
I guess it's just one of those things one needs to be aware of.
heLen