Task

If your language has a library or built-in functions for trigonometry, show examples of:

   sine
   cosine
   tangent
   inverses   (of the above)

using the same angle in radians and degrees.

For the non-inverse functions,   each radian/degree pair should use arguments that evaluate to the same angle   (that is, it's not necessary to use the same angle for all three regular functions as long as the two sine calls use the same angle).

For the inverse functions,   use the same number and convert its answer to radians and degrees.

If your language does not have trigonometric functions available or only has some available,   write functions to calculate the functions based on any   known approximation or identity.




/* NetRexx */
options replace format comments java crossref symbols nobinary utf8
 
numeric digits 30
 
parse 'Radians Degrees angle' RADIANS DEGREES ANGLE .;
parse 'sine cosine tangent arcsine arccosine arctangent' SINE COSINE TANGENT ARCSINE ARCCOSINE ARCTANGENT .
 
trigVals = ''
trigVals[RADIANS, ANGLE     ] = (Rexx Math.PI) / 4 -- Pi/4 == 45 degrees
trigVals[DEGREES, ANGLE     ] = 45.0
trigVals[RADIANS, SINE      ] = (Rexx Math.sin(trigVals[RADIANS, ANGLE]))
trigVals[DEGREES, SINE      ] = (Rexx Math.sin(Math.toRadians(trigVals[DEGREES, ANGLE])))
trigVals[RADIANS, COSINE    ] = (Rexx Math.cos(trigVals[RADIANS, ANGLE]))
trigVals[DEGREES, COSINE    ] = (Rexx Math.cos(Math.toRadians(trigVals[DEGREES, ANGLE])))
trigVals[RADIANS, TANGENT   ] = (Rexx Math.tan(trigVals[RADIANS, ANGLE]))
trigVals[DEGREES, TANGENT   ] = (Rexx Math.tan(Math.toRadians(trigVals[DEGREES, ANGLE])))
trigVals[RADIANS, ARCSINE   ] = (Rexx Math.asin(trigVals[RADIANS, SINE]))
trigVals[DEGREES, ARCSINE   ] = (Rexx Math.toDegrees(Math.acos(trigVals[DEGREES, SINE])))
trigVals[RADIANS, ARCCOSINE ] = (Rexx Math.acos(trigVals[RADIANS, COSINE]))
trigVals[DEGREES, ARCCOSINE ] = (Rexx Math.toDegrees(Math.acos(trigVals[DEGREES, COSINE])))
trigVals[RADIANS, ARCTANGENT] = (Rexx Math.atan(trigVals[RADIANS, TANGENT]))
trigVals[DEGREES, ARCTANGENT] = (Rexx Math.toDegrees(Math.atan(trigVals[DEGREES, TANGENT])))
 
say        ' '.right(12)'|' RADIANS.right(17)                           '|' DEGREES.right(17)                           '|'
say      ANGLE.right(12)'|' trigVals[RADIANS, ANGLE     ].format(4, 12) '|' trigVals[DEGREES, ANGLE     ].format(4, 12) '|'
say       SINE.right(12)'|' trigVals[RADIANS, SINE      ].format(4, 12) '|' trigVals[DEGREES, SINE      ].format(4, 12) '|'
say     COSINE.right(12)'|' trigVals[RADIANS, COSINE    ].format(4, 12) '|' trigVals[DEGREES, COSINE    ].format(4, 12) '|'
say    TANGENT.right(12)'|' trigVals[RADIANS, TANGENT   ].format(4, 12) '|' trigVals[DEGREES, TANGENT   ].format(4, 12) '|'
say    ARCSINE.right(12)'|' trigVals[RADIANS, ARCSINE   ].format(4, 12) '|' trigVals[DEGREES, ARCSINE   ].format(4, 12) '|'
say  ARCCOSINE.right(12)'|' trigVals[RADIANS, ARCCOSINE ].format(4, 12) '|' trigVals[DEGREES, ARCCOSINE ].format(4, 12) '|'
say ARCTANGENT.right(12)'|' trigVals[RADIANS, ARCTANGENT].format(4, 12) '|' trigVals[DEGREES, ARCTANGENT].format(4, 12) '|'
say
 
return
 