Subject RE: [firebird-support] ROUND(ABS(-1.4)) returns NULL
Author Hayashi@apex-jp.com
Thanks Helen

> This gives you the expected result:
>
> 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. Is
> >this correct? Is this bug?
>
> Not by any rule about UDFs. You can use UDFs from any number
> of libraries.
>
> 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.

Hummm... It is difficult but important to treat UDFs. OK.

> 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 knew this technique. It is correct result.

> I guess it's just one of those things one needs to be aware of.

yes I am aware of that.

best

Tsutomu Hayashi in Japan
Mail : hayashi@...
Web : http://www.apex-jp.com/ (Japanese Only)
http://dmj.psnet.ne.jp/ (Delphi Magazine)