reature request: fixed point

Walter Bright newshound1 at digitalmars.com
Sat Mar 1 18:28:23 PST 2008


kov_serg wrote:
> Is it possible to add to "Basic Data Types" one more type?
> 
> fixed point type is intermediate type between fload and integer. Build in support of fixed point type will great help in realtime signal and image processing. 32 bit fixed point with 16bit for integer part and 16 bit of fraction is very easy implemented on any 32bit CPU and have good performance. Especially if CPU has no FPU.
> 
> fixed x; // 32bit min=-0x8000.0000 max=0x7FFF.FFFF
> ...
> fixed a=3.14, b=2.3, c=-5.3;
> fixed d=a*b/c;
> 
> What you think about including "fixed" type in D 2.0?

It isn't too hard to do fixed point arithmetic:

typedef int Fixed;
Fixed fixed(int m, int n) { return cast(Fixed)(m * 0x10000 + n); }

Fixed a = fixed(3,14);
Fixed b = fixed(2,3);
Fixed c = -fixed(5,3);
Fixed d = a * b / c;



More information about the Digitalmars-d mailing list