Thread: A faster way to calculate sine function?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    100

    A faster way to calculate sine function?

    I remember reading an interesting article about some guy who made up a new algorithm for calculating approximate values of the sine function, which I found out to be at least 30%-40% faster than the one used in math.h. Unfortunately I lost the code where I used this algorithm and now that I've spent several hours searching for it over the 'net, it feels like it just vanished somewhere...
    So... does anyone happen to know what am I talking about or has a link to that article? I'm sure I'm not the only one who has read it, and I'd really appreciate it if anyone could either give me a link to that page or the algorithm itself
    Sauron a few seconds before his defeat:
    "What? A 'division by 0' error?!?"

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    here's a little place full of code: http://www.frees3x.org
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    100
    and you think I haven't searched google already?
    Sauron a few seconds before his defeat:
    "What? A 'division by 0' error?!?"

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    For small values of x,
    sin x ~= x
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    100
    true if they're out of the variable's accuracy range
    Sauron a few seconds before his defeat:
    "What? A 'division by 0' error?!?"

  6. #6
    Registered User big146's Avatar
    Join Date
    Apr 2003
    Posts
    74
    Take a look at this....hope it helps
    Code:
    //The code below calculates the cosine of 50000000 random values
    //using both a look up table, which is calculated at the beginning
    //of the program, and using the normal cos function during runtime.
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
    	//Declare look up table
    	double COSTable[360]; //360 elements for all angles between 0 and 359.
    	int Number;
    
    	//Calculate look up table
    	cout << "Calculating Cosine look up table..." << endl;
    
    	for(Number = 0; Number < 360; Number++)
    	{
    		COSTable[Number] = cos(Number * 3.14159 / 180);
    	}
    
    	//Calculate Cosine of 50000000 values using look up table
    	// and then using cos.
    	cout << "Calculating cosine of 50000000 random values using look"
    	     << " up table..." << endl;
    
    		 //Look up table
    		 for(Number = 0; Number < 50000000; Number++)
    		 {
    			 COSTable[rand() % 360];
    		 }
    
    		 cout << "Complete..." << endl;
    
    		 cout << "Calculating cosine of 50000000 random values using cos"
    		      << " function..." << endl;
    
    			  //cos function
    			  for(Number = 0; Number < 50000000; Number++)
    			  {
    				  cos(double(rand() % 360));
    			  }
    		 
    			  cout << "Complete..." << endl;
    
    			  return 0;
    }
    Last edited by big146; 11-06-2004 at 12:36 PM.
    big146

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    100
    Interesting solution
    It's not exactly what I was looking for, but I do agree that it's a pretty nice way to speed up things if you're dealing a lot with exact degree values. I'll keep that in mind
    Sauron a few seconds before his defeat:
    "What? A 'division by 0' error?!?"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM