Trigonometric functions: Difference between revisions
Content deleted Content added
m →{{header|AWK}}: Typo in comment. |
→{{header|C}}: Add bc. |
||
Line 232: | Line 232: | ||
PRINT arccos + " " + arccos * 180 / pi |
PRINT arccos + " " + arccos * 180 / pi |
||
PRINT ATN(TAN(radians)) + " " + ATN(TAN(radians)) * 180 / pi 'arctan</lang> |
PRINT ATN(TAN(radians)) + " " + ATN(TAN(radians)) * 180 / pi 'arctan</lang> |
||
=={{header|bc}}== |
|||
{{trans|AWK}} |
|||
<lang bc>/* t(x) = tangent of x */ |
|||
define t(x) { |
|||
return s(x) / c(x) |
|||
} |
|||
/* y(y) = arcsine of y, domain [-1, 1], range [-pi/2, pi/2] */ |
|||
define y(y) { |
|||
/* Handle angles with no tangent. */ |
|||
if (y == -1) return -2 * a(1) /* -pi/2 */ |
|||
if (y == 1) return 2 * a(1) /* pi/2 */ |
|||
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */ |
|||
return a(y / sqrt(1 - y * y)) |
|||
} |
|||
/* x(x) = arccosine of x, domain [-1, 1], range [0, pi] */ |
|||
define x(x) { |
|||
auto a |
|||
/* Handle angle with no tangent. */ |
|||
if (x == 0) return 2 * a(1) /* pi/2 */ |
|||
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */ |
|||
a = a(sqrt(1 - x * x) / x) |
|||
if (a < 0) { |
|||
return a + 4 * a(1) /* add pi */ |
|||
} else { |
|||
return a |
|||
} |
|||
} |
|||
scale = 50 |
|||
p = 4 * a(1) /* pi */ |
|||
d = p / 180 /* one degree in radians */ |
|||
"Using radians: |
|||
" |
|||
" sin(-pi / 6) = "; s(-p / 6) |
|||
" cos(3 * pi / 4) = "; c(3 * p / 4) |
|||
" tan(pi / 3) = "; t(p / 3) |
|||
" asin(-1 / 2) = "; y(-1 / 2) |
|||
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2) |
|||
" atan(sqrt(3)) = "; a(sqrt(3)) |
|||
"Using degrees: |
|||
" |
|||
" sin(-30) = "; s(-30 * d) |
|||
" cos(135) = "; c(135 * d) |
|||
" tan(60) = "; t(60 * d) |
|||
" asin(-1 / 2) = "; y(-1 / 2) / d |
|||
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2) / d |
|||
" atan(sqrt(3)) = "; a(sqrt(3)) / d |
|||
quit</lang> |
|||
Output: <pre>Using radians: |
|||
sin(-pi / 6) = -.49999999999999999999999999999999999999999999999999 |
|||
cos(3 * pi / 4) = -.70710678118654752440084436210484903928483593768845 |
|||
tan(pi / 3) = 1.73205080756887729352744634150587236694280525381032 |
|||
asin(-1 / 2) = -.52359877559829887307710723054658381403286156656251 |
|||
acos(-sqrt(2) / 2) = 2.35619449019234492884698253745962716314787704953131 |
|||
atan(sqrt(3)) = 1.04719755119659774615421446109316762806572313312503 |
|||
Using degrees: |
|||
sin(-30) = -.49999999999999999999999999999999999999999999999981 |
|||
cos(135) = -.70710678118654752440084436210484903928483593768778 |
|||
tan(60) = 1.73205080756887729352744634150587236694280525380865 |
|||
asin(-1 / 2) = -30.00000000000000000000000000000000000000000000001203 |
|||
acos(-sqrt(2) / 2) = 135.00000000000000000000000000000000000000000000005500 |
|||
atan(sqrt(3)) = 60.00000000000000000000000000000000000000000000002463</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |