[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 (Settings changed) made by elias
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: Closed
>Resolution: Invalid
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: Elias Pschernig (elias)
Date: 2007-02-04 14:32

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

On the mailing list I was notified about a discussion about this:
http://www.allegro.cc/forums/thread/488085

So apparently, the float version is faster, and therefore there is no good
reason not to use float - at least I can't see one. The result has to be
fixed point, and how to obtain the result should be in the fastest possible
way.

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

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/