Mason Watmough
Mason Watmough

Reputation: 495

How to get specifics of floating point type C/C++

I am developing a program for a couple of rather poorly documented MCUs. So far, the most pressing problem is that I have to get all of these MCUs to constantly communicate (send/recieve) floating-point data, and I have no idea exactly what the specifications are for the floating point types. In other words, I cannot make sure that one floating point type will have the same value if I send it along a serial/parallel connection to another MCU. Everywhere I have looked does not give me specifics for how they handle them (precision, mantissa, location of sign bit, etc...)

I have the standard fixed point integer types like int and long figured out; this applies explicitly to floating point types like float and double.

The worst part is that I do not have access to the standard library for every MCU. That means I cannot use std::numeric_limits or other stuff like that.

As a last resort, I can create my own struct, class, or other type and use some well-placed logic operators to get each data type to do what I want, but this is ultimately undesirable for my project. The same goes for trial-and-error of what the bit structure of every floating point type is for every MCU.

So, is it possible to not only see the specifics of the floating point types, but also possibly change them if they don't follow the standard? Or, is it as simple as "You need to get a better MCU"?

EDIT #1:

As I have recently tested my 12 MCUs, only 5 of them support IEEE standard for single and double precision. The other seven all use unique formats for both single and double precision.

EDIT #2:

As suggested, I ran Kahan's Paranoia Test Script, suggested by Simon Byrne:

You could try running Kahan's paranoia test script, which is available in several different languages from Netlib. This tries to figure out the floating point characteristics by test computations.

This worked well for two of my MCUs. The remaining five do not have enough memory to run the test. However, the two I did manage to decode have extremely weird ways of handling the sign bit and endianess, and I'll have to look into some weird logical operations so as to make a foolproof compatibility layer.

Upvotes: 0

Views: 135

Answers (1)

Simon Byrne
Simon Byrne

Reputation: 7874

You could try running Kahan's paranoia test script, which is available in several different languages from Netlib. This tries to figure out the floating point characteristics by test computations.

Upvotes: 2

Related Questions