mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Added more builtin inverse conversion functions
Added builtin functions to convert between degrees, minutes and seconds and degrees under the config("mod") round rules: dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg dm2d(d, m [,rnd]) - convert deg, min to deg See help/dms2d and help/dm2d. Example: ; print dms2d(12, 20, 44.16); 12.3456 ; print dm2d(3601, -25.5594); 0.57401 Added builtin functions to convert between gradians, minutes and seconds and gradians under the config("mod") round rules: gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad gm2g(g, m [,rnd]) - convert grad and min to grad See help/g2gms and help/g2gm. Example: ; print gms2g(12, 20, 44.16); 12.3456 ; print gm2g(4001, -25.5594); 0.57401 Added builtin functions to convert between hours, minutes and seconds and hours under the config("mod") round rules: hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours hm2h(h, m [,rnd]) - convert hours, min to hours See help/hms2h and help/hm2h. Example: ; print hms2h(12, 20, 44.16); 12.3456 ; print hm2h(241, -25.5594); 0.57401
This commit is contained in:
48
CHANGES
48
CHANGES
@@ -143,6 +143,54 @@ The following are the changes from calc version 2.14.0.0 to date:
|
||||
|
||||
Added a few more examples to help/strcmp.
|
||||
|
||||
Added builtin functions to convert between degrees, minutes and
|
||||
seconds and degrees under the config("mod") round rules:
|
||||
|
||||
dms2d(d, m, s [,rnd]) - convert deg, min, and secs to deg
|
||||
dm2d(d, m [,rnd]) - convert deg, min to deg
|
||||
|
||||
See help/dms2d and help/dm2d.
|
||||
|
||||
Example:
|
||||
|
||||
; print dms2d(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print dm2d(3601, -25.5594);
|
||||
0.57401
|
||||
|
||||
Added builtin functions to convert between gradians, minutes and
|
||||
seconds and gradians under the config("mod") round rules:
|
||||
|
||||
gms2g(g, m, s [,rnd]) - convert grad, min, and secs to grad
|
||||
gm2g(g, m [,rnd]) - convert grad and min to grad
|
||||
|
||||
See help/g2gms and help/g2gm.
|
||||
|
||||
Example:
|
||||
|
||||
; print gms2g(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print gm2g(4001, -25.5594);
|
||||
0.57401
|
||||
|
||||
Added builtin functions to convert between hours, minutes and
|
||||
seconds and hours under the config("mod") round rules:
|
||||
|
||||
hms2h(h, m, s [,rnd]) - convert hours, min, and secs to hours
|
||||
hm2h(h, m [,rnd]) - convert hours, min to hours
|
||||
|
||||
See help/hms2h and help/hm2h.
|
||||
|
||||
Example:
|
||||
|
||||
; print hms2h(12, 20, 44.16);
|
||||
12.3456
|
||||
|
||||
; print hm2h(241, -25.5594);
|
||||
0.57401
|
||||
|
||||
|
||||
The following are the changes from calc version 2.13.0.1 to 2.13.0.1:
|
||||
|
||||
|
110
cal/regress.cal
110
cal/regress.cal
@@ -8563,7 +8563,115 @@ define test_functions3()
|
||||
vrfy(m == -40.74,
|
||||
'9213: m == -40.74');
|
||||
|
||||
print '9214: Ending test_functions3';
|
||||
/* dm2d */
|
||||
vrfy(dm2d(203, 325.5594) == 208.42599,
|
||||
'9214: dm2d(203, 325.5594) == 208.42599');
|
||||
vrfy(dm2d(3601, -25.5594) == 0.57401,
|
||||
'9215: dm2d(3601, -25.5594) == 0.57401');
|
||||
vrfy(dm2d(-923, -25.5594) == 156.57401,
|
||||
'9216: dm2d(-923, -25.5594) == 156.57401');
|
||||
vrfy(dm2d(203, 325.5594, 1) == -151.57401,
|
||||
'9217: dm2d(203, 325.5594, 1) == -151.57401');
|
||||
|
||||
vrfy(d2dm(dm2d(12, 20.16),d,m) == 12.336,
|
||||
'9218: d2dm(dm2d(12, 20.16),d,m) == 12.336');
|
||||
vrfy(d == 12,
|
||||
'9219: d == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9220: m == 20.16');
|
||||
|
||||
/* dms2d */
|
||||
vrfy(dms2d(12, 20, 44.16) == 12.3456,
|
||||
'9221: dms2d(12, 20, 44.16) == 12.3456');
|
||||
vrfy(dms2d(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9222: dms2d(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(dms2d(-65, -40, -44.4) == 294.321,
|
||||
'9223: dms2d(-65, -40, -44.4) == 294.321');
|
||||
vrfy(dms2d(12, 20, 44.16, 1) == -347.6544,
|
||||
'9224: dms2d(12, 20, 44.16, 1) == -347.6544');
|
||||
|
||||
vrfy(d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456,
|
||||
'9225: d2dms(dms2d(13, 20, 44.16),d,m,s) == 13.3456');
|
||||
vrfy(d == 13,
|
||||
'9226: d == 13');
|
||||
vrfy(m == 20,
|
||||
'9227: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9228: s == 44.16');
|
||||
|
||||
/* gm2g */
|
||||
vrfy(gm2g(203, 325.5594) == 208.42599,
|
||||
'9229: gm2g(203, 325.5594) == 208.42599');
|
||||
vrfy(gm2g(3601, -25.5594) == 0.57401,
|
||||
'9230: gm2g(3601, -25.5594) == 0.57401');
|
||||
vrfy(gm2g(-923, -25.5594) == 276.57401,
|
||||
'9231: gm2g(-923, -25.5594) == 276.57401');
|
||||
vrfy(gm2g(203, 325.5594, 1) == -191.57401,
|
||||
'9232: gm2g(203, 325.5594, 1) == -191.57401');
|
||||
|
||||
vrfy(g2gm(gm2g(12, 20.16),g,m) == 12.336,
|
||||
'9233: g2gm(gm2g(12, 20.16),g,m) == 12.336');
|
||||
vrfy(g == 12,
|
||||
'9234: g == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9235: m == 20.16');
|
||||
|
||||
/* gms2g */
|
||||
vrfy(gms2g(12, 20, 44.16) == 12.3456,
|
||||
'9236: gms2g(12, 20, 44.16) == 12.3456');
|
||||
vrfy(gms2g(123.456, -345.68, 4.08) == 117.6958,
|
||||
'9237: gms2g(123.456, -345.68, 4.08) == 117.6958');
|
||||
vrfy(gms2g(-65, -40, -44.4) == 334.321,
|
||||
'9238: gms2g(-65, -40, -44.4) == 334.321');
|
||||
vrfy(gms2g(12, 20, 44.16, 1) == -387.6544,
|
||||
'9239: gms2g(12, 20, 44.16, 1) == -387.6544');
|
||||
|
||||
vrfy(g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456,
|
||||
'9240: g2gms(gms2g(14, 20, 44.16),g,m,s) == 14.3456');
|
||||
vrfy(g == 14,
|
||||
'9241: g == 14');
|
||||
vrfy(m == 20,
|
||||
'9242: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9243: s == 44.16');
|
||||
|
||||
/* hm2h */
|
||||
vrfy(hm2h(203, 325.5594) == 16.42599,
|
||||
'9244: hm2h(203, 325.5594) == 16.42599');
|
||||
vrfy(hm2h(241, -25.5594) == 0.57401,
|
||||
'9245: hm2h(241, -25.5594) == 0.57401');
|
||||
vrfy(hm2h(-923, -25.5594) == 12.57401,
|
||||
'9246: hm2h(-923, -25.5594) == 12.57401');
|
||||
vrfy(hm2h(203, 325.5594, 1) == -7.57401,
|
||||
'9247: hm2h(203, 325.5594, 1) == -7.57401');
|
||||
|
||||
vrfy(h2hm(hm2h(12, 20.16),h,m) == 12.336,
|
||||
'9248: h2hm(hm2h(12, 20.16),h,m) == 12.336');
|
||||
vrfy(h == 12,
|
||||
'9249: h == 12');
|
||||
vrfy(m == 20.16,
|
||||
'9250: m == 20.16');
|
||||
|
||||
/* hms2h */
|
||||
vrfy(hms2h(12, 20, 44.16) == 12.3456,
|
||||
'9251: hms2h(12, 20, 44.16) == 12.3456');
|
||||
vrfy(hms2h(123.456, -345.68, 4.08) == 21.6958,
|
||||
'9252: hms2h(123.456, -345.68, 4.08) == 21.6958');
|
||||
vrfy(hms2h(-65, -40, -44.4) == 6.321,
|
||||
'9253: hms2h(-65, -40, -44.4) == 6.321');
|
||||
vrfy(hms2h(12, 20, 44.16, 1) == -11.6544,
|
||||
'9254: hms2h(12, 20, 44.16, 1) == -11.6544');
|
||||
|
||||
vrfy(h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456,
|
||||
'9255: h2hms(hms2h(15, 20, 44.16),h,m,s) == 15.3456');
|
||||
vrfy(h == 15,
|
||||
'9256: h == 15');
|
||||
vrfy(m == 20,
|
||||
'9257: m == 20');
|
||||
vrfy(s == 44.16,
|
||||
'9258: s == 44.16');
|
||||
|
||||
print '9259: Ending test_functions3';
|
||||
}
|
||||
print;
|
||||
print '9100: parsed test_functions3()';
|
||||
|
12
calcerr.tbl
12
calcerr.tbl
@@ -530,3 +530,15 @@ E_H2HM1 Non-lvalue arguments 2 or 3 for h2hm
|
||||
E_H2HM2 Non-real-number arg 1 for h2hm
|
||||
E_H2HM3 No-assign-to argument 2 or 3 for h2hm
|
||||
E_H2HM4 Invalid rounding arg 4 for h2hm
|
||||
E_DMS2D1 Non-real-number aarguments 1, 2 or 3 for dms2d
|
||||
E_DMS2D2 Invalid rounding arg 4 for dms2d
|
||||
E_DM2D1 Non-real-number aarguments 1 or 2 for dm2d
|
||||
E_DM2D2 Invalid rounding arg 4 for dm2d
|
||||
E_GMS2G1 Non-real-number aarguments 1, 2 or 3 for gms2g
|
||||
E_GMS2G2 Invalid rounding arg 4 for gms2g
|
||||
E_GM2G1 Non-real-number aarguments 1 or 2 for gm2g
|
||||
E_GM2G2 Invalid rounding arg 4 for gm2g
|
||||
E_HMS2H1 Non-real-number aarguments 1, 2 or 3 for hms2h
|
||||
E_HMS2H2 Invalid rounding arg 4 for hms2h
|
||||
E_HM2H1 Non-real-number aarguments 1 or 2 for hm2h
|
||||
E_HM2H2 Invalid rounding arg 4 for hm2h
|
||||
|
402
func.c
402
func.c
@@ -4588,6 +4588,396 @@ f_h2hm(int count, VALUE **vals)
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_dms2d(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3, *v4;
|
||||
NUMBER *tmp, *tmp2, *tmp3, *tmp4;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
v3 = vals[2];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 4) {
|
||||
v4 = vals[3];
|
||||
if (v4->v_type == V_ADDR) {
|
||||
v4 = v4->v_addr;
|
||||
}
|
||||
if (v4->v_type != V_NUM || qisfrac(v4->v_num) ||
|
||||
qisneg(v4->v_num) || zge31b(v4->v_num->num)) {
|
||||
return error_value(E_DMS2D2);
|
||||
}
|
||||
rnd = qtoi(v4->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM ||
|
||||
v3->v_type != V_NUM) {
|
||||
return error_value(E_DMS2D1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute s/3600
|
||||
*/
|
||||
tmp = qdivi(v3->v_num, 3600);
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp2 = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute m/60 + s/3600
|
||||
*/
|
||||
tmp3 = qqadd(tmp2, tmp);
|
||||
qfree(tmp);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* compute d + m/60 + s/3600
|
||||
*/
|
||||
tmp4 = qqadd(v1->v_num, tmp3);
|
||||
qfree(tmp3);
|
||||
|
||||
/*
|
||||
* compute mod(d + m/60 + s/3600, 360, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp4, &_qthreesixty, rnd);
|
||||
qfree(tmp4);
|
||||
|
||||
/*
|
||||
* return mod(d + m/60 + s/3600, 360, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_dm2d(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3;
|
||||
NUMBER *tmp, *tmp2;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 3) {
|
||||
v3 = vals[2];
|
||||
if (v3->v_type == V_ADDR) {
|
||||
v3 = v3->v_addr;
|
||||
}
|
||||
if (v3->v_type != V_NUM || qisfrac(v3->v_num) ||
|
||||
qisneg(v3->v_num) || zge31b(v3->v_num->num)) {
|
||||
return error_value(E_DM2D2);
|
||||
}
|
||||
rnd = qtoi(v3->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM) {
|
||||
return error_value(E_DM2D1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute d + m/60
|
||||
*/
|
||||
tmp2 = qqadd(v1->v_num, tmp);
|
||||
qfree(tmp);
|
||||
|
||||
/*
|
||||
* compute mod(d + m/60, 360, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp2, &_qthreesixty, rnd);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* return mod(d + m/60, 360, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_gms2g(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3, *v4;
|
||||
NUMBER *tmp, *tmp2, *tmp3, *tmp4;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
v3 = vals[2];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 4) {
|
||||
v4 = vals[3];
|
||||
if (v4->v_type == V_ADDR) {
|
||||
v4 = v4->v_addr;
|
||||
}
|
||||
if (v4->v_type != V_NUM || qisfrac(v4->v_num) ||
|
||||
qisneg(v4->v_num) || zge31b(v4->v_num->num)) {
|
||||
return error_value(E_GMS2G2);
|
||||
}
|
||||
rnd = qtoi(v4->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM ||
|
||||
v3->v_type != V_NUM) {
|
||||
return error_value(E_GMS2G1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute s/3600
|
||||
*/
|
||||
tmp = qdivi(v3->v_num, 3600);
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp2 = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute m/60 + s/3600
|
||||
*/
|
||||
tmp3 = qqadd(tmp2, tmp);
|
||||
qfree(tmp);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* compute g + m/60 + s/3600
|
||||
*/
|
||||
tmp4 = qqadd(v1->v_num, tmp3);
|
||||
qfree(tmp3);
|
||||
|
||||
/*
|
||||
* compute mod(g + m/60 + s/3600, 400, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp4, &_qfourhundred, rnd);
|
||||
qfree(tmp4);
|
||||
|
||||
/*
|
||||
* return mod(g + m/60 + s/3600, 400, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_gm2g(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3;
|
||||
NUMBER *tmp, *tmp2;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 3) {
|
||||
v3 = vals[2];
|
||||
if (v3->v_type == V_ADDR) {
|
||||
v3 = v3->v_addr;
|
||||
}
|
||||
if (v3->v_type != V_NUM || qisfrac(v3->v_num) ||
|
||||
qisneg(v3->v_num) || zge31b(v3->v_num->num)) {
|
||||
return error_value(E_GM2G2);
|
||||
}
|
||||
rnd = qtoi(v3->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM) {
|
||||
return error_value(E_GM2G1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute g + m/60
|
||||
*/
|
||||
tmp2 = qqadd(v1->v_num, tmp);
|
||||
qfree(tmp);
|
||||
|
||||
/*
|
||||
* compute mod(g + m/60, 400, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp2, &_qfourhundred, rnd);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* return mod(g + m/60, 400, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_hms2h(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3, *v4;
|
||||
NUMBER *tmp, *tmp2, *tmp3, *tmp4;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
v3 = vals[2];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 4) {
|
||||
v4 = vals[3];
|
||||
if (v4->v_type == V_ADDR) {
|
||||
v4 = v4->v_addr;
|
||||
}
|
||||
if (v4->v_type != V_NUM || qisfrac(v4->v_num) ||
|
||||
qisneg(v4->v_num) || zge31b(v4->v_num->num)) {
|
||||
return error_value(E_HMS2H2);
|
||||
}
|
||||
rnd = qtoi(v4->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM ||
|
||||
v3->v_type != V_NUM) {
|
||||
return error_value(E_HMS2H1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute s/3600
|
||||
*/
|
||||
tmp = qdivi(v3->v_num, 3600);
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp2 = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute m/60 + s/3600
|
||||
*/
|
||||
tmp3 = qqadd(tmp2, tmp);
|
||||
qfree(tmp);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* compute h + m/60 + s/3600
|
||||
*/
|
||||
tmp4 = qqadd(v1->v_num, tmp3);
|
||||
qfree(tmp3);
|
||||
|
||||
/*
|
||||
* compute mod(h + m/60 + s/3600, 24, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp4, &_qtwentyfour, rnd);
|
||||
qfree(tmp4);
|
||||
|
||||
/*
|
||||
* return mod(d + m/60 + s/3600, 24, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_hm2h(int count, VALUE **vals)
|
||||
{
|
||||
VALUE *v1, *v2, *v3;
|
||||
NUMBER *tmp, *tmp2;
|
||||
VALUE result;
|
||||
long rnd;
|
||||
|
||||
/* collect required args */
|
||||
v1 = vals[0];
|
||||
v2 = vals[1];
|
||||
|
||||
/* determine rounding mode */
|
||||
if (count == 3) {
|
||||
v3 = vals[2];
|
||||
if (v3->v_type == V_ADDR) {
|
||||
v3 = v3->v_addr;
|
||||
}
|
||||
if (v3->v_type != V_NUM || qisfrac(v3->v_num) ||
|
||||
qisneg(v3->v_num) || zge31b(v3->v_num->num)) {
|
||||
return error_value(E_H2HM2);
|
||||
}
|
||||
rnd = qtoi(v3->v_num);
|
||||
} else {
|
||||
rnd = conf->quomod;
|
||||
}
|
||||
|
||||
/* type parse args */
|
||||
if (v1->v_type != V_NUM || v2->v_type != V_NUM) {
|
||||
return error_value(E_H2HM1);
|
||||
}
|
||||
|
||||
/*
|
||||
* compute m/60
|
||||
*/
|
||||
tmp = qdivi(v2->v_num, 60);
|
||||
|
||||
/*
|
||||
* compute d + m/60
|
||||
*/
|
||||
tmp2 = qqadd(v1->v_num, tmp);
|
||||
qfree(tmp);
|
||||
|
||||
/*
|
||||
* compute mod(h + m/60, 24, rnd);
|
||||
*/
|
||||
result.v_type = v1->v_type;
|
||||
result.v_subtype = v1->v_subtype;
|
||||
result.v_num = qmod(tmp2, &_qtwentyfour, rnd);
|
||||
qfree(tmp2);
|
||||
|
||||
/*
|
||||
* return mod(h + m/60, 24, rnd);
|
||||
*/
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
S_FUNC VALUE
|
||||
f_mmin(VALUE *v1, VALUE *v2)
|
||||
{
|
||||
@@ -9576,6 +9966,10 @@ STATIC CONST struct builtin builtins[] = {
|
||||
"number of digits in base b representation of a"},
|
||||
{"display", 0, 1, 0, OP_NOP, 0, f_display,
|
||||
"number of decimal digits for displaying numbers"},
|
||||
{"dm2d", 2, 3, 0, OP_NOP, 0, f_dm2d,
|
||||
"convert a deg, b min to degrees, rounding type c\n"},
|
||||
{"dms2d", 3, 4, 0, OP_NOP, 0, f_dms2d,
|
||||
"convert a deg, b min, c sec to degrees, rounding type d\n"},
|
||||
{"dp", 2, 2, 0, OP_NOP, 0, f_dp,
|
||||
"dot product of two vectors"},
|
||||
{"epsilon", 0, 1, 0, OP_SETEPSILON, 0, 0,
|
||||
@@ -9690,6 +10084,10 @@ STATIC CONST struct builtin builtins[] = {
|
||||
"Gudermannian function"},
|
||||
{"getenv", 1, 1, 0, OP_NOP, 0, f_getenv,
|
||||
"value of environment variable (or NULL)"},
|
||||
{"gm2g", 2, 3, 0, OP_NOP, 0, f_gm2g,
|
||||
"convert a grads, b min to grads, rounding type c\n"},
|
||||
{"gms2g", 3, 4, 0, OP_NOP, 0, f_gms2g,
|
||||
"convert a grads, b min, c sec to grads, rounding type d\n"},
|
||||
{"h2hm", 3, 4, FA, OP_NOP, 0, f_h2hm,
|
||||
"convert a to b hours, c min, rounding type d\n"},
|
||||
{"h2hms", 4, 5, FA, OP_NOP, 0, f_h2hms,
|
||||
@@ -9701,6 +10099,10 @@ STATIC CONST struct builtin builtins[] = {
|
||||
"return list of specified number at head of a list"},
|
||||
{"highbit", 1, 1, 0, OP_HIGHBIT, 0, 0,
|
||||
"high bit number in base 2 representation"},
|
||||
{"hm2h", 2, 3, 0, OP_NOP, 0, f_hm2h,
|
||||
"convert a hours, b min to hours, rounding type c\n"},
|
||||
{"hms2h", 3, 4, 0, OP_NOP, 0, f_hms2h,
|
||||
"convert a hours, b min, c sec to hours, rounding type d\n"},
|
||||
{"hmean", 0, IN, 0, OP_NOP, 0, f_hmean,
|
||||
"harmonic mean of values"},
|
||||
{"hnrmod", 4, 4, 0, OP_NOP, f_hnrmod, 0,
|
||||
|
3
help.c
3
help.c
@@ -83,6 +83,9 @@ STATIC struct help_alias {
|
||||
{"show", "command"},
|
||||
{"stdlib", "resource"},
|
||||
{"question", "questions"},
|
||||
{"dm2d", "dms2d"},
|
||||
{"gm2g", "gms2g"},
|
||||
{"hm2d", "hms2d"},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
@@ -365,17 +365,17 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
|
||||
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 d2dm \
|
||||
d2dms d2g d2r delete den dereference det digit digits display dp \
|
||||
d2dms d2g d2r delete den dereference det digit digits display dms2d 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 g2gm g2gms \
|
||||
g2r gcd gcdrem gd getenv h2hm h2hms 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 \
|
||||
g2r gcd gcdrem gd getenv gms2g h2hm h2hms hash head highbit hmean \
|
||||
hms2h 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 \
|
||||
|
@@ -76,7 +76,7 @@ EXAMPLE
|
||||
; global d, m, s;
|
||||
|
||||
; print d2dms(12.3456,d,m,s), d, m, s;
|
||||
12.3456, 12, 20, 44.16
|
||||
12.3456 12 20 44.16
|
||||
; print d2dms(1234.5678,d,m,s), d, m, s;
|
||||
154.5678 154 34 4.08
|
||||
; print d2dms(-1234.5678,d,m,s), d, m, s;
|
||||
|
84
help/dms2d
Normal file
84
help/dms2d
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
dm2d, dms2d - convert degrees, minutes, and seconds to degrees
|
||||
|
||||
SYNOPSIS
|
||||
dm2d(d, m [,rnd])
|
||||
dms2d(d, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
d real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return degrees
|
||||
|
||||
DESCRIPTION
|
||||
Convert degrees, m minutes, and s seconds returning degrees.
|
||||
|
||||
The return value in degrees, is quivalent to the following:
|
||||
|
||||
mod(d + m/60 + s/3600, 360, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 360) or a real value in the interval (-360, 0].
|
||||
For the default round mode, the return value is in the interval [0, 360).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The dm2d(d, m, rnd) builtin is an alias for dms2d(d, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print dm2d(203, 325.5594);
|
||||
208.42599
|
||||
; print dm2d(3601, -25.5594);
|
||||
0.57401
|
||||
; print dm2d(-923, -25.5594);
|
||||
156.57401
|
||||
|
||||
; print dms2d(12, 20, 44.16);
|
||||
12.3456
|
||||
; print dms2d(123.456, -345.68, 4.08);
|
||||
117.6958
|
||||
; print dms2d(-65, -40, -44.4);
|
||||
294.321
|
||||
|
||||
; print dm2d(203, 325.5594, 1);
|
||||
-151.57401
|
||||
; print dms2d(12, 20, 44.16, 1);
|
||||
-347.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## 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/25 17:24:51
|
||||
## 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/
|
84
help/gms2g
Normal file
84
help/gms2g
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
gm2g, gms2g - convert gradians, minutes, and seconds to gradians
|
||||
|
||||
SYNOPSIS
|
||||
gm2g(d, m [,rnd])
|
||||
gms2g(d, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
d real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return gradians
|
||||
|
||||
DESCRIPTION
|
||||
Convert gradians, m minutes, and s seconds returning gradians.
|
||||
|
||||
The return value in gradians, is quivalent to the following:
|
||||
|
||||
mod(d + m/60 + s/4000, 400, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 400) or a real value in the interval (-400, 0].
|
||||
For the default round mode, the return value is in the interval [0, 400).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The gm2g(d, m, rnd) builtin is an alias for gms2g(d, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print gm2g(203, 325.5594);
|
||||
208.42599
|
||||
; print gm2g(4001, -25.5594);
|
||||
0.57401
|
||||
; print gm2g(-923, -25.5594);
|
||||
276.57401
|
||||
|
||||
; print gms2g(12, 20, 44.16);
|
||||
12.3456
|
||||
; print gms2g(123.456, -345.68, 4.08);
|
||||
117.6958
|
||||
; print gms2g(-65, -40, -44.4);
|
||||
334.321
|
||||
|
||||
; print gm2g(203, 325.5594, 1);
|
||||
-191.57401
|
||||
; print gms2g(12, 20, 44.16, 1);
|
||||
-387.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## 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/25 17:24:51
|
||||
## 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/
|
84
help/hms2h
Normal file
84
help/hms2h
Normal file
@@ -0,0 +1,84 @@
|
||||
NAME
|
||||
hm2h, hms2h - convert hours, minutes, and seconds to hours
|
||||
|
||||
SYNOPSIS
|
||||
hm2h(h, m [,rnd])
|
||||
hms2h(h, m, s [,rnd])
|
||||
|
||||
TYPES
|
||||
h real
|
||||
m real
|
||||
s real (defauls to 0)
|
||||
rnd nonnegative integer, defaults to config("mod")
|
||||
|
||||
return hours
|
||||
|
||||
DESCRIPTION
|
||||
Convert hours, m minutes, and s seconds returning hours.
|
||||
|
||||
The return value in hours, is quivalent to the following:
|
||||
|
||||
mod(h + m/60 + s/3600, 24, rnd);
|
||||
|
||||
Depending on the rounding mode, the return could be a real value
|
||||
in the interval [0, 24) or a real value in the interval (-24, 0].
|
||||
For the default round mode, the return value is in the interval [0, 24).
|
||||
|
||||
A missing rnd defaults to config("mod").
|
||||
For more information on the effects of rnd, see "help mod".
|
||||
|
||||
The hm2h(h, m, rnd) builtin is an alias for hms2h(h, m, 0, rnd).
|
||||
|
||||
|
||||
EXAMPLE
|
||||
; print hm2h(203, 325.5594);
|
||||
16.42599
|
||||
; print hm2h(241, -25.5594);
|
||||
0.57401
|
||||
; print hm2h(-923, -25.5594);
|
||||
12.57401
|
||||
|
||||
; print hms2h(12, 20, 44.16);
|
||||
12.3456
|
||||
; print hms2h(123.456, -345.68, 4.08);
|
||||
21.6958
|
||||
; print hms2h(-65, -40, -44.4);
|
||||
6.321
|
||||
|
||||
; print hm2h(203, 325.5594, 1);
|
||||
-7.57401
|
||||
; print hms2h(12, 20, 44.16, 1);
|
||||
-11.6544
|
||||
|
||||
|
||||
LIMITS
|
||||
none
|
||||
|
||||
LINK LIBRARY
|
||||
none
|
||||
|
||||
SEE ALSO
|
||||
config, d2dm, d2dms, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
|
||||
h2hm, h2hms, hm2d, hms2d, mod
|
||||
|
||||
## 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/25 17:24:51
|
||||
## 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/
|
Reference in New Issue
Block a user