aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes tan(90) and sin(90)/cos(90) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "tan(90) and sin(90)/cos(90)" Watch "tan(90) and sin(90)/cos(90)" New topic

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

Rama Raju

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
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:
subject: tan(90) and sin(90)/cos(90)