• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic