File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# tan(90) and sin(90)/cos(90)

Rama Raju
Greenhorn

Joined: Jul 07, 2000
Posts: 12
Hi all,
In Mathematics, we know tan(90) and sin(90)/cos(90) are infinity.
But When I write same in java. I am getting
System.out.println(Math.sin(90)/Math.cos(90)); as -1.9952004122082418
System.out.println(Math.tan(90)) as
1.995200412208242.
Can u please help me?
Suma Narayan
Ranch Hand

Joined: Apr 03, 2000
Posts: 136
Hi Rama,
Yes in pure mathematics tan(90) is infinity and since sin(90) is 1.0000 and cos(90) is 0.0000, the tan(90) is infinity. Consider the following e.g
public class Matharg
{
public static void main(String[] args)
{

System.out.println("Value of tan(0) is " + Math.tan(Math.toRadians(0)));
System.out.println("Value of sin(90) is " + Math.sin(Math.toRadians(90)));
System.out.println("Value of cos(90) is " + Math.cos(Math.toRadians(90)));
System.out.println("Value of sin(90)/cos(90) is " + Math.sin(Math.toRadians(90))/ Math.cos(Math.toRadians(90)));
}
}
All the above functions take the arguments of type double and return double.
If you run this, it gives the following result
Value of tan(0) is 0
Value of sin(90) is 1.0
Value of cos(90) is 6.123233995736766e-17
Value of tan(90) is 1.633123935319537e16
Note the toRadians is used to convert degree to radians as all sin,cos and tan take radian arguments.
The value of cos(90) is not 0.0000 and hence tan(90) is not infinity. In pure Mathematics, the value 6.123233995736766e-17 will be
.000000000000000006123.....If I remember correctly, we consider only 4 decimal places for all trignometric functions and also for Logarithm functions. But in Java since double provides such a wide range of values, cos(90) is not 0.0000 and hence we don't get the same result.
This is what I understand.
I will wait for others to answer this question. May be my understanding is not right.

I agree. Here's the link: http://aspose.com/file-tools

subject: tan(90) and sin(90)/cos(90)