[AD] small bugfix for the fix class (2nd trial) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Once again I will report the small bug in the fixed class when 'int' is
divided by 'fix'. Here's a sample for the case I mean:
#include <allegro.h>
#include <iostream>
main()
{
fix a(3);
int b;
b = 9/a;
cout << b;
}
The attached diff is made from alinline.h cvs-version 1.8. (Think my last
diff had the wrong direction. The new one has diff's -Nru format, and because
the old one is still not applied, better take the new one. The bugfix is the
same)
Then I'm really a little bit unlucky with the rounding feature of
fixtoi/fixtof. I had an application where this feature broke an array
boundary. Well, it is described in the docs, but you don't really expect it.
A float isn't rounded too when it is converted to an int. Surely, you can use
the shift (but not with the fix-wrapper), but IMHO the rounding function
should be optional and extra available, i.e. as itofixr. Because some other
definitions back to 3.12 are broken that's now perhaps the latest time to
discuss this (same with ftofix). I know that in case of a change some sources
must be checked...
Thanks
Andy
--- alinline.old Tue Jan 23 00:17:14 2001
+++ alinline.h Tue Jan 23 00:30:32 2001
@@ -1020,9 +1020,9 @@
inline friend fix operator / (const fix x, const fix y) { fix t; t.v = fdiv(x.v, y.v); return t; }
inline friend fix operator / (const fix x, const int y) { fix t; t.v = x.v / y; return t; }
- inline friend fix operator / (const int x, const fix y) { fix t; t.v = x / fixtoi(y.v); return t; }
+ inline friend fix operator / (const int x, const fix y) { fix t; t.v = fdiv(itofix(x), y.v); return t; }
inline friend fix operator / (const fix x, const long y) { fix t; t.v = x.v / y; return t; }
- inline friend fix operator / (const long x, const fix y) { fix t; t.v = x / fixtoi(y.v); return t; }
+ inline friend fix operator / (const long x, const fix y) { fix t; t.v = fdiv(itofix(x), y.v); return t; }
inline friend fix operator / (const fix x, const float y) { fix t; t.v = ftofix(fixtof(x.v) / y); return t; }
inline friend fix operator / (const float x, const fix y) { fix t; t.v = ftofix(x / fixtof(y.v)); return t; }
inline friend fix operator / (const fix x, const double y) { fix t; t.v = ftofix(fixtof(x.v) / y); return t; }