xsl-list
[Top] [All Lists]

Re: [xsl] XPath MOD 10 calculation

2007-05-25 08:41:15
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.

David



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>