64 bit Flotingpoint

Powersoft

Member
Hello,
Is there an example how to use the 64 bit floating point, when programming from the Arduino Ide?

Thanks for any help.
Jan
 
I copied your exact message into the phind.com prompt and it returned this: link.
You probably can take it from there.

Paul
I mean... it's not wrong, but if OP is asking about the Teensy 4 that advice isn't particularly useful.

To perform 64-bit math all you have to do is use doubles, e.g.:
Code:
double a = 1.0;
double b = 2.0;
double c = a + b;
 
it's not wrong, but if OP is asking about the Teensy 4 that advice isn't particularly useful.
I didn't see a Teensy 4 reference? To me this was a generic question and as such googling or using some AI is usually a good starting point.

Paul
 
The OP never did mention which board they are interested in using with 64 bit floating point.

And, the simple answer is indeed to just use double. But, to cover things more fully, if you define a floating point constant or literal then putting f on the end makes it a single precision (32bit) floating point number while no f means double (usually).

So, 1.0f is 32 bit and 1.0 is 64 bit.

Also, the Teensy4 can actually do double precision / 64 bit floating point in hardware and at a decent speed. On a Teensy4/4.1/MicroMod there really is usually no good reason not to use doubles for everything. The processor can handle it no problem. On other Arduino boards this ranges from a mildly bad idea to a very, very, very slow idea. Don't use 64 bit doubles on an ATMEGA board unless you've got all the time in the world.
 
On a Teensy4/4.1/MicroMod there really is usually no good reason not to use doubles for everything.
It's (roughly) half as fast as 32-bit floating point and takes up double the memory, so better to not use it unless you need the precision.
 
But the problem for the clientele that tend to use the Arduino IDE is that not using double leads to situations that may bring them outside of their depth. I'm not trying to be condescending either. Everyone has varying levels of knowledge in various domains. No one is an expert in everything.

You have to ask yourself whether you think the average programmer (even in general) understands the implications of the way floating point numbers are represented. Do you know how many mantissa and exponent bits there are in single and double precision floats? I don't without looking it up. So, I still advise people to use double precision if possible and only use something else if there are known reasons for doing something different. For money calculations? Don't use floating point AT ALL. For speed critical things? If you can use single precision and not get messed up then go for it. For memory critical things? Probably need to use single precision and just be careful.

But, the issues with single precision are subtle and can bite without much warning. When those issues happen they can be tough to figure out, especially if you aren't a computer science major and don't know how floating point values are stored. In the old days people used to use fixed point a lot more often (well, people still do in the 8 bit MCU world). This also has computational limits but they're very explicit. I just don't think the limits of single point math are very obvious at all to the average programmer.
 
We don't really have examples programs because using 64 bit double precision floating point is so simple. On Teensy 4.x, just create and use variables with type "double". Float constants will automatically be double. So very easy! Nothing special is needed code-wise (eg, as with Microchip PIC chips) because the compiler automatically uses the FPU. The FPU handles both 32 and 64 bit float in hardware. 32 bit is faster, but not by much. All buses inside the chip are 64 bits wide, so 64 bit double performs quite well.

On Teensy 3.x the usage is the same, but with the minor caveat that constants are 32 bit float. Probably not much of an issue today, since Teensy 3.x has been discontinued for quite some time. Teensy 3.5 and 3.6 had a 32 bit FPU. Teensy 3.2 & LC had no FPU.

Teensy 1.0 & 2.0 (also discontinued) only supported 32 bit float. If you use double, the compiler automatically uses 32 bit float.
 
Back
Top