[xquery-talk] Literal NaN

Michael Kay mike at saxonica.com
Fri Feb 25 16:11:59 PST 2011


On 25/02/2011 15:29, David Lee wrote:
>
> Today I ran into yet a new hole in my xquery knowledge.  (I guess I'm 
> a sponge !)
>
> I needed to check if a value was numeric or not.  I found the functx 
> function
>
> http://www.xqueryfunctions.com/xq/functx_is-a-number.html
>
> The code is interesting :
>
> define function is-a-number
>
>   ( $value as xdt:anyAtomicType? )  as xs:boolean {
>
>    fn:string(fn:number($value)) != 'NaN'
>
> }
>
This code returns false if the input is NaN, which is interesting though 
not wrong - despite the name, NaN is a member of the numeric value space.
>
> I'm wondering why this hand-standing ? Why cant I compare to NaN 
> directly ?
>
> Is there no literal constructor for NaN ? I cant find any ... and my 
> obvious attempts fail like
>
>                 If(  number("abc") eq NaN ) ...
>
Because comparison to NaN always yields false.
>
> Its just strange to me to have a value which can be returned by a 
> function which you cant construct ...
>
>
You can construct it using xs:double('NaN') or xs:float('NaN')

Michael Kay
Saxonica

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20110225/22c384d9/attachment.htm


More information about the talk mailing list