# How to manipulate small numbers with higher precision than a float?

So I am using an arduino in an application which requires finding the value of 6th degree polynomial at various positions where the coefficients of the polynomial ideally would have at least 8 decimal points of precision. I have actually found around doing this calculation on the arduino as my system includes a raspberry pi running a python script which it is communicating to anyway. So I can just do the calculation on the pi and send it back to the arduino.

However if if I didn't have the pi, can anyone suggest what the best way of representing a number and doing calculations, with higher degrees of precision than float can provide?

I'm assuming it would be possibly to define your own data type and write methods and functions to perform basic arithmetic operations upon it on an arduino, but is there possibly any libraries which already exist to do this? Or would I literally have to write something like this from scratch?

You can look at the big number library.

For 8 digits of precision use long or unsigned long. That gets you 9 places. Think in terms of fixed point math.

genericpurpleturtle: So I am using an arduino in an application which requires finding the value of 6th degree polynomial at various positions where the coefficients of the polynomial ideally would have at least 8 decimal points of precision. I have actually found around doing this calculation on the arduino as my system includes a raspberry pi running a python script which it is communicating to anyway. So I can just do the calculation on the pi and send it back to the arduino.

However if if I didn't have the pi, can anyone suggest what the best way of representing a number and doing calculations, with higher degrees of precision than float can provide?

The Arduino DUE platform is ARM based 32-bit and supports 64-bit "double" number format for double precision floating point numbers.

I think ESP8266 also supports 8-byte double floats.

If the coefficients of your polynomial are fractions, you might be able to write functions that work with 'numbers' expressed as a long long (64 bit) denominator and numerator, and perhaps a separate sign bit. Getting a greatest common divisor of two numbers is a well-known and fast algorithm.

You can use C++ operator overloading to do this as classes that "look" like regular numbers in code.