[futurebasic] Re: [FB] Problem with FIXED type variables.

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2010 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Tue, 13 Apr 2010 08:41:23 +1200
Stu Cram wrote:

> I'm experiencing troubles using the FIXED data type.
> (OS 10.5.8;  MacBook;  Intel;  FB 5.4.5 0; FB2C 1.4.5)
> 
> According to the Help section:
> II.2.1 Fixed-point Reals
> A fixed-point real number variable must be declared in a dim statement, using the as Fixed clause. It's accurate to about 5 places past the decimal point, and can handle numbers in the range of approximately -32767.99998 through +32767.99998. A fixed-point variable occupies 4 bytes of storage.
> 
> However, this short program seems to indicate that the FIXED variables now are being treated as integers.   :-(
> [snip]
> Am I misunderstanding the type FIXED or is the a new bug in FB5/FB2C?  
> I thought this would a month or so ago when I last tried this and other examples.

It could never have worked. As a check, I tried your demo in FB4 and the results are the same. 

To work with Fixed variables you have to convert decimal forms on input/output and use FixXxxxx() functions for math operations other than addition and subtraction. 

// FixMath.h
toolbox fn FixRatio( short numer, short denom ) = Fixed
toolbox fn FixRound( Fixed x ) = short
toolbox fn Long2Fix( long x ) = Fixed
toolbox fn Fix2Long( Fixed x ) = long
toolbox fn FixDiv( Fixed x, Fixed y ) = Fixed
toolbox fn FixMul( Fixed a, Fixed b ) = Fixed
toolbox fn FixATan2( long x, long y ) = Fixed

For general programming, the Fixed type became redundant when processors got hardware floating-point.

Robert P.