lesto:
just a little problem (arduino IDE 1.0.1):halfPI = PI / 2;give some error with overloaded constructor. I've work around it because I'm not good with c++
Try:
halfPI = bigPI / BigNumber (2);
You can probably cut down the precision of bigPI - that uses RAM and you are hardly going to need all those digits.
execution time (microseconds, precision of 5): 142256 vs 116(using float)
Yes, I didn't say it was fast. ![]()
Arbitrary precision libraries tend to be slow by their nature.
Some of your stuff is inefficient:
BigNumber negate = BigNumber(x < 0);
if (x < 0){
x*=-1;
}
Why multiply when you can negate?
BigNumber acosine(BigNumber x) {
boolean negate = false;
if (x.isNegative ())
{
x -= x;
negate = true;
}
BigNumber ret = -0.0187293;
ret *= x;
ret += 0.0742610;
ret *= x;
ret -= 0.2121144;
ret *= x;
ret += 1.5707288;
BigNumber bigSqrt = x - BigNumber (1);
ret *= bigSqrt.sqrt();
ret -= 2 * ret;
if (negate)
return - bigPI - ret;
else
return bigPI + ret;
}
Try to keep multiplications down. Subtracting a number from 0 will be faster than multiplying by -1. Also I don't know why you were working on x as a float. Doesn't that throw away the extra precision? I haven't tested the changes, but they show what I had in mind.