doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

m_fixed.c (551B)


      1 #include <limits.h>
      2 
      3 #include "stdlib.h"
      4 #include "doomdef.h"
      5 #include "i_system.h"
      6 #include "m_fixed.h"
      7 
      8 fixed_t
      9 FixedMul(fixed_t a, fixed_t b)
     10 {
     11     return ((long)a * (long)b) >> FRACBITS;
     12 }
     13 
     14 fixed_t
     15 FixedDiv(fixed_t a, fixed_t b)
     16 {
     17     if ((abs(a) >> 14) >= abs(b)) return (a^b)<0 ? INT_MIN : INT_MAX;
     18     return FixedDiv2 (a,b);
     19 }
     20 
     21 fixed_t
     22 FixedDiv2(fixed_t a, fixed_t b)
     23 {
     24     double c;
     25 
     26     c = ((double)a) / ((double)b) * FRACUNIT;
     27     if (c >= 2147483648.0 || c < -2147483648.0)
     28 		I_Error("FixedDiv: divide by zero");
     29     return (fixed_t)c;
     30 }