reature request: fixed point

kov_serg kov_serg at freemail.ru
Sat Mar 1 14:24:25 PST 2008


Bill Baxter Wrote:

...
> 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
I have no idea how to implement fixed type effective in D. But it very simple in assembler code. So why not to include this type to buildin type. It simple, it fast, it usefull.
For example for fixed 16.16 and 24.8 operation mul_div will look the same

fixed mul_div(fixed a,fixed b,fixed c) { asm {
  // assume: eax=a, edx=b, ecx=c
  imul edx
  idiv ecx
  // result in eax
}}

Simple thing must be simple
fixed d=a*b/c;
d+=a;
// and so on

I'll be happy to see fixed type in any form buildin or as a library. But I think this type should be.

ps: I fixed 16.16 and 24.8 is the most usefull



More information about the Digitalmars-d mailing list