mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
115 lines
3.6 KiB
Plaintext
115 lines
3.6 KiB
Plaintext
NAME
|
|
quo - compute integer quotient of a value by a real number
|
|
|
|
SYNOPSIS
|
|
quo(x, y, rnd) or x // y
|
|
|
|
TYPES
|
|
If x is a matrix or list, the returned value is a matrix or list v of
|
|
the same structure for which each element v[[i]] = quo(x[[i]], y, rnd).
|
|
|
|
If x is an xx-object or x is not an object and y is an xx-object,
|
|
this function calls the user-defined function xx_quo(x, y, rnd);
|
|
the types of arguments and returned value are as required by the
|
|
definition of xx_quo().
|
|
|
|
If neither x nor y is an object, and x is not a matrix or list:
|
|
|
|
x number (real or complex)
|
|
y real
|
|
rnd integer, defaults to config("quo")
|
|
|
|
return number
|
|
|
|
DESCRIPTION
|
|
If x is real or complex and y is zero, quo(x, y, rnd) returns zero.
|
|
|
|
If x is complex, quo(x, y, rnd) returns
|
|
quo(re(x), y, rnd) + quo(im(x), y, rnd) * 1i.
|
|
|
|
In the following it is assumed that x is real and y is nonzero.
|
|
|
|
If x/y is an integer quo(x, y, rnd) returns x/y.
|
|
|
|
If x is real, y nonzero and x/y is not an integer, x // y returns
|
|
one of the two integers v for which abs(x/y - v) < 1. Which
|
|
integer is returned is controlled by rnd as follows:
|
|
|
|
rnd sign of x/y - v Description of rounding
|
|
|
|
0 + down, towards minus infinity
|
|
1 - up, towards infinity
|
|
2 sgn(x/y) towards zero
|
|
3 -sgn(x/y) from zero
|
|
4 sgn(y)
|
|
5 -sgn(y)
|
|
6 sgn(x)
|
|
7 -sgn(x)
|
|
8 to nearest even integer
|
|
9 to nearest odd integer
|
|
10 even if x/y > 0, otherwise odd
|
|
11 odd if x/y > 0, otherwise even
|
|
12 even if y > 0, otherwise odd
|
|
13 odd if y > 0, otherwise even
|
|
14 even if x > 0, otherwise odd
|
|
15 odd if x > 0, otherwise even
|
|
|
|
16-31 to nearest integer when this
|
|
is uniquely determined;
|
|
otherwise, when x/y is a
|
|
half-integer, as if
|
|
rnd replaced by rnd & 15
|
|
|
|
NOTE: Blank entries in the table above indicate that the
|
|
description would be complicated and probably not of
|
|
much interest.
|
|
|
|
The C language method of modulus and integer division is:
|
|
|
|
config("quomod", 2)
|
|
config("quo", 2)
|
|
config("mod", 2)
|
|
|
|
EXAMPLE
|
|
print quo(11,5,0), quo(11,5,1), quo(-11,5,2), quo(-11,-5,3)
|
|
2 3 -2 3
|
|
|
|
print quo(12.5,5,16), quo(12.5,5,17), quo(12.5,5,24), quo(-7.5,-5,24)
|
|
2 3 2 2
|
|
|
|
LIMITS
|
|
none
|
|
|
|
LINK LIBRARY
|
|
void quovalue(VALUE *x, VALUE *y, VALUE *rnd, VALUE *result)
|
|
NUMBER *qquo(NUMBER *x, NUMBER *y, long rnd)
|
|
|
|
SEE ALSO
|
|
mod, quomod, //, %
|
|
|
|
## Copyright (C) 1999 Landon Curt Noll
|
|
##
|
|
## Calc is open software; you can redistribute it and/or modify it under
|
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
|
## as published by the Free Software Foundation.
|
|
##
|
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
## Public License for more details.
|
|
##
|
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
##
|
|
## @(#) $Revision: 29.3 $
|
|
## @(#) $Id: quo,v 29.3 2006/06/24 19:06:58 chongo Exp $
|
|
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/quo,v $
|
|
##
|
|
## Under source code control: 1995/09/18 04:01:44
|
|
## File existed as early as: 1995
|
|
##
|
|
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
|
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|