2 mod - compute the remainder for an integer quotient
9 If x is a matrix or list, the returned value is a matrix or list v of
10 the same structure for which each element v[[i]] = mod(x[[i]], y, rnd).
12 If x is an xx-object or x is not an object and y is an xx-object,
13 this function calls the user-defined function xx_mod(x, y, rnd);
14 the types of arguments and returned value are as required by the
15 definition of xx_mod().
17 If neither x nor y is an object, or x is not a matrix or list:
19 x number (real or complex)
21 rnd integer, defaults to config("mod")
30 is equivalent to call:
40 config("mod", rnd), x % y
42 except that the global config("mod") value does not change.
44 If x is real or complex and y is zero, mod(x, y, rnd) returns x.
46 If x is complex, mod(x, y, rnd) returns
47 mod(re(x), y, rnd) + mod(im(x), y, rnd) * 1i.
49 In the following it is assumed x is real and y is nonzero.
51 If x/y is an integer mod(x, y, rnd) returns zero.
53 If x/y is not an integer, mod(x, y, rnd) returns one of the two
54 values of r for which for some integer q exists such that x = q * y + r
55 and abs(r) < abs(y). Which of the two values or r that is returned is
58 If bit 4 of rnd is set (e.g. if 16 <= rnd < 32) abs(r) <= abs(y)/2;
59 this uniquely determines r if abs(r) < abs(y)/2. If bit 4 of rnd is
60 set and abs(r) = abs(y)/2, or if bit 4 of r is not set, the result for
61 r depends on rnd as in the following table:
63 rnd & 15 sign of r parity of q
75 10 even if x/y > 0, otherwise odd
76 11 odd if x/y > 0, otherwise even
77 12 even if y > 0, otherwise odd
78 13 odd if y > 0, otherwise even
79 14 even if x > 0, otherwise odd
80 15 odd if x > 0, otherwise even
82 NOTE: Blank entries in the table above indicate that the
83 description would be complicated and probably not of
86 The C language method of modulus and integer division is:
92 This dependence on rnd is consistent with quo(x, y, rnd) and
93 appr(x, y, rnd) in that for any real x and y and any integer rnd,
95 x = y * quo(x, y, rnd) + mod(x, y, rnd).
96 mod(x, y, rnd) = x - appr(x, y, rnd)
98 If y and rnd are fixed and mod(x, y, rnd) is to be considered as
99 a canonical residue of x % y, bits 1 and 3 of rnd should be
100 zero: if 0 <= rnd < 32, it is only for rnd = 0, 1, 4, 5, 16, 17,
101 20, or 21, that the set of possible values for mod(x, y, rnd)
102 form an interval of length y, and for any x1, x2,
104 mod(x1, y, rnd) = mod(x2, y, rnd)
108 x1 is congruent to x2 modulo y.
110 This is particularly relevant when working with the ring of
111 integers modulo an integer y.
114 ; print mod(11,5,0), mod(11,5,1), mod(-11,5,2), mod(-11,-5,3)
117 ; print mod(12.5,5,16), mod(12.5,5,17), mod(12.5,5,24), mod(-7.5,-5,24)
120 ; A = list(11,13,17,23,29)
123 list (5 elements, 5 nonzero):
134 void modvalue(VALUE *x, VALUE *y, VALUE *rnd, VALUE *result)
135 NUMBER *qmod(NUMBER *y, NUMBER *y, long rnd)
140 ## Copyright (C) 1999-2006 Landon Curt Noll
142 ## Calc is open software; you can redistribute it and/or modify it under
143 ## the terms of the version 2.1 of the GNU Lesser General Public License
144 ## as published by the Free Software Foundation.
146 ## Calc is distributed in the hope that it will be useful, but WITHOUT
147 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
148 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
149 ## Public License for more details.
151 ## A copy of version 2.1 of the GNU Lesser General Public License is
152 ## distributed with calc under the filename COPYING-LGPL. You should have
153 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
154 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
156 ## @(#) $Revision: 30.1 $
157 ## @(#) $Id: mod,v 30.1 2007/03/16 11:10:42 chongo Exp $
158 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/mod,v $
160 ## Under source code control: 1995/09/18 02:09:31
161 ## File existed as early as: 1995
163 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
164 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/