I used the following sketch as baseline for testing math functions:
void setup(){
pinMode(13, OUTPUT);
Serial.begin(115200);
}
int v;
#include <MemoryFree.h>
void loop(){
v = analogRead(A0);
Serial.println(v);
v = freeMemory();
Serial.println(v);
delay(1000);
}
This basic sketch compiles to 2714 bytes and the freeMemory function returns 810 bytes. I called various functions from the math library one by one using the following pattern:
Serial.println(function(v)). The compiled size of each sketch increased by between 1670 bytes when calling
atan(v) & 2310 bytes when calling
pow(v, 0.123); the free memory dropped to 808 bytes but stayed constant no matter which function was called. Other function calls such as sin, cos, tan, log, log10, exp etc. added code that fell between these two extremes. Finally I made a sketch that calls all the functions mentioned in the online math page:
void setup(){
pinMode(13, OUTPUT);
Serial.begin(115200);
}
int v;
double x, y;
#include <MemoryFree.h>
void loop(){
v = analogRead(A0);
Serial.println(v);
x = (double)v / 234;
y = 0.123;
Serial.println(x,8);
Serial.println(cos(x), 8);
Serial.println(fabs(x), 8);
Serial.println(fmod(x, y), 8);
Serial.println(modf(x, &y), 8);
Serial.println(sin(x), 8);
Serial.println(sqrt(x), 8);
Serial.println(tan(x), 8);
Serial.println(exp(x), 8);
Serial.println(atan(x), 8);
Serial.println(atan2(x, 0.1), 8);
Serial.println(log(x), 8);
Serial.println(log10(x), 8);
Serial.println(pow(x, 0.123), 8);
Serial.println(square(x), 8);
v = freeMemory();
Serial.println(v);
delay(10000);
}
This sketch compiled to 6428 bytes and the free memory reported was 800 bytes. Clearly there is sufficient flash memory and SRAM available on the Atmega8 chip to call some math functions and still have enough resources to do other stuff like read an analog pin and send data over the serial port.