Completed degree, radian, gradian builtin conversions

Updated CHANGES.

Updated help/unexpected.

Added help files for d2g(), d2r(), g2d(), g2r(), r2d(), r2g().

Added regression test code for the same functions.

Fixed a few minor typos.
This commit is contained in:
Landon Curt Noll
2021-09-07 13:28:03 -07:00
parent 554cd97145
commit ca5a81122a
10 changed files with 490 additions and 31 deletions

View File

@@ -356,7 +356,7 @@ BLT_HELP_FILES= ${BLT_HELP_FILES_3} ${BLT_HELP_FILES_5} \
#
# Please use:
#
# make detail_help_list
# make clobber >/dev/null && make detail_help_list
#
# to keep this list in nice sorted order.
#
@@ -364,32 +364,32 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
append appr arg argv arrow asec asech asin asinh assign atan atan2 \
atanh avg base base2 bernoulli bit blk blkcpy blkfree blocks bround \
btrunc calc_tty calclevel calcpath catalan ceil cfappr cfsim char \
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime delete \
den dereference det digit digits display dp epsilon errcount errmax \
errno error estr euler eval exp fact factor fclose fcnt feof ferror \
fflush fgetc fgetfield fgetfile fgetline fgets fgetstr fib files floor \
fopen forall fpathopen fprintf fputc fputs fputstr frac free \
freebernoulli freeeuler freeglobals freeredc freestatics frem freopen \
fscan fscanf fseek fsize ftell gcd gcdrem gd getenv hash head highbit \
hmean hnrmod hypot ilog ilog10 ilog2 im indices inputlevel insert int \
inverse iroot isalnum isalpha isassoc isatty isblk iscntrl isconfig \
isdefined isdigit iserror iseven isfile isgraph ishash isident isint \
islist islower ismat ismult isnull isnum isobj isobjtype isodd isprime \
isprint isptr ispunct isqrt isrand israndom isreal isrel issimple \
isspace issq isstr istype isupper isxdigit jacobi join lcm lcmfact \
lfactor ln log lowbit ltol makelist matdim matfill matmax matmin \
matsum mattrace mattrans max memsize meq min minv mmin mne mod modify \
name near newerror nextcand nextprime norm null num oldvalue ord param \
perm pfact pi pix places pmod polar poly pop popcnt pound power \
prevcand prevprime printf prompt protect ptest push putenv questions \
quo quomod rand randbit random randombit randperm rcin rcmul rcout \
rcpow rcsq re remove reverse rewind rm root round rsearch runtime \
saveval scale scan scanf search sec sech seed segment select sgn sha1 \
sin sinh size sizeof sleep sort sqrt srand srandom ssq stoponerror str \
strcasecmp strcat strcmp strcpy strerror strlen strncasecmp strncmp \
strncpy strpos strprintf strscan strscanf strtolower strtoupper substr \
sum swap system systime tail tan tanh test time trunc usertime version \
xor
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime d2g d2r \
delete den dereference det digit digits display dp epsilon errcount \
errmax errno error estr euler eval exp fact factor fclose fcnt feof \
ferror fflush fgetc fgetfield fgetfile fgetline fgets fgetstr fib \
files floor fopen forall fpathopen fprintf fputc fputs fputstr frac \
free freebernoulli freeeuler freeglobals freeredc freestatics frem \
freopen fscan fscanf fseek fsize ftell g2d g2d.bak g2r gcd gcdrem gd \
getenv hash head highbit hmean hnrmod hypot ilog ilog10 ilog2 im \
indices inputlevel insert int inverse iroot isalnum isalpha isassoc \
isatty isblk iscntrl isconfig isdefined isdigit iserror iseven isfile \
isgraph ishash isident isint islist islower ismat ismult isnull isnum \
isobj isobjtype isodd isprime isprint isptr ispunct isqrt isrand \
israndom isreal isrel issimple isspace issq isstr istype isupper \
isxdigit jacobi join lcm lcmfact lfactor ln log lowbit ltol makelist \
matdim matfill matmax matmin matsum mattrace mattrans max memsize meq \
min minv mmin mne mod modify name near newerror nextcand nextprime \
norm null num oldvalue ord param perm pfact pi pix places pmod polar \
poly pop popcnt pound power prevcand prevprime printf prompt protect \
ptest push putenv quo quomod r2d r2g rand randbit random randombit \
randperm rcin rcmul rcout rcpow rcsq re remove reverse rewind rm root \
round rsearch runtime saveval scale scan scanf search sec sech seed \
segment select sgn sha1 sin sinh size sizeof sleep sort sqrt srand \
srandom ssq stoponerror str strcasecmp strcat strcmp strcpy strerror \
strlen strncasecmp strncmp strncpy strpos strprintf strscan strscanf \
strtolower strtoupper substr sum swap system systime tail tan tanh \
test time trunc usertime version xor
# This list is of files that are clones of DETAIL_HELP files. They are
# built from DETAIL_HELP files.

55
help/d2g Normal file
View File

@@ -0,0 +1,55 @@
NAME
d2g - convert degrees to gradians
SYNOPSIS
d2g(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x degrees, return the equivalent number of gradians.
The eps argument is ignored.
EXAMPLE
; print d2g(45), d2g(180), d2g(30)
50 200 ~33.33333333333333333333
; print d2g(3i+2)
~2.22222222222222222222+~3.33333333333333333333i
LIMITS
none
LINK LIBRARY
none
SEE ALSO
d2r, r2d, g2r, r2g, g2d,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

59
help/d2r Normal file
View File

@@ -0,0 +1,59 @@
NAME
d2r - convert degrees to radians
SYNOPSIS
d2r(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x degrees, return the equivalent number of radians.
The eps controls the precision of the calculated internal
constant pi / 180.
EXAMPLE
; print d2r(45), d2r(180), d2r(30)
~0.78539816339744830962 3.14159265358979323846 ~0.52359877559829887308
; print d2r(3i+2)
~0.03490658503988659154+~0.05235987755982988731i
; print sin(d2r(30)), cos(d2r(60)), tan(d2r(45))
0.5 0.5 1
LIMITS
eps > 0
LINK LIBRARY
NUMBER *qpidiv180(NUMBER *eps)
SEE ALSO
r2d, g2r, r2g, d2g, g2d,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

55
help/g2d Normal file
View File

@@ -0,0 +1,55 @@
NAME
g2d - convert gradians to degrees
SYNOPSIS
g2d(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x gradians, return the equivalent number of degrees.
The eps argument is ignored.
EXAMPLE
; print g2d(50), g2d(200), g2d(30)
45 180 27
; print g2d(3i+2)
1.8+2.7i
LIMITS
none
LINK LIBRARY
none
SEE ALSO
d2r, r2d, g2r, r2g, d2g,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

59
help/g2r Normal file
View File

@@ -0,0 +1,59 @@
NAME
g2r - convert gradians to radians
SYNOPSIS
g2r(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x gradians, return the equivalent number of radians.
The eps controls the precision of the calculated internal
constant pi / 200.
EXAMPLE
; print g2r(50), g2r(200), g2r(50)
~0.78539816339744830962 3.14159265358979323846 ~0.78539816339744830962
; print g2r(3i+2)
~0.03141592653589793238+~0.04712388980384689858i
; print sin(g2r(100/3)), cos(g2r(200/3)), tan(g2r(50))
0.5 0.5 1
LIMITS
eps > 0
LINK LIBRARY
NUMBER *qpidiv200(NUMBER *eps)
SEE ALSO
d2r, r2d, r2g, d2g, g2d,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

57
help/r2d Normal file
View File

@@ -0,0 +1,57 @@
NAME
r2d - convert radians to degrees
SYNOPSIS
r2d(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x radians, return the equivalent number of degrees.
The eps controls the precision of the calculated internal
constant pi / 180.
EXAMPLE
; pi = pi(1e-20)
; print r2d(pi), r2d(pi/3), r2d(2*pi)
180 60 360
; print r2d(pi+4i), r2d(pi/3 + 1i*pi), r2d(pi/5 + 5i*pi)
180+~229.18311805232928350739i 60+180, 36+900i
LIMITS
eps > 0
LINK LIBRARY
NUMBER *qpidiv180(NUMBER *eps)
SEE ALSO
d2r, g2r, r2g, d2g, g2d,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

57
help/r2g Normal file
View File

@@ -0,0 +1,57 @@
NAME
r2g - convert radians to gradians
SYNOPSIS
r2g(x [,eps])
TYPES
x number (real or complex)
eps nonzero real, defaults to epsilon()
return number
DESCRIPTION
Given x radians, return the equivalent number of gradians.
The eps controls the precision of the calculated internal
constant pi / 200.
EXAMPLE
; pi = pi()
; print r2g(pi), r2g(pi/3), r2g(2*pi)
200 ~66.66666666666666666667 400
; print r2g(pi+4i), r2g(pi/4 + 1i*pi), r2g(pi/5 + 5i*pi)
200+~254.64790894703253723043i 50+200i 40+1000i
LIMITS
eps > 0
LINK LIBRARY
NUMBER *qpidiv200(NUMBER *eps)
SEE ALSO
d2r, r2d, g2r, d2g, g2d,
sin, cos, tan, sec, csc, cot, epsilon
## Copyright (C) 2021 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: 2021/09/07 12:04:28
## File existed as early as: 2021
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/

View File

@@ -228,7 +228,7 @@ Unexpected
1<<8/2
evalues to 128, not 16, because <<8 is performed before the /2.
evaluates to 128, not 16, because <<8 is performed before the /2.
&A[0] and A are different things in calc
@@ -529,6 +529,34 @@ Unexpected
; help fclose
trig functions use only radians
===============================
Some might be surprised to discover that all of the trigonometric in calc:
sin, cos, tan, sec, csc, cot
asin, acos, atan, asec, acsc, acot
work in only radians.
Calc as builtin functions to convert between degrees, radians and gradians:
d2r(deg) - given degrees returns radians
g2r(grad) - given gradians returns radians
r2d(rad) - given radians returns degrees
g2d(grad) - given gradians returns degrees
r2g(rad) - given radians returns gradians
d2g(deg) - given degrees returns gradians
For example, if you want to take the sin of 30 degrees, convert
the 30 degrees into radians and pass the result to sin():
; print sin(d2r(30))
0.5
## Copyright (C) 1999-2007,2014,2017,2021 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under