Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh93 math library functions 2

Status
Not open for further replies.
May 3, 2002
633
0
0
US
Has anyone used ksh93 to access the math library functions (math.h) such as, tangent, sine, cosine..., and give an example of how to do it.

The documentation on the kornshell.com website says that it you can do this, but has no examples of how to do it.

Below it mentions typeset -F but again no examples of how to get to exponent of a number or to figure cosines.
 
Hi:

You're right about the dtksh documentation. It is rather slim and skimpy. I found a comment in Bolsky's book "The New KornShell" that all arguments to the trig functions are in radians - not degrees.

Remembering high school trig, one degree = PI/180:

#!/usr/dt/bin/dtksh
radian=$((3.1416 / 180 ))

echo "sin 0: "$((sin(0 * radian)))
echo "cos 10: "$((cos(10 * radian)))
echo "cos 30: "$((cos(30 * radian)))
echo "sin 30: "$((sin(30 * radian)))
echo "sin 45: "$((sin(45 * radian)))
echo "tan 45: "$((tan(45.0 * radian)))
echo "sin 1: "$((sin(1 * radian)))

output is:

sin 0: 0
cos 10: 0.98480768214
cos 30: 0.866024791583
sin 30: 0.500001060362
sin 45: 0.707108079858
tan 45: 1.00000367321
sin 1: 0.0174524472444

As far as exponents, there is a logrithmic function, so I guess you can use that to do exponent arithmetic.

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top