m_fixed.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. static const char
  24. rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
  25. #include "stdlib.h"
  26. #include "doomtype.h"
  27. #include "i_system.h"
  28. #ifdef __GNUG__
  29. #pragma implementation "m_fixed.h"
  30. #endif
  31. #include "m_fixed.h"
  32. // Fixme. __USE_C_FIXED__ or something.
  33. fixed_t
  34. FixedMul
  35. ( fixed_t a,
  36. fixed_t b )
  37. {
  38. return ((long long) a * (long long) b) >> FRACBITS;
  39. }
  40. //
  41. // FixedDiv, C version.
  42. //
  43. fixed_t
  44. FixedDiv
  45. ( fixed_t a,
  46. fixed_t b )
  47. {
  48. if ( (abs(a)>>14) >= abs(b))
  49. return (a^b)<0 ? MININT : MAXINT;
  50. return FixedDiv2 (a,b);
  51. }
  52. fixed_t
  53. FixedDiv2
  54. ( fixed_t a,
  55. fixed_t b )
  56. {
  57. #if 0
  58. long long c;
  59. c = ((long long)a<<16) / ((long long)b);
  60. return (fixed_t) c;
  61. #endif
  62. double c;
  63. c = ((double)a) / ((double)b) * FRACUNIT;
  64. if (c >= 2147483648.0 || c < -2147483648.0)
  65. I_Error("FixedDiv: divide by zero");
  66. return (fixed_t) c;
  67. }