[AD] [ alleg-Bugs-1650580 ] Problem in fixed point library.

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


Bugs item #1650580, was opened at 2007-02-02 13:15
Message generated for change (Comment added) made by snam_34
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1650580&group_id=5665

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core Library
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: mans (snam_34)
Assigned to: Nobody/Anonymous (nobody)
Summary: Problem in fixed point library.

Initial Comment:
Hello,
    I am interested to use fixed point section of library and I found a mistake in it:

if you look for fixdiv which is fixed division, it is implimented using floating point division: Here is the code:

AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
{
   if (y == 0) {
      *allegro_errno = ERANGE;
      return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
   }
   else
      return ftofix(fixtof(x) / fixtof(y));
})

as you can see after, checking for range, X and Y converted to floating points and divided in that way. This is in contrast of using fixed arithmatics.

I think we need to extend this so it uses fixed point arithmatic instead of floating point.

Regards
ps: Is there any other fixed point library that I can look and possible use?


----------------------------------------------------------------------

>Comment By: mans (snam_34)
Date: 2007-02-02 16:27

Message:
Logged In: YES 
user_id=1708717
Originator: YES

Hello
   The patch Elias gave, seems doesn't work properly but the following one
is working.

fixed fixdiv(fixed x, fixed y)
{
	if (y == 0) {
		allegro_errno = ERANGE;
		return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
	}
	else
	{
		return ((LONG_LONG)x<<16)/(LONG_LONG)y;
	}	

		//return ftofix(fixtof(x) / fixtof(y));
}

Regards


----------------------------------------------------------------------

Comment By: Elias Pschernig (elias)
Date: 2007-02-02 13:58

Message:
Logged In: YES 
user_id=32894
Originator: NO

Well, for platform where someone submitted a patch, we have optimized
assembler version of fixdiv. But you're right, the generic C version indeed
seems to use float. Anyway, how hard can it be writing a replacement which
does not use float?

Try something like:

AL_INLINE(fixed, fixdiv, (fixed x, fixed y),
{
   if (y == 0) {
      *allegro_errno = ERANGE;
      return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
   }
   return itofix(x / y) + itofix(x % y) / y;
})


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105665&aid=1650580&group_id=5665




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