Trigonometric functions: Difference between revisions

Content added Content deleted
m (→‎{{header|ooRexx}}: corrected misspelling of Gerard.)
(jq)
Line 1,166: Line 1,166:
// arctangent
// arctangent
window.alert(arctan + " " + (arctan * 180 / Math.PI));</lang>
window.alert(arctan + " " + (arctan * 180 / Math.PI));</lang>

=={{header|jq}}==

jq includes the standard C-library trigonometric functions (sin, cos, tan, asin, acos, atan), but they are provided as filters as illustrated in the definition of <tt>radians</tt> below.

The trigonometric filters only accept radians, so conversion is necessary when dealing with degrees. The constant <tt>π</tt> can be defined as also shown in the following definition of <tt>radians</tt>:<lang jq>
# degrees to radians
def radians:
(-1|acos) as $pi | (. * $pi / 180);

def task:
(-1|acos) as $pi
| ($pi / 180) as $degrees
| "Using radians:",
" sin(-pi / 6) = \( (-$pi / 6) | sin )",
" cos(3 * pi / 4) = \( (3 * $pi / 4) | cos)",
" tan(pi / 3) = \( ($pi / 3) | tan)",
" asin(-1 / 2) = \((-1 / 2) | asin)",
" acos(-sqrt(2)/2) = \((-(2|sqrt)/2) | acos )",
" atan(sqrt(3)) = \( 3 | sqrt | atan )",

"Using degrees:",
" sin(-30) = \((-30 * $degrees) | sin)",
" cos(135) = \((135 * $degrees) | cos)",
" tan(60) = \(( 60 * $degrees) | tan)",
" asin(-1 / 2) = \( (-1 / 2) | asin / $degrees)",
" acos(-sqrt(2)/2) = \( (-(2|sqrt) / 2) | acos / $degrees)",
" atan(sqrt(3)) = \( (3 | sqrt) | atan / $degrees)"
;

task
</lang>
{{out}}
<lang sh>Using radians:
sin(-pi / 6) = -0.49999999999999994
cos(3 * pi / 4) = -0.7071067811865475
tan(pi / 3) = 1.7320508075688767
asin(-1 / 2) = -0.5235987755982988
acos(-sqrt(2)/2) = 2.356194490192345
atan(sqrt(3)) = 1.0471975511965979
Using degrees:
sin(-30) = -0.49999999999999994
cos(135) = -0.7071067811865475
tan(60) = 1.7320508075688767
asin(-1 / 2) = -29.999999999999996
acos(-sqrt(2)/2) = 135
atan(sqrt(3)) = 60.00000000000001</lang>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==