Trig

Trig functions

#! /usr/bin/bc -l
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 a
         if (x == 0) return 2 * a(1)  /* pi/2 */
        a = a(sqrt(1 - x * x) / x)
        if (a < 0) {
                return a + 4 * a(1)  /* add pi */
        } else {
                return a
        }
}
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

Unknown's avatar

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
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment