Re: [AD] ftofix optimisation

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


At 20:46 1999-12-28 +0100, I wrote:

>Here is the code:
>
>fixed ftofix(float f)
>{
>  fixed i;
>  fixed sign;
>  unsigned char shift;
>
>  i = *(fixed*)&f;
>  sign = i >> 31;
>  i &= 0x7FFFFFFF;
>  if (i >= 0x47000000)
>  {
>    *allegro_errno = ERANGE;
>    return 0x7FFFFFFF - sign;
>  }
>  shift = 0x8d - (i >> 23);
>#if you want rounding
>  if (shift > 7)
>    return ((((((i & 0x007FFFFF) | 0x00800000) << 7) + (1 << (shift - 1)))
>>> shift) + sign) ^ sign;
>  else
>#endif
>    return (((((i & 0x007FFFFF) | 0x00800000) << 7) >> shift) + sign) ^ sign;
>}

Oops, this one converts from float, not double. The code for double would
look similar, but not identical. Is there any interest for a double
version? In ithat case I can convert this one.

Erik



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