The ^ symbol is presumably the exponentiation operator on your calculator.
In C/C++ there is no exponentiation operator. The ^ symbol in C/C++ means the exclusive OR logical operator.
Try this:
Be aware that float has only ~7 significant digits
Unless I'm missing something, you have completely changed the calculations by altering the grouping of terms in a way that will give a completely different result....
RayLivingston:
Unless I'm missing something, you have completely changed the calculations by altering the grouping of terms in a way that will give a completely different result....
Somewhat OT here but just a datapoint for calculator vs arduino.
About 8 months ago I wrote an algebraic parser for the Teensy3/3.1 (both of which have a lot more sram than a Nano/UNO) and one of the things I implemented with it was an integral evaluator which uses Simpson's rule.
My calculator is a Sharp EL-W516X which also uses Simpson's rule to evaluate integrals. I timed how long it took to calculate the integral of sin(x*x) from zero to pi using 100 intervals. It takes 23 seconds.
The same thing on a 96MHz Teensy3 takes 10.6ms and on a 96MHz Teensy3.1 takes 7ms (I think the T3.1 has a bigger cache than the T3 which improves the execution time).
Vaclav:
Your calculator is much smarter than ANY Arduino ever be.
Look up int range and long range.
Also calculator 180^3 = Arduino 180 * 180 * 180
I like to add
By itself the reference to int and long is OK.
In the context of the application I would suggest to use float variables since your constants are floats.
Just to be consistent if for nothing else.
However, there is seldom mentioned / used feature of C called "automatic conversion " which SHOULD take care of variable "mismatch" as just experienced.
But the rules for automatic conversion are pretty specific, and if not followed will make things worse rather than better