00001 // Wild Magic Source Code 00002 // David Eberly 00003 // http://www.geometrictools.com 00004 // Copyright (c) 1998-2008 00005 // 00006 // This library is free software; you can redistribute it and/or modify it 00007 // under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation; either version 2.1 of the License, or (at 00009 // your option) any later version. The license is available for reading at 00010 // either of the locations: 00011 // http://www.gnu.org/copyleft/lgpl.html 00012 // http://www.geometrictools.com/License/WildMagicLicense.pdf 00013 // 00014 // Version: 4.0.0 (2006/06/28) 00015 00016 #ifndef WM4MATHMCR_H 00017 #define WM4MATHMCR_H 00018 00019 //---------------------------------------------------------------------------- 00020 00021 // Fast conversion from a IEEE 32-bit floating point number F in [0,1] to a 00022 // a 32-bit integer I in [0,2^L-1]. 00023 // 00024 // fFloat = F 00025 // iLog = L 00026 // iInt = I 00027 00028 #define WM4_SCALED_FLOAT_TO_INT(fFloat,iLog,iInt)\ 00029 { \ 00030 int iShift = 150 - iLog - ((*(int*)(&fFloat) >> 23) & 0xFF); \ 00031 if ( iShift < 24 ) \ 00032 { \ 00033 iInt = ((*(int*)(&fFloat) & 0x007FFFFF) | \ 00034 0x00800000) >> iShift; \ 00035 if ( iInt == (1 << iLog) ) \ 00036 { \ 00037 iInt--; \ 00038 } \ 00039 } \ 00040 else \ 00041 { \ 00042 iInt = 0; \ 00043 } \ 00044 } 00045 00046 //---------------------------------------------------------------------------- 00047 00048 #endif