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