RoboPro 48-bits float

Hier habt Ihr die Möglichkeit direkt mit dem fischertechnik Team in Kontakt zu treten
Here you have the Possibility to get in direct contact with the fischertechnik-Team

Moderator: fischertechnik Mitarbeiter

Forumsregeln
Bitte beachte die Forumsregeln!

In dieser Unterkategorie können nur fischertechnik-Mitarbeiter und Moderatoren antworten!
Antworten
vleeuwen
Beiträge: 1557
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

RoboPro 48-bits float

Beitrag von vleeuwen » 30 Sep 2019, 10:00

How is the 48-bits float (6 bytes) organized and serialized in the .rpp?

In the RoboPro .rpp (XML) file a float has been saved (serialized) as 3 values (as strings), namely: value0, value1 and value2; each value represent 2 bytes.
This is datatype 11.
But how to come from the value0, value1, value2 to a C# or C/C++ Double type.


From RoboPro help:
The precision of arithmetic operations is 48 bits with a 32 bit mantissa. This corresponds to a precision of slightly more than 9 decimal digits.
So this float is not an old Pascal 48-bits real type, because that has a 40 bits mantissa.
https://stackoverflow.com/questions/319 ... nt-integer
http://www.shikadi.net/moddingwiki/Turbo_Pascal_Real
How is the float organized and how is it serialized in the .rpp?

ROBOProEntwickler
Beiträge: 14
Registriert: 28 Dez 2012, 14:56

Re: RoboPro 48-bits float

Beitrag von ROBOProEntwickler » 21 Okt 2019, 19:29

Modulo swapping the order the value0 is the exponent and the value1 and value2 are the upper and lower half words of the 32 bit mantissa. Unlike IEEE format, this format does not have an implicit one because it does not normalize on subtraction, so that the numbers "know" how precise they are (unlike IEEE numbers which are optimized for maximum precision for people who know what they are doing). Please note that these numbers have a larger exponent range than 64 bit IEEE floats, so it is not always possible to convert them to doubles.

Besides my believe that normalizing floats are not the right thing for kids, the main reason for not using IEEE floats is that originally floats were also intended for the TX, which does have HW floats, but it was then not published for the TX. Maybe in some future I switch to IEEE double interval aritthmeitc - there are some good libraries for this meanwhile.

Here is a snippet from the source code, which defines the underlying C datatype (FL_NAME is a macro which identifies teh specific type, like 48 bit or 64 bit):

Code: Alles auswählen

typedef struct FL_NAME(sFloat)
{
    FL_NAME(tWord) exponent;
    FL_NAME(tWord) mantissa[FL_NAME(nMantissaWords)];
} FL_NAME(tFloat);

enum FL_NAME(eExponent)
{
    FL_NAME(Exponent_Value_Undefined)= 0,
    FL_NAME(Exponent_Value_Nan)      = 1,
    FL_NAME(Exponent_Value_Underflow)= 2,  /* 0 or arithmetic underflow */
    FL_NAME(Exponent_Value_Overflow) = 3,  /* x/0 or arithmetic overflow */
    FL_NAME(Exponent_Value_Lost)     = 4,  /* overflow*underflow or overflow/overflow */
    FL_NAME(Exponent_Value_Min)      = 256,
    FL_NAME(Exponent_Value_Zero)     = (1<<(FL_NAME(nBitsPerWord)-3)),
    FL_NAME(Exponent_Value_Max)      = (1<<(FL_NAME(nBitsPerWord)-2))-256,
    
	FL_NAME(Exponent_Mask_Exp)       = (1<<(FL_NAME(nBitsPerWord)-2))-1,

    FL_NAME(Exponent_Flag_Exact)     = (1<<(FL_NAME(nBitsPerWord)-2)),
    FL_NAME(Exponent_Flag_Minus)     = (1<<(FL_NAME(nBitsPerWord)-1))
};

Antworten