2 quomod - assign quotient and remainder to two lvalues
5 quomod(x, y, Q, R [, rnd])
10 Q null-or-real-valued lvalue with assign-to permission
11 R null-or-real-valued lvalue with assign-to permission
12 rnd nonnegative integer, defaults to config("quomod")
17 If y is nonzero and x/y is an integer q, this function assigns
18 q to Q and zero to R, and returns zero.
20 If y is zero, zero is assigned to Q, x to R and 0 or 1 returned
21 according as x is zero or nonzero.
23 In the remaining case, y nonzero and x/y not an intger, there
24 are two pairs (q,r) for which x = q * y + r, q is an integer, and
25 abs(r) < abs(y). Depending on the low 5 bits of rnd, the q and r
26 of one of these pairs will be assigned to Q and R respectively,
27 and the number 1 returned. The effects of rnd can be described in
28 terms of the way q is related to x/y, e.g. by rounding down,
29 rounding towards zero, rounding to a nearest integeri, etc. or
30 by properties of the remainder r, e.g. positive, negative,
31 smallest, etc. The effects of the most commonly used values of
32 rnd are described in the following table:
36 0 round down. q = floor(x/y) same sign as y
37 1 round up, q = ceil(x/y) opposite sign to y
38 2 round to zero, q = int(x/y) same sign as x, r = y * frac(x/y)
39 3 round from zero oppsite sign to x
43 7 opposite sigh to x/y
48 For 16 <= rnd < 32, the rounding is to the nearest integer and r
49 is the smallest (in absolute value) remainder except when x/y is
50 halfway between consecutive integers, in which case the rounding
51 is as given by the 4 low bits of rnd. Using rnd = 24 gives the
52 cpmmonly used principle of rounding: round to the nearest integer,
53 but take the even integer when there are two equally close integers.
55 For more detail on the effects of rnd for values other than those
56 listed above, see "help quo" and "help mod".
58 In all cases, the values assigned to Q and R by quomod(x, y, Q, R, rnd)
59 are the same as those given by Q = quo(x,y,rnd), R = mod(x,y,rnd).
60 If config("quo") == rnd, Q is also given by quo(x,y) or x // y.
61 If config("mod") == rnd, R is also given by mod(x,y) or x % y.
63 The rounding used by the C language for x / y and x % y corresponds
66 An error values is returned and the values of Q and R are not changed
67 if Q and R are not both lvalues, or if the current value of any
68 argument is not as specified above, or if Q or R has no-assign-to
69 prptection, e.g. after protect(Q,1).
75 ; print quomod(13,5,u,v), u, v, quomod(15.6,5.2,M[0],M[1]), M[0], M[1];
79 ; print quomod(13, 5, A[1], A[2]), A[1], A[2]
82 ; print quomod(10, -3, u, v), u, v;
84 ; print quomod(10, -3, u, v, 0), u, v;
86 ; print quomod(10, -3, u, v, 1), u, v;
88 ; print quomod(10, -3, u, v, 2), u, v;
90 ; print quomod(-10, -3, u, v, 2), u, v;
97 BOOL qquomod(NUMBER *q1, NUMBER *q2, NUMBER **quo, NUMBER **mod)
100 //, %, quo, mod, floor. ceil, int. frac
102 ## Copyright (C) 1999-2006 Landon Curt Noll
104 ## Calc is open software; you can redistribute it and/or modify it under
105 ## the terms of the version 2.1 of the GNU Lesser General Public License
106 ## as published by the Free Software Foundation.
108 ## Calc is distributed in the hope that it will be useful, but WITHOUT
109 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
110 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
111 ## Public License for more details.
113 ## A copy of version 2.1 of the GNU Lesser General Public License is
114 ## distributed with calc under the filename COPYING-LGPL. You should have
115 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
116 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
118 ## @(#) $Revision: 30.1 $
119 ## @(#) $Id: quomod,v 30.1 2007/03/16 11:10:42 chongo Exp $
120 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/quomod,v $
122 ## Under source code control: 1995/05/07 03:17:03
123 ## File existed as early as: 1995
125 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
126 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/