A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: simple trig help

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Location
    kent, uk
    Posts
    20

    Question simple trig help

    The following code is driving me mad why is my trace cos value not zero but -1.836909530733566e-16 please im going out of my head checked it on 2 calculators gives 0 which is correct please help cheers.

    var a:Number=(270*Math.PI)/180;

    var xx:Number=Math.cos(a);
    var yy:Number=Math.sin(a);

    trace("cos x = "+xx); // why is this value not zero
    trace("sin y = "+yy); // this is correct displaying -1

  2. #2
    It's just a rounding error. The number that it is outputting is very close to zero. This has to do with the way floating point calculations are done in the computer. They can't be exactly correct.

  3. #3
    Senior Member
    Join Date
    Sep 2005
    Location
    Detroit
    Posts
    193
    This seems to be a bug. On the positive side, however, the number it returns is pretty darn close to 0. That's what piqued my interest in this because a lot of my programs rely on cos. This should be reported.
    While the music played you worked by candlelight
    Those san francisco nights
    You were the best in town
    Just by chance you crossed the diamond with the pearl
    You turned it on the world
    That’s when you turned the world around

  4. #4
    Junior Member
    Join Date
    Sep 2007
    Location
    kent, uk
    Posts
    20
    Cheers my friends for the confirmation.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center