SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
Quick note I'd like to add to this. Most likely the provided functions in the arduino core library are just directly inherited from avr-libc. I have to look at the sources, but I doubt they would reinvent the wheel. If that is the case, please look at the following link, specifically at the time it takes to execute these functions in your AVR chip. ... marks.html

If your application is timing critical, a lookup table may be the best method. As an example, sin(1.2345) will take 1653 / (16 MHz) = 103.3125 microseconds to execute. Using a lookup table not only may reduce the time it takes for the function to execute, it may even make your memory (both flash and RAM) footprint smaller.
By thefatmoop
ohh duhh... i didn't look to see if one was included

haha 103 microseconds per calculation wow! i guess it's going to take some major code tweaking to get about 4 sig figs on an integration

for what it's worth here's the code for c++ using the rectangle method to approx an integration
Code: Select all
double f(double x){

	return sin(x)/x;


double integrate(double a,double b,int N){
     double dx = (b - a) / N;//delta x, not instantaneous
	 double sum = 0;

	 for(int iter = 1; iter < N; iter++){
	     double x = a + iter*dx;
		 sum += f(x);
     return sum*dx;

double integrateFull(double a, double b){
	double area1 = integrate(a,b,1);
	double area2 = integrate(a,b,2);
	int N=2;

	while(fabs(area1 - area2)> .00001){
		area1 = area2;
		area2 = integrate(a,b,N);
	cout << "\nN is:"<<N<<endl;
	return area2;
to verify code is working: