mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Initial code for g2d() & d2g() builtins
We still need to add: help files for g2d & d2g regression tests for g2d & d2g notes in related trig help files note in unexpected help file note in CHANGES
This commit is contained in:
@@ -504,3 +504,5 @@ E_G2R1 Bad epsilon for converting gradians to radians
|
|||||||
E_G2R2 Bad first argument converting gradians to radians
|
E_G2R2 Bad first argument converting gradians to radians
|
||||||
E_R2G1 Bad epsilon for converting radians to gradians
|
E_R2G1 Bad epsilon for converting radians to gradians
|
||||||
E_R2G2 Bad first argument converting radians to gradians
|
E_R2G2 Bad first argument converting radians to gradians
|
||||||
|
E_D2G1 Bad first argument converting degrees to gradians
|
||||||
|
E_G2D1 Bad first argument converting gradians to degrees
|
||||||
|
70
func.c
70
func.c
@@ -2349,6 +2349,72 @@ f_r2g(int count, VALUE **vals)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* f_d2g - convert degrees to gradians
|
||||||
|
*
|
||||||
|
* NOTE: The epsilon (vals[1]->v_num) argument is ignored.
|
||||||
|
*/
|
||||||
|
/*ARGSUSED*/
|
||||||
|
S_FUNC VALUE
|
||||||
|
f_d2g(int UNUSED(count), VALUE **vals)
|
||||||
|
{
|
||||||
|
VALUE result;
|
||||||
|
|
||||||
|
/* initialize VALUE */
|
||||||
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
|
/* NOTE: the epsilon (vals[1]->v_num) argument is ignored */
|
||||||
|
|
||||||
|
/* calculate argument * (10/9) */
|
||||||
|
switch (vals[0]->v_type) {
|
||||||
|
case V_NUM:
|
||||||
|
result.v_num = qmul(vals[0]->v_num, &_qtendivnine_);
|
||||||
|
result.v_type = V_NUM;
|
||||||
|
break;
|
||||||
|
case V_COM:
|
||||||
|
result.v_com = c_mulq(vals[0]->v_com, &_qtendivnine_);
|
||||||
|
result.v_type = V_COM;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return error_value(E_D2G1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* f_g2d - convert gradians to degrees
|
||||||
|
*
|
||||||
|
* NOTE: The epsilon (vals[1]->v_num) argument is ignored.
|
||||||
|
*/
|
||||||
|
/*ARGSUSED*/
|
||||||
|
S_FUNC VALUE
|
||||||
|
f_g2d(int UNUSED(count), VALUE **vals)
|
||||||
|
{
|
||||||
|
VALUE result;
|
||||||
|
|
||||||
|
/* initialize VALUE */
|
||||||
|
result.v_subtype = V_NOSUBTYPE;
|
||||||
|
|
||||||
|
/* NOTE: the epsilon (vals[1]->v_num) argument is ignored */
|
||||||
|
|
||||||
|
/* calculate argument * (9/10) */
|
||||||
|
switch (vals[0]->v_type) {
|
||||||
|
case V_NUM:
|
||||||
|
result.v_num = qmul(vals[0]->v_num, &_qninedivten_);
|
||||||
|
result.v_type = V_NUM;
|
||||||
|
break;
|
||||||
|
case V_COM:
|
||||||
|
result.v_com = c_mulq(vals[0]->v_com, &_qninedivten_);
|
||||||
|
result.v_type = V_COM;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return error_value(E_G2D1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
S_FUNC VALUE
|
S_FUNC VALUE
|
||||||
f_sin(int count, VALUE **vals)
|
f_sin(int count, VALUE **vals)
|
||||||
{
|
{
|
||||||
@@ -8838,6 +8904,8 @@ STATIC CONST struct builtin builtins[] = {
|
|||||||
"date and time as string"},
|
"date and time as string"},
|
||||||
{"custom", 0, IN, 0, OP_NOP, 0, f_custom,
|
{"custom", 0, IN, 0, OP_NOP, 0, f_custom,
|
||||||
"custom builtin function interface"},
|
"custom builtin function interface"},
|
||||||
|
{"d2g", 1, 2, 0, OP_NOP, 0, f_d2g,
|
||||||
|
"convert degrees to gradians"},
|
||||||
{"d2r", 1, 2, 0, OP_NOP, 0, f_d2r,
|
{"d2r", 1, 2, 0, OP_NOP, 0, f_d2r,
|
||||||
"convert degrees to radians"},
|
"convert degrees to radians"},
|
||||||
{"delete", 2, 2, FA, OP_NOP, 0, f_listdelete,
|
{"delete", 2, 2, FA, OP_NOP, 0, f_listdelete,
|
||||||
@@ -8950,6 +9018,8 @@ STATIC CONST struct builtin builtins[] = {
|
|||||||
"return the file position"},
|
"return the file position"},
|
||||||
{"frac", 1, 1, 0, OP_FRAC, qfrac, 0,
|
{"frac", 1, 1, 0, OP_FRAC, qfrac, 0,
|
||||||
"fractional part of value"},
|
"fractional part of value"},
|
||||||
|
{"g2d", 1, 2, 0, OP_NOP, 0, f_g2d,
|
||||||
|
"convert gradians to degrees"},
|
||||||
{"g2r", 1, 2, 0, OP_NOP, 0, f_g2r,
|
{"g2r", 1, 2, 0, OP_NOP, 0, f_g2r,
|
||||||
"convert gradians to radians"},
|
"convert gradians to radians"},
|
||||||
{"gcd", 1, IN, 0, OP_NOP, f_gcd, 0,
|
{"gcd", 1, IN, 0, OP_NOP, f_gcd, 0,
|
||||||
|
5
qmath.c
5
qmath.c
@@ -44,9 +44,12 @@ NUMBER _qnegone_ = { { _oneval_, 1, 1 }, { _oneval_, 1, 0 }, 1, NULL };
|
|||||||
NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL };
|
NUMBER _qonehalf_ = { { _oneval_, 1, 0 }, { _twoval_, 1, 0 }, 1, NULL };
|
||||||
NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL };
|
NUMBER _qneghalf_ = { { _oneval_, 1, 1 }, { _twoval_, 1, 0 }, 1, NULL };
|
||||||
NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL };
|
NUMBER _qonesqbase_ = { { _oneval_, 1, 0 }, { _sqbaseval_, 2, 0 }, 1, NULL };
|
||||||
|
NUMBER _qtendivnine_ = { { _tenval_, 1, 0 }, { _nineval_, 1, 0 }, 1, NULL };
|
||||||
|
NUMBER _qninedivten_ = { { _nineval_, 1, 0 }, { _tenval_, 1, 0 }, 1, NULL };
|
||||||
|
|
||||||
NUMBER * initnumbs[INITCONSTCOUNT] = {&_qzero_, &_qone_, &_qtwo_, &_qthree_,
|
NUMBER * initnumbs[INITCONSTCOUNT] = {&_qzero_, &_qone_, &_qtwo_, &_qthree_,
|
||||||
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_};
|
&_qfour_, &_qten_, &_qnegone_, &_qonehalf_, &_qneghalf_,
|
||||||
|
&_qonesqbase_, &_qtendivnine_, &_qninedivten_ };
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
3
qmath.h
3
qmath.h
@@ -35,7 +35,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define INITCONSTCOUNT 9 /* number of initnumbs[] pre-defined constants */
|
#define INITCONSTCOUNT 12 /* number of initnumbs[] pre-defined constants */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rational arithmetic definitions.
|
* Rational arithmetic definitions.
|
||||||
@@ -275,6 +275,7 @@ static inline NUMBER* qlink(NUMBER* q) { if(q) { (q)->links++; } return q; }
|
|||||||
*/
|
*/
|
||||||
EXTERN NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_;
|
EXTERN NUMBER _qzero_, _qone_, _qnegone_, _qonehalf_, _qneghalf_, _qonesqbase_;
|
||||||
EXTERN NUMBER _qtwo_, _qthree_, _qfour_, _qten_;
|
EXTERN NUMBER _qtwo_, _qthree_, _qfour_, _qten_;
|
||||||
|
EXTERN NUMBER _qtendivnine_, _qninedivten_;
|
||||||
EXTERN NUMBER * initnumbs[];
|
EXTERN NUMBER * initnumbs[];
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user