Subject: Re: [xsl] XPath MOD 10 calculation From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Fri, 25 May 2007 16:54:32 +0100 |
> why is: > -(-foo mod 10) > > not the same as: > > foo mod 10
In the real world (that is, in mathematics) it is, also the mod function doesn't return an integer but rather an element of the finite set Z_n (which is how come 0 = 10 in the first place) however in most computer languages, and in particular in XPath the designers define mod not to be an operation on the set Z_n but rather an operation on Z (The integers) that is "remainder after division, and that retains the sign, so in XPath -9 mod 10 = -9 1 mod 10 = 1 so even though 1 and -9 are equal mod 10, it's not true that (1 mod 10) = (-9 mod 10) in Xpath, but it is true that (1 - -9 ) mod 10 = 0
which means that to check $x and $y are equal mod 10 you can use ($x - $y) mod 10 = 0 as you don't care which coset representative the mod operator uses, but if you want to generate the coset representative for -$x you can't just use -$x mod 10 you have to use (10 - $x) mod 10 to get the positive representative, hence my comment that it matters whether you are just checking a given checkdigit, or if you are calculting a digit and need to ensure you end up in the range 0 to 1.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XPath MOD 10 calculation, David Carlisle | Thread | Re: [xsl] XPath MOD 10 calculation, Manfred Staudinger |
Re: [xsl] XPath MOD 10 calculation, David Carlisle | Date | RE: [xsl] Grouping and Numbering, Carl Radley |
Month |