FW: Do we need an abs() function?

Forwarding to the public comments list.  Steve Tolkin amended this
proposal by asking that the function be polymorphic i.e.

return the numeric type that was passed to it.  This is consistent with
the behavior of most of our numeric functions.

All the best, Ashok 

  _____  

From: w3c-query-operators-request@w3.org
[mailto:w3c-query-operators-request@w3.org] On Behalf Of Ashok Malhotra
Sent: Friday, April 11, 2003 11:34 AM
To: w3c-query-operators@w3.org

 

We discussed this earlier, if memory serves me as a suggestion from
Steve Tolkin, and decided that the user could 

write it and it did not need to be in the F&O.  Now, one of our
developers is arguing that it's a nuisance not to have 

such a function.  See below.  Should we reopen this question?

Here is the rationale:

I need to find the absolute, truncated integer value of the result of a
division. My problem was that by definition, fn:floor() on negative
numbers gives me the next lower number instead of the integral part of
the original number (i.e. floor(-1.2) = -2 and not -1. As you mentioned,
I could also achieve it by saying floor(-(a div b)) but the if condition
still remains.

So instead of saying something like:

fn:floor(fn:abs(a div b))

I instead have to say:

if (a div b < 0.0) then fn:floor(-(a div b)) else fn:floor(a div b)

 All the best, Ashok

Received on Friday, 18 April 2003 08:28:32 UTC