[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> OK, two patches attached. One implements the above two methods and their
> documentation, the other adds two methods to the 'fix' class to do much
> the same thing (depending on the C implementations, of course).
+AL_INLINE(fixed, radtofix, (double x),
+{
+ /* the constant comes from the 16.16 representation of 256/2pi */
+ return fixmul(ftofix(x), (fixed)2670177) & 0xFFFF;
+})
+
+
+AL_INLINE(double, fixtorad, (fixed x),
+{
+ /* the constant comes from the 16.16 representation of 2pi/256 */
+ return fixtof(fixmul(x & 0xFFFF, (fixed)1608));
+})
Why to use 'double' instead of 'float' ? ftofix() and fixtof() both use floats.
Moreover, I think taking a look at the actual implementation of fixmul()
could be worth while...
+ double fixtorad() const { return fixtorad(v); }
Simply rad(), no ? r = f.rad();
+ static fix radtofix(double x) { fix t; t.v = radtofix(x); return t; }
Why not from_rad() ? fix f = fix::from_rad(r);
And I think { return fix(radtofix(x)); } is better.
> It should provide more of a reminder that radians don't directly convert
> to fixed point values, which is perhaps more important than any
> convenience factors.
That's my point of view too.
- Eric