Xpath Mod operator confusion

Discussion in 'XML' started by annoyedtuna@yahoo.co.uk, Apr 25, 2005.

  1. Guest

    When I perform the following:

    <xsl:value-of select="( 182.88 mod 30.48 )"/>

    I get 30.479999999999993 as a result

    By my calculations, the result should actually be 0


    Does anyone know what's going on here?
     
    , Apr 25, 2005
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > When I perform the following:
    >
    > <xsl:value-of select="( 182.88 mod 30.48 )"/>
    >
    > I get 30.479999999999993 as a result
    >
    > By my calculations, the result should actually be 0
    >
    >
    > Does anyone know what's going on here?



    Yes. The "number" type in XPath is actually "double". (Decimal) Numbers
    are expressed as double precision and thus there are cases when this results
    in small truncating errors (the same as e.g. 1/3 = 0.33333... gets truncated
    when represented as a decimal number).

    Not commenting on the really strange idea to use the "mod" operator for
    non-integer operands, you really got what you asked for ...

    The situation's changed in XPath 2.0, where there's the xs:decimal datatype.
    As the the type of the above numbers is xs:decimal,

    182.88 mod 30.48

    is evaluated to 0.

    Workaround for XPath 1.0:

    Use:

    (100*182.88) mod (100*30.48)


    Cheers,

    Dimitre Novatchev
     
    Dimitre Novatchev, Apr 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Basel Naamna

    MOD operator synthesis

    Basel Naamna, May 8, 2004, in forum: VHDL
    Replies:
    2
    Views:
    3,573
    Ken Smith
    May 10, 2004
  2. Ben Sizer

    Re: mod python confusion

    Ben Sizer, Jun 1, 2004, in forum: Python
    Replies:
    1
    Views:
    317
    David Fraser
    Jun 1, 2004
  3. Hari Sekhon
    Replies:
    0
    Views:
    514
    Hari Sekhon
    Jun 20, 2006
  4. ryles
    Replies:
    3
    Views:
    537
    Piet van Oostrum
    Jul 26, 2009
  5. T. Onoma
    Replies:
    9
    Views:
    357
    Dave Thomas
    Dec 15, 2003
Loading...

Share This Page