Article # 88, added by Geoworks, historical record
| first | previous | index | next | last |

Converting WWFixedAsDword to floating point.




Question:
I need to convert a value that is returned from a GenList
Class (the message is MSG_GEN_GET_VALUE). The value is
returned as a WWFixedAsDWord. I have some code for
converting a WWFixed to FloatNum, but it does not work with
the WWFixedAsDword. Is there any way around this problem?

Answer:
Floating point numbers in Geos follow the Intel IEEE 754
standard. In this format, floating point numbers are 80 bits
(10 bytes) long. In GOC and C, use "long double".

Here is some sample code to convert a WWFixedAsDWord to a
double, and also to the Geos/Intel 80-bit floating point
format:

 WWFixedAsDWord numWWFixed;
 word           intPart;
 word           fracPart;
 double         numIEEE64;
 long double    numGeos80;

 numWWFixed = @call MyGenValue::MSG_GEN_VALUE_GET_VALUE();
   /*
    * Convert WWFixedAsDWord to double.
    */
 intPart = IntegerOf( numWWFixed );
 fracPart = FractionOf( numWWFixed );
 numIEEE64 = (double)intPart + (double)fracPart / 65536;
   /*
    * Now convert it to the Geos 80-bit format.
    */
 FloatIEEE64ToGeos80( &numIEEE64 ); 
   /*
    * The result is pushed on the FP stack.
    */
 FloatPopNumber( &numGeos80 );

For further information on floating point numbers, see the
documentation: Concepts book Appendix D and the header files
float.h and math.h.