[AD] fixdiv implementation |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hello, this is in response to that bug report from a couple of days ago. I've made one that relies on the existence of a 64 bit long type but otherwise needs no FPU code. I wrapped it in some preprocessor directives as a result. This is the same situation as is with fixmul, so I figured it'd be fine. I guess eventually someone should make 32 bit only implementations, but this is better than nothing.
diff file attached.
SiegeLord
Index: fmaths.inl
===================================================================
--- fmaths.inl (revision 10260)
+++ fmaths.inl (working copy)
@@ -143,7 +143,7 @@
})
#endif /* fixmul() C implementations */
-
+#if (defined ALLEGRO_I386) || (!defined LONG_LONG)
AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
{
if (y == 0) {
@@ -153,8 +153,30 @@
else
return ftofix(fixtof(x) / fixtof(y));
})
+#else
+AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
+{
+ LONG_LONG lres = x;
+ if (y == 0) {
+ *allegro_errno = ERANGE;
+ return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
+ }
+ lres <<= 16;
+ lres /= y;
+ if (lres > 0x7FFFFFFF) {
+ *allegro_errno = ERANGE;
+ return 0x7FFFFFFF;
+ }
+ else if (lres < -0x7FFFFFFF) {
+ *allegro_errno = ERANGE;
+ return 0x80000000;
+ }
+ else {
+ return (fixed)(lres);
+ }
+})
+#endif /* fixmul() C implementations */
-
AL_INLINE(int, fixfloor, (fixed x),
{
/* (x >> 16) is not portable */