Trig functions
#! /usr/bin/bc -lq
define t(x) {
return s(x) / c(x)
}
define y(y) {
if (y == -1) return -2 * a(1) /* -pi/2 */
if (y == 1) return 2 * a(1) /* pi/2 */
return a(y / sqrt(1 - y * y))
}
define x(x) {
auto angle
if (x == 0) return 2 * a(1) /* pi/2 */
angle = a(sqrt(1 - x * x) / x)
if (x < 0) return angle + 4 * a(1)
return angle
}
p = 4 * a(1) /* pi */
d = p / 180 /* one degree in radians */
print "Using radians:\n"
"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))
print "\n\nUsing degrees:\n"
"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

About Linuxgal
Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu