Re: [AD] a fix struct for dallegro

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2007-04-16, Chris Robinson <chris.kcat@xxxxxxxxxx> wrote:
> On Monday 16 April 2007 08:13:30 am torhus@xxxxxxxxxx wrote:
> > I could simply remove the floating point overloads of the operators.  So
> > the only interaction between fixed and floats would be this:
> >
> > fix(2.5);       // static opCall, wraps ftofix()
> > fix f = 2.5;    // same function as above is called here
> > double d = f.toDouble();  // wrapper for fixtof()
> >
> > f + 2.5;       // error, no opAdd(double)
> > f + fix(2.5);  // ok
> > f = 2.5;       // error, no opAssign(double)
> > f = fix(2.5);  // ok
> >
> > etc.
> >
> > Does this match your idea of explicit?
> 
> Then what does that gain over the fixed type and its functions?

Can you overload the standard operators if you don't use a fixed struct?
Remember we still want fixed and int to be separate types.

> Basically what I'm trying to avoid is something like this:
> 
> // Original:
> float f = M_PI;
> f /= 2.0;
> // f is now quarter circle in radians
> 
> // Decides to use fixed
> fix f = fix(M_PI);
> f /= fix(2.0);
> // f is now quarter circle, but fixed doesn't use radians. Expect problems!

The problem here is not float vs fixed but between different angle
representations.  Who says I don't want radians stored as fixed point
values?  If you wanted type safety you should make new types:

    typedef float radians;
    typedef fixed binary_angle;

(that's supposed to be D code)

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/