mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Added several conversion functions: Added builtin functions to convert between degrees and degrees, minutes and seconds under the config("mod") round rules: d2dms(degs, d, m, s [,rnd]) - given degs, compute d, m, s d2dm(degs, d, m [,rnd]) - given degs, compute d, m See help/d2dms and help/d2dm. Example: ; print d2dms(360.321,deg=,min=,sec=), deg, min, sec; 0.321 0 19 15.6 ; print d2dm(360.321,deg=,min=), deg, min; 0.321 0 19.26 Added builtin functions to convert between gradians and gradians, minutes and seconds under the config("mod") round rules: g2gms(grads, g, m, s [,rnd]) - given grads, compute g, m, s g2gm(grads, g, m [,rnd]) - given grads, compute g, m See help/g2gms and help/g2gm. Example: ; print g2gms(400.321,grad=,min=,sec=), grad, min, sec; 0.321 0 19 15.6 ; print g2gm(400.321,grad=,min=), grad, min; 0.321 0 19.26 Added builtin functions to convert between hours and hours, minutes and seconds under the config("mod") round rules: h2hms(hours, h, m, s [,rnd]) - given hours, compute h, m, s h2hm(hours, h, m [,rnd]) - given hours, compute h, m See help/h2hms and help/h2hm. Example: ; print h2hms(24.321,hour=,min=,sec=), hour, min, sec; 0.321 0 19 15.6 ; print h2hm(24.321,hour=,min=), hour, min; 0.321 0 19.26 In addtion: Renumbered regression tests 3408 thru 3437, to 9102 thru 9131. Updated Added hms.cal resource file to use h2hms() builtin. Updated Added dms.cal resource file to use d2dms() builtin. Fix minor typo in help/mod SYNOPSIS. Fix minor typo in help/quo SYNOPSIS. Added a few more examples to help/strcmp.
111 lines
3.4 KiB
Plaintext
111 lines
3.4 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.
|
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
##
|
|
## 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/
|