00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT library (C++) 00015 * 00016 * COMMENTS: Fast lookup to get integer square roots. The square roots 00017 * will round, thus UTisqrt(3) = 2, UTisqrt(2) = 1 00018 * The table is good for positive integers up to 1024 00019 * 00020 */ 00021 00022 #ifndef __UT_ISqrt_h__ 00023 #define __UT_ISqrt_h__ 00024 00025 #include "UT_API.h" 00026 #include <SYS/SYS_Types.h> 00027 00028 #define MAX_ISQRT 1024 00029 00030 UT_API extern int UTisqrtTable[]; 00031 UT_API extern float UTinvSqrtTable[]; 00032 00033 UT_API unsigned int UTbigISqrt(unsigned int val); 00034 00035 inline int UTisqrtFast(unsigned val) { return UTisqrtTable[val]; } 00036 inline float UTinverseSqrtFast(unsigned val) { return UTinvSqrtTable[val]; } 00037 00038 inline int 00039 UTisqrt(unsigned val) 00040 { 00041 return val <= MAX_ISQRT ? UTisqrtTable[val] : UTbigISqrt(val); 00042 } 00043 00044 inline float 00045 UTinverseSqrt(unsigned val) 00046 { 00047 return val <= MAX_ISQRT ? UTinvSqrtTable[val] 00048 : 1.0F/(float)UTbigISqrt(val); 00049 } 00050 00051 #endif
1.5.9