• 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

problems with Math.tan

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code:

Gives the following output:

degrees = 72.0
tanDegrees = -0.26241737750193517


While my calculator returns something different:

3.077683537


What am I doing wrong in the Java source?
[ January 10, 2004: Message edited by: Kevin de Berk ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're assuming that the tan funtion uses degrees. It doesn't - the API says it uses radians (pi=3.1419... radians equals 180 degrees). Most calculators have several possible modes - a "DRG" button toggles between degrees mode, radians mode, and grad mode (which has 100 grads in a 90 degree angle; seldom used). Your calculator is currently in degrees mode. Java's Math class doesn't have these modes; it always uses radians because that's the most mathematically natural mode to use. (Computations are actually simplest for the computer this way.) But you can use the toDegrees() and toRadians() methods to convert between radians and degrees.
 
Kevin de Berk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh..
Well, thanks mate
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic