Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/linmath/cmath.I

Go to the documentation of this file.
00001 // Filename: cmath.I
00002 // Created by:  drose (19May00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 //Windows has isnan in a different place and with a different name
00020 //than everyone else.  Sheesh
00021 #ifdef _WIN32
00022 #include <float.h>
00023 #endif
00024 
00025 INLINE_LINMATH float csqrt(float v) {
00026   return sqrtf(v);
00027 }
00028 
00029 INLINE_LINMATH float csin(float v) {
00030   return sinf(v);
00031 }
00032 
00033 INLINE_LINMATH float ccos(float v) {
00034   return cosf(v);
00035 }
00036 
00037 INLINE_LINMATH float ctan(float v) {
00038   return tanf(v);
00039 }
00040 
00041 INLINE_LINMATH void
00042 sincosf(float v, float *pSinResult, float *pCosResult) {
00043 
00044 // MS VC defines _M_IX86 for x86.  gcc should define _X86_
00045 #if defined(_M_IX86) || defined(_X86_)
00046 //#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
00047     __asm {
00048         mov eax, pSinResult
00049         mov edx, pCosResult
00050         fld v
00051         fsincos
00052         fstp DWORD ptr [edx]
00053         fstp DWORD ptr [eax]
00054     }
00055 #else //!_X86_
00056     *pSinResult = sinf(v);
00057     *pCosResult = cosf(v);
00058 #endif //!_X86_
00059 }
00060 
00061 INLINE_LINMATH void
00062 sincosd(double v, double *pSinResult, double *pCosResult) {
00063 #if defined(_M_IX86) || defined(_X86_)
00064 //#define fsincos_opcode __asm _emit 0xd9 __asm _emit 0xfb
00065     __asm {
00066         mov eax, pSinResult
00067         mov edx, pCosResult
00068         fld v
00069         fsincos
00070         fstp QWORD ptr [edx]
00071         fstp QWORD ptr [eax]
00072     }
00073 #else //!_X86_
00074     *pSinResult = sin(v);
00075     *pCosResult = cos(v);
00076 #endif //!_X86_
00077 }
00078 
00079 INLINE_LINMATH void csincos(float v,float *pSinResult, float *pCosResult) {
00080   sincosf(v,pSinResult,pCosResult);
00081 }
00082 
00083 INLINE_LINMATH void csincos(double v,double *pSinResult, double *pCosResult) {
00084   sincosd(v,pSinResult,pCosResult);
00085 }
00086 
00087 INLINE_LINMATH float cabs(float v) {
00088   return fabs(v);
00089 }
00090 
00091 INLINE_LINMATH float catan(float v) {
00092   return atanf(v);
00093 }
00094 
00095 INLINE_LINMATH float catan2(float y, float x) {
00096   return atan2f(y, x);
00097 }
00098 
00099 #ifdef __INTEL_COMPILER
00100 // see float.h
00101 #define FPU_CONTROLWORD_WRITEMASK    0xFFFFF        // if you look at defn of _CW_DEFAULT, all settings fall within 0xFFFFF
00102 #define FPU_CONTROLWORD_NEW_SETTING  _CW_DEFAULT
00103 #endif  
00104 
00105 INLINE_LINMATH double cfloor(double f) {
00106   #ifdef __INTEL_COMPILER
00107     // intel floor doesnt work right if fpu mode is not double, so make double-prec mode is on
00108     unsigned int saved_fpu_control_word=_controlfp(0x0,0x0);
00109     _controlfp(FPU_CONTROLWORD_NEW_SETTING,FPU_CONTROLWORD_WRITEMASK);
00110     double retval=floor(f);
00111     _controlfp(saved_fpu_control_word,FPU_CONTROLWORD_WRITEMASK);
00112     return retval;
00113   #else
00114     return floor(f);  
00115   #endif
00116 }
00117 
00118 INLINE_LINMATH double cceil(double f) {
00119   #ifdef __INTEL_COMPILER
00120     // intel ceil doesnt work right if fpu mode is not double, so make double-prec mode is on
00121     unsigned int saved_fpu_control_word=_controlfp(0x0,0x0);
00122     _controlfp(FPU_CONTROLWORD_NEW_SETTING,FPU_CONTROLWORD_WRITEMASK);
00123     double retval=ceil(f);
00124     _controlfp(saved_fpu_control_word,FPU_CONTROLWORD_WRITEMASK);
00125     return retval;
00126   #else
00127     return ceil(f);  
00128   #endif
00129 }
00130 
00131 INLINE_LINMATH double csqrt(double v) {
00132   return sqrt(v);
00133 }
00134 
00135 INLINE_LINMATH double csin(double v) {
00136   return sin(v);
00137 }
00138 
00139 INLINE_LINMATH double ccos(double v) {
00140   return cos(v);
00141 }
00142 
00143 INLINE_LINMATH double ctan(double v) {
00144   return tan(v);
00145 }
00146 
00147 INLINE_LINMATH double cabs(double v) {
00148   return fabs(v);
00149 }
00150 
00151 INLINE_LINMATH double catan(double v) {
00152   return atan(v);
00153 }
00154 
00155 INLINE_LINMATH double catan2(double y, double x) {
00156   return atan2(y, x);
00157 }
00158 
00159 INLINE_LINMATH bool cnan(double v) {
00160 #ifndef _WIN32
00161   return (isnan(v) != 0);
00162 #else
00163   return (_isnan(v) != 0);
00164 #endif
00165 }
00166 
00167 

Generated on Fri May 2 00:40:00 2003 for Panda by doxygen1.3