reature request: fixed point
Bill Baxter
dnewsgroup at billbaxter.com
Sat Mar 1 13:50:16 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?
What about 24.8 format? Cairo just switched to this for instance. Or
those based off short or long.
There are too many potential flavors.
More constructive would probably be to list things that a "struct fixed
{...}" currently can't do that are necessary to make it seem like a
built-in. All the things you showed in your example are possible now.
struct fixed
{
static fixed opCall(double x) {
fixed R; with(R) {
/* repr = convert x to fixed */
} return R;
}
fixed opMul(fixed x) { /* return repr * x */ }
fixed opDiv(fixed x) { /* return repr / x */ }
int repr;
}
--bb
More information about the Digitalmars-d
mailing list