Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default Math.atan(double a) is not accurate.

    EDIT!!!!

    Silly me, I forgot that 5's and 10's were int. PLEASE DISREGARD for I FOUND OUT!

    double in = 5/5;
    double degrees = Math.toDegrees(Math.atan(in));

    double in = 10/5;
    double degrees = Math.toDegrees(Math.atan(in));

    All numbers for "in" between 1 and 2 generated the exact same 45 degrees.
    Without the Math.toDegrees(), it still generates .7xxxxxx (radian version :P);

    My question is, why? I really don't see anything wrong, but this is the first time I use atan (normally I'd use sines and cosines);

    halp.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Math.atan(double a) is not accurate.

    Run this program to see what is wrong:

    Java Code:
    public class Foo {
       public static void main(String[] args) {
          double in = 5/5;
          System.out.println("in: " + in);
          
          in = 10 / 5;
          System.out.println("in: " + in);
          
          // so far so good, right?
          
          in = 3 / 5;
          System.out.println("in: " + in);
          // now the output is not so good.
          
          // what about...
          
          in = 3.0 / 5;
          System.out.println("in: " + in);
          // ah, that's better!
       }
    }
    Then Google Java int division to see why you're seeing the results above.

Similar Threads

  1. more accurate average of array data
    By jwl in forum New To Java
    Replies: 2
    Last Post: 10-28-2012, 10:14 PM
  2. Math.atan --- To Degrees Help
    By GregoryNeal in forum New To Java
    Replies: 1
    Last Post: 03-07-2012, 06:54 AM
  3. Stimulsoft Reports.Fx. Convenient, Fast, Accurate.
    By Andrew1000 in forum Java Software
    Replies: 0
    Last Post: 09-20-2011, 12:12 PM
  4. keep double accurate to two decimal places
    By africanhacker in forum New To Java
    Replies: 5
    Last Post: 03-24-2011, 06:23 PM
  5. is Math.pow only used with type double?
    By AprilFlowers in forum New To Java
    Replies: 9
    Last Post: 10-23-2009, 04:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •