00001 // Wild Magic Source Code 00002 // David Eberly 00003 // http://www.geometrictools.com 00004 // Copyright (c) 1998-2007 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 // The license applies to versions 0 through 4 of Wild Magic. 00014 // 00015 // Version: 4.0.0 (2006/06/28) 00016 00017 #ifndef WM4MATHMCR_H 00018 #define WM4MATHMCR_H 00019 00020 //---------------------------------------------------------------------------- 00021 00022 // Fast conversion from a IEEE 32-bit floating point number F in [0,1] to a 00023 // a 32-bit integer I in [0,2^L-1]. 00024 // 00025 // fFloat = F 00026 // iLog = L 00027 // iInt = I 00028 00029 #define WM4_SCALED_FLOAT_TO_INT(fFloat,iLog,iInt)\ 00030 { \ 00031 int iShift = 150 - iLog - ((*(int*)(&fFloat) >> 23) & 0xFF); \ 00032 if ( iShift < 24 ) \ 00033 { \ 00034 iInt = ((*(int*)(&fFloat) & 0x007FFFFF) | \ 00035 0x00800000) >> iShift; \ 00036 if ( iInt == (1 << iLog) ) \ 00037 { \ 00038 iInt--; \ 00039 } \ 00040 } \ 00041 else \ 00042 { \ 00043 iInt = 0; \ 00044 } \ 00045 } 00046 00047 //---------------------------------------------------------------------------- 00048 00049 #endif