Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
298 | serge | 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 "stdlib.h" |
||
29 | |||
30 | #include "doomtype.h" |
||
31 | #include "i_system.h" |
||
32 | |||
33 | #ifdef __GNUG__ |
||
34 | #pragma implementation "m_fixed.h" |
||
35 | #endif |
||
36 | #include "m_fixed.h" |
||
37 | |||
38 | |||
39 | |||
40 | |||
41 | // Fixme. __USE_C_FIXED__ or something. |
||
42 | |||
43 | fixed_t |
||
44 | FixedMul |
||
45 | ( fixed_t a, |
||
46 | fixed_t b ) |
||
47 | { |
||
48 | return ((long long) a * (long long) b) >> FRACBITS; |
||
49 | } |
||
50 | |||
51 | |||
52 | |||
53 | // |
||
54 | // FixedDiv, C version. |
||
55 | // |
||
56 | |||
57 | fixed_t |
||
58 | FixedDiv |
||
59 | ( fixed_t a, |
||
60 | fixed_t b ) |
||
61 | { |
||
62 | if ( (abs(a)>>14) >= abs(b)) |
||
63 | return (a^b)<0 ? MININT : MAXINT; |
||
64 | return FixedDiv2 (a,b); |
||
65 | } |
||
66 | |||
67 | |||
68 | |||
69 | fixed_t |
||
70 | FixedDiv2 |
||
71 | ( fixed_t a, |
||
72 | fixed_t b ) |
||
73 | { |
||
74 | #if 0 |
||
75 | long long c; |
||
76 | c = ((long long)a<<16) / ((long long)b); |
||
77 | return (fixed_t) c; |
||
78 | #endif |
||
79 | |||
80 | double c; |
||
81 | |||
82 | c = ((double)a) / ((double)b) * FRACUNIT; |
||
83 | |||
84 | if (c >= 2147483648.0 || c < -2147483648.0) |
||
85 | I_Error("FixedDiv: divide by zero"); |
||
86 | return (fixed_t) c; |
||
87 | }>16)><16)>0> |