-
Notifications
You must be signed in to change notification settings - Fork 1
/
M_FIXED.C
49 lines (40 loc) · 937 Bytes
/
M_FIXED.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// m_fixed.c : fixed point implementation.
#include "i_system.h"
#include "m_fixed.h"
#ifdef __WIN32__
#define INT64 __int64
#else
#define INT64 long long
#endif
// Fixme. __USE_C_FIXED__ or something.
#ifndef USEASM
fixed_t FixedMul (fixed_t a, fixed_t b)
{
return ((INT64) a * (INT64) b) >> FRACBITS;
}
fixed_t FixedDiv2 (fixed_t a, fixed_t b)
{
#if 0
INT64 c;
c = ((INT64)a<<16) / ((INT64)b);
return (fixed_t) c;
#endif
double c;
c = ((double)a) / ((double)b) * FRACUNIT;
if (c >= 2147483648.0 || c < -2147483648.0)
I_Error("FixedDiv: divide by zero");
return (fixed_t) c;
}
/*
//
// FixedDiv, C version.
//
fixed_t FixedDiv ( fixed_t a, fixed_t b )
{
//I_Error("<a: %ld, b: %ld>",(long)a,(long)b);
if ( (abs(a)>>14) >= abs(b))
return (a^b)<0 ? MININT : MAXINT;
return FixedDiv2 (a,b);
}
*/
#endif // useasm