Re: [xml] XPath mod operator problems

In message <15643 13793 243565 537255 guitars rock roll>
          Geert Kloosterman <geertk ai rug nl> wrote:

Hi Daniel, all,

When I change the following lines of xpath.c (l. 4890, 4891),

        ctxt->value->floatval = arg2 * (tmp - (double)((int)tmp));


        ctxt->value->floatval = fmod(arg1, arg2);

the behaviour looks correct.  But I don't know if fmod conforms
to the XPath requirements of the `mod' operator.

I don't think anyone has replied with the standards on these; I only have C
ISO/IEC 9899:1999 to hand, but the relevant section is and :

2    The fmod functions compute the floating-point remainder of x/y.

3    The fmod functions return the value x - ny, for some integer n such
     that, if y is nonzero, the result has the same sign as x and magnitude
     less than the magnitude of y. If y is zero, whether a domain error
     occurs or the fmod functions return zero is implementation-defined.

XPath 1.0 states :

The mod operator returns the remainder from a truncating division.  For

 * '5 mod 2' returns '1'
 * '5 mod -2' returns '1'
 * '-5 mod 2' returns '-1'
 * '-5 mod -2' returns '-1'

Note: This is the same as the % operator in Java and ECMAScript.

This is not the same as the IEEE 754 remainder operation, which
returns the remainder from a rounding division.

This would appear to me to be compatible, and thus suitable for use.
I haven't got earlier versions of the spec but I believe that the
fmod function has been part of the standard library for some time.

Gerph {djf0-.3w6e2w2.226,6q6w2q2,2.3,2m4}
... Eyes to the heavens, screaming at the sky;
    Trying to send you messages, but choking on goodbye.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]