2 * $Logfile: /Freespace2/code/Math/Floating.h $
7 * Low-level floating point math macros and routines
10 * Revision 1.1 2002/05/03 03:28:12 root
14 * 4 4/07/99 6:22p Dave
15 * Fred and Freespace support for multiple background bitmaps and suns.
16 * Fixed link errors on all subprojects. Moved encrypt_init() to
17 * cfile_init() and lcl_init(), since its safe to call twice.
19 * 3 11/05/98 4:18p Dave
20 * First run nebula support. Beefed up localization a bit. Removed all
21 * conditional compiles for foreign versions. Modified mission file
24 * 2 10/07/98 10:53a Dave
27 * 1 10/07/98 10:49a Dave
29 * 13 2/26/98 3:28p John
30 * Changed all sqrt's to use fl_sqrt. Took out isqrt function
32 * 12 1/26/98 10:43p Mike
33 * Make ships not all zoom away from an impending shockwave at the same
34 * time. Based on ai class and randomness
36 * 11 1/17/98 3:32p Mike
37 * Add rand_range(), returns random float in min..max.
39 * 10 7/29/97 2:36p Hoffoss
40 * Added header file required by _isnan().
42 * 9 7/29/97 2:35p Hoffoss
43 * Added a NaN check macro.
45 * 8 2/17/97 5:18p John
46 * Added a bunch of RCS headers to a bunch of old files that don't have
58 extern float fl_isqrt( float a );
60 extern int rand_chance(float frametime, float chance = 1.0f);
61 float frand_range(float min, float max);
63 // determine if a floating point number is NaN (Not a Number)
64 #define fl_is_nan(fl) _isnan(fl)
66 // Handy macros to prevent type casting all over the place
68 #define fl_sqrt(fl) (float)sqrt((float)(fl))
69 #define fl_isqrt(fl) (1.0f/(float)sqrt((float)(fl)))
70 #define fl_abs(fl) (float)fabs((double)(fl))
71 #define i2fl(i) ((float)(i))
72 #define fl2i(fl) ((int)(fl))
73 #define flceil(fl) (int)ceil(fl)
74 #define flfloor(fl) (int)floor(fl)
75 #define f2fl(fx) ((float)(fx)/65536.0f)
76 #define fl2f(fl) (int)((fl)*65536.0f)
78 // convert a measurement in degrees to radians
79 #define fl_radian(fl) ((float)((fl * 3.14159f)/180.0f))
81 // convert a measurement in radians to degrees
82 #define fl_degrees(fl) ((float)((fl * 180.0f)/3.14159))
84 // use this instead of:
85 // for: (int)floor(x+0.5f) use fl_round_2048(x)
86 // (int)ceil(x-0.5f) use fl_round_2048(x)
87 // (int)floor(x-0.5f) use fl_round_2048(x-1.0f)
88 // (int)floor(x) use fl_round_2048(x-0.5f)
89 // for values in the range -2048 to 2048
90 // use this instead of:
91 // for: (int)floor(x+0.5f) use fl_round_2048(x)
92 // (int)ceil(x-0.5f) use fl_round_2048(x)
93 // (int)floor(x-0.5f) use fl_round_2048(x-1.0f)
94 // (int)floor(x) use fl_round_2048(x-0.5f)
95 // for values in the range -2048 to 2048
97 extern const float *p_fl_magic;
99 inline int fl_round_2048( float x )
102 tmp_quad = x + *p_fl_magic;
103 return *((int *)&tmp_quad);
107 inline float fl_sqrt( float x)
118 float fl_isqrt( float x )
126 return 1.0f / retval;
132 // rounds off a floating point number to a multiple of some number
133 extern float fl_roundoff(float x, int multiple);