A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: how many decimal places are enough for sin, cos

  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    34

    Question how many decimal places are enough for sin, cos

    I am making game and I need to move MovieClips around with

    x += speed * cos( angle );
    y += speed * sin( angle );

    Instead of calling cos() and sin() functions, which is too slow, I'll use sin and cos table.

    So I wonder if anyone knows what's optimal number of decimal places for sin values. Five, seven, twelve, more...?

  2. #2
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    I really don't think you'll notice any speed increase by using a sin/cos table instead of using the Math.sin and Math.cos functions. If you're using one anyway though, I would think that 5 decimal places would be enough. Some games use 3.14 for pi and it's not really noticeable.

  3. #3
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    Ive benchmarked it in the past and lookup tables are slower than calling the actual functions.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  4. #4
    Member
    Join Date
    Jun 2008
    Posts
    34
    My table is 1 second faster than Math.sin... per million lops.
    And it has 15 decimal places.

    Well maybe it's a bug in Flash CS and AS3...

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