home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / m_fixed.c < prev    next >
C/C++ Source or Header  |  1999-12-17  |  2KB  |  87 lines

  1. /*  Emacs style mode select   -*- C++ -*-  */
  2. /* ----------------------------------------------------------------------------- */
  3. /*  */
  4. /*  $Id:$ */
  5. /*  */
  6. /*  Copyright (C) 1993-1996 by id Software, Inc. */
  7. /*  */
  8. /*  This source is available for distribution and/or modification */
  9. /*  only under the terms of the DOOM Source Code License as */
  10. /*  published by id Software. All rights reserved. */
  11. /*  */
  12. /*  The source is distributed in the hope that it will be useful, */
  13. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of */
  14. /*  FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License */
  15. /*  for more details. */
  16. /*  */
  17. /*  $Log:$ */
  18. /*  */
  19. /*  DESCRIPTION: */
  20. /*     Fixed point implementation. */
  21. /*  */
  22. /* ----------------------------------------------------------------------------- */
  23.  
  24. #include "stdlib.h"
  25.  
  26. #include "doomtype.h"
  27. #include "i_system.h"
  28.  
  29. #ifdef __GNUG__
  30. #pragma implementation "m_fixed.h"
  31. #endif
  32. #include "m_fixed.h"
  33.  
  34.  
  35.  
  36.  
  37. /*  Fixme. __USE_C_FIXED__ or something. */
  38.  
  39. #ifndef ATARI
  40.  
  41. fixed_t
  42. FixedMul
  43. ( fixed_t    a,
  44.   fixed_t    b )
  45. {
  46.     return ((long long) a * (long long) b) >> FRACBITS;
  47. }
  48.  
  49.  
  50.  
  51. /*  */
  52. /*  FixedDiv, C version. */
  53. /*  */
  54.  
  55. fixed_t
  56. FixedDiv
  57. ( fixed_t    a,
  58.   fixed_t    b )
  59. {
  60.     if ( (abs(a)>>14) >= abs(b))
  61.     return (a^b)<0 ? MININT : MAXINT;
  62.     return FixedDiv2 (a,b);
  63. }
  64.  
  65.  
  66.  
  67. fixed_t
  68. FixedDiv2
  69. ( fixed_t    a,
  70.   fixed_t    b )
  71. {
  72. #if 0
  73.     long long c;
  74.     c = ((long long)a<<16) / ((long long)b);
  75.     return (fixed_t) c;
  76. #endif
  77.  
  78.     double c;
  79.  
  80.     c = ((double)a) / ((double)b) * FRACUNIT;
  81.  
  82.     if (c >= 2147483648.0 || c < -2147483648.0)
  83.     I_Error("FixedDiv: divide by zero");
  84.     return (fixed_t) c;
  85. }
  86. #endif
  87.