mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 23:40:07 +00:00
Added math.rad() and math.deg()
This commit is contained in:
parent
d1ea5c9703
commit
7c7a2ed8d9
@ -752,6 +752,38 @@ int cosmoB_mATan(CState *state, int nargs, CValue *args) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cosmoB_mRad(CState *state, int nargs, CValue *args) {
|
||||||
|
if (nargs != 1) {
|
||||||
|
cosmoV_error(state, "math.rad() expected 1 argument, got %d!", nargs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IS_NUMBER(args[0])) {
|
||||||
|
cosmoV_typeError(state, "math.rad", "<number>", "%s", cosmoV_typeStr(args[0]));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert the degree to radians
|
||||||
|
cosmoV_pushNumber(state, cosmoV_readNumber(args[0]) * (acos(-1) / 180));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cosmoB_mDeg(CState *state, int nargs, CValue *args) {
|
||||||
|
if (nargs != 1) {
|
||||||
|
cosmoV_error(state, "math.deg() expected 1 argument, got %d!", nargs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IS_NUMBER(args[0])) {
|
||||||
|
cosmoV_typeError(state, "math.deg", "<number>", "%s", cosmoV_typeStr(args[0]));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert the degree to radians
|
||||||
|
cosmoV_pushNumber(state, cosmoV_readNumber(args[0]) * (180 / acos(-1)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void cosmoB_loadMathLib(CState *state) {
|
void cosmoB_loadMathLib(CState *state) {
|
||||||
const char *identifiers[] = {
|
const char *identifiers[] = {
|
||||||
"abs",
|
"abs",
|
||||||
@ -762,7 +794,9 @@ void cosmoB_loadMathLib(CState *state) {
|
|||||||
"tan",
|
"tan",
|
||||||
"asin",
|
"asin",
|
||||||
"acos",
|
"acos",
|
||||||
"atan"
|
"atan",
|
||||||
|
"rad",
|
||||||
|
"deg"
|
||||||
};
|
};
|
||||||
|
|
||||||
CosmoCFunction mathLib[] = {
|
CosmoCFunction mathLib[] = {
|
||||||
@ -774,7 +808,9 @@ void cosmoB_loadMathLib(CState *state) {
|
|||||||
cosmoB_mTan,
|
cosmoB_mTan,
|
||||||
cosmoB_mASin,
|
cosmoB_mASin,
|
||||||
cosmoB_mACos,
|
cosmoB_mACos,
|
||||||
cosmoB_mATan
|
cosmoB_mATan,
|
||||||
|
cosmoB_mRad,
|
||||||
|
cosmoB_mDeg
|
||||||
};
|
};
|
||||||
|
|
||||||
// make math library object
|
// make math library object
|
||||||
|
Loading…
Reference in New Issue
Block a user