[futurebasic] Re: Floating point question [FB^3]

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: Robert Cogburn <rcogburn@...>
Date: Thu, 23 Sep 1999 00:05:46 -0600
>I am a little confused about the format of floating point numbers in FB^3. 
>Are the floating point values defined with the "#" symbol extended presision 
>(10 bytes per number) or double presision (8 bytes per number)? 
>Are single precision floating point numbers 4 bytes per number or 8 bytes 
>number? This quote from the conversions manual seems to imply that they 
>are 8 
>bytes but that seems wrong to me: "When saving single precision floats, both 
>PPC and SANE (but not FutureBASIC II) use the same 8 byte structure and 
>may be saved as numeric values."
>If floating point values defined with the "#" symbol are extended precision 
>with 10 bytes per number is it posible to convert them to the 8 byte per 
>number double precision format? If not is it posible to still use the 
>SaneCalls.INCL file from FB2 to convert between different kinds of floating 
>point numbers, even though the SaneCalls.INCL file seem to be written in 68K 
>assembly? (I need the double precision numbers because they are required in 
>the format of a file my program creates for use by another program.)

You can check variable sizes with SIZEOF, as in the following:

DIM a!,b#

The results are

 4               10                in 68K compile
 4               8                  in PPC compile

so single precision FPs are 4 bytes in either case. Doubles are 8 bytes 
in PPC - always - but are stored as extended precision (10 bytes) in 68K. 
There is one other tricky thing: if you have the Align variables option 
on then the address of b# may be 8 bytes beyond the address of a! in the 
PPC compile because doubles are placed on double long (multiples of 8) 

For most purposes the best way to convert extended data from 68K to the 
PPC double format is to store the values from the 68K program as text in 
a file then convert the text to floats in your PPC program, using STR$ 
and VAL. This came up early in the beta testing and, as Staz pointed out, 
this approach is very fast. In the Examples:Neat Apps there is a project 
providing functions for direct conversion of BCD to PPC format.