Hi,
I have only been using Arduino for about 2 months and I have not quite worked out the maths stuff yet. There seem to be loads of restrictions on what you can do in terms of maths on it and this is something I have not come across before.

My formula, although not fully tested, is something like this:

Pi = 3.14159
WDist = 12
Deg = 90
IWDist = 5

2Pi2*Dist/(360/Deg)+IWDist

and should output something like 42.69911184

Apart from Pi all of the inputs will be changing.

Am I right in thinking that the Arduino will get confused with these long numbers? If is there a way to make it work? Can I do all this in one line? And should I use any libraries or is the arithmetic in the Arduino sufficient?

Thanks alot for any help. I am loving the Arduino and if I can get this to work I have a great project ahead of me

The Arduino doesn't know anything about PI, or pie, so, you'll need to define it:

const float Pi = 3.14159; // To however many digits you want.

Am I right in thinking that the Arduino will get confused with these long numbers?

No. The Arduino is perfectly capable of this arithmetic. Floating point math is not fast, so if you minimize the number of operations, the calculation will be quicker. There are 3 constants in this equation. They can be replaced with one:

OK thanks. Yes I was going to define Pi. Thanks for simplifying my formula. I thought it was a bit messy somehow but I did not realise it was that bad. I just knocked it up on Excel.

S if I use this formula, how long do you think it would take to calculate? This is part of a driving system for a chassis and if it takes more than say a second it becomes almost pointless.

Also, can I just use it like this?

const float Pi = 3.141593;
int Dist = 12;
int Deg = 90;
int IWDist = 5;
float Result = ((Pi*Dist*Deg)/90.0) + IWDist;

Brilliant thanks BenF! Sorry for doubting you. Copying that to a local text file now.

Thanks for all your help guys,
If you're lucky and I get this working I might be able to share a nice little function for driving a tracked chassis with you all.

Thanks again,
Sam.

PS. This is one of the nicest forums ever. For me the prize is between this and the MediaBrowser forum.

The constant as defined by Arduino for PI is the best representation possible with the double (64-bit) data type. Arduino will only support float (32 bit) for runtime calculations, but this is handled transparently by the compiler.

Actually it is preferred to use double precision for floating point constants also in Arduino. This is because the compiler as such will use double precision for its compile time math and any math expressions that can be evaluated at compile time will benefit from the extra precision.

Thanks. Makes sense now. I don't even need it that accurate anyway because it is just steering a chassis but thanks for all the input. As I said earlier hopefully I can share something with you guys when this is done.

This is because the compiler as such will use double precision for its compile time math and any math expressions that can be evaluated at compile time will benefit from the extra precision.

Very good point, but all those extra 'useless' digits are a bit excessive