01-08-2016, 09:36 AM
Hi to everybody!
I created a small program that provides conversion from radians or degrees to gradian and viceversa. There are also the three basic trigonometric functions and their inverse functions that work directly in gradians.
I hope it is useful to someone. If there are errors and bugs report it!
I created a small program that provides conversion from radians or degrees to gradian and viceversa. There are also the three basic trigonometric functions and their inverse functions that work directly in gradians.
I hope it is useful to someone. If there are errors and bugs report it!
Code:
// Gradian Toolbox
// January 2016
// HAngle = 1 -> degrees mode
// HAngle = 0 -> radian mode
// Exact function removes approximation error
// Approx function convert decimal value to fraction whenever possible
// Converting to grads
EXPORT TO_GRAD(n)
BEGIN
IF HAngle == 1 THEN
RETURN 10*n/9;
ELSE
RETURN 200*n/π;
END;
END;
// Convert from grads
EXPORT FROM_GRAD(n)
BEGIN
IF HAngle == 1 THEN
RETURN 9*n/10;
ELSE
RETURN n*π/200;
END;
END;
// Grads cosine
EXPORT COS_G(n)
BEGIN
RETURN COS(FROM_GRAD(n));
END;
// Grads sine
EXPORT SIN_G(n)
BEGIN
RETURN SIN(FROM_GRAD(n));
END;
// Grads tangent
EXPORT TAN_G(n)
BEGIN
RETURN TAN(FROM_GRAD(n));
END;
// Grads arccosine
EXPORT ACOS_G(n)
BEGIN
IF HAngle == 1 THEN
RETURN approx(exact(10*ACOS(n)/9));
ELSE
RETURN approx(exact(200*ACOS(n)/π));
END;
END;
// Grads arcsine
EXPORT ASIN_G(n)
BEGIN
IF HAngle == 1 THEN
RETURN approx(exact(10*ASIN(n)/9));
ELSE
RETURN approx(exact(200*ASIN(n)/π));
END;
END;
// Grads arctangent
EXPORT ATAN_G(n)
BEGIN
IF HAngle == 1 THEN
RETURN approx(exact(10*ATAN(n)/9));
ELSE
RETURN approx(exact(200*ATAN(n)/π));
END;
END;