- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/Programmation/Sources/Tensor2/Utils/src/frost_utils_math.cpp

Go to the documentation of this file.

    00001 /* ###################################### */
    00002 /* ###     Frost Engine, by Kalith    ### */
    00003 /* ###################################### */
    00004 /*                                        */
    00005
    00006 #include "frost_utils_math.h"
    00007
    00008 #include <cmath>
    00009
    00010 #ifdef MSVC
    00011     // Note : Microsoft's Visual C++ doesn't include the round function.
    00012     long round( double x )
    00013     {
    00014         int i = static_cast<long>(x);
    00015         if (x >= 0.0)
    00016             return (x-i >= 0.5) ? i + 1 : i;
    00017         else
    00018             return (i-x >= 0.5) ? i - 1 : i;
    00019     }
    00020 #endif
    00021
    00022 namespace Frost
    00023 {
    00024 // s_int
    00025
    00026     s_float cos(const s_int& iValue)
    00027     {
    00028         return ::cos(iValue.Get()*2.0f*s_float::PI.Get());
    00029     }
    00030
    00031     s_float acos(const s_int& iValue)
    00032     {
    00033         return s_float(::acos(static_cast<float>(iValue.Get())))/(2.0f*s_float::PI);
    00034     }
    00035
    00036     s_float sin(const s_int& iValue)
    00037     {
    00038         return ::sin(iValue.Get()*2.0f*s_float::PI.Get());
    00039     }
    00040
    00041     s_float asin(const s_int& iValue)
    00042     {
    00043         return s_float(::asin(static_cast<float>(iValue.Get())))/(2.0f*s_float::PI);
    00044     }
    00045
    00046     s_float tan(const s_int& iValue)
    00047     {
    00048         return ::tan(iValue.Get()*2.0f*s_float::PI.Get());
    00049     }
    00050
    00051     s_float atan(const s_int& iValue)
    00052     {
    00053         return s_float(::atan(static_cast<float>(iValue.Get())))/(2.0f*s_float::PI);
    00054     }
    00055
    00056     s_float atan2(const s_int& iX, const s_int& iY)
    00057     {
    00058         return s_float(::atan2(static_cast<float>(iX.Get()), static_cast<float>(iY.Get())))/(2.0f*s_float::PI.Get());
    00059     }
    00060
    00061     s_int fabs(const s_int& iValue)
    00062     {
    00063         return static_cast<int>(::fabs(static_cast<float>(iValue.Get())));
    00064     }
    00065
    00066     s_float pow(const s_int& iValue, const s_float& fValue)
    00067     {
    00068         return ::pow(static_cast<float>(iValue.Get()), static_cast<float>(fValue.Get()));
    00069     }
    00070
    00071     s_double pow(const s_int& iValue, const s_double& dValue)
    00072     {
    00073         return ::pow(static_cast<double>(iValue.Get()), static_cast<double>(dValue.Get()));
    00074     }
    00075
    00076     s_float sqrt(const s_int& iValue)
    00077     {
    00078         return ::sqrt(static_cast<float>(iValue.Get()));
    00079     }
    00080
    00081     s_float exp(const s_int& iValue)
    00082     {
    00083         return ::exp(static_cast<float>(iValue.Get()));
    00084     }
    00085
    00086 // s_uint
    00087
    00088     s_float cos(const s_uint& uiValue)
    00089     {
    00090         return ::cos(uiValue.Get()*2.0f*s_float::PI.Get());
    00091     }
    00092
    00093     s_float acos(const s_uint& uiValue)
    00094     {
    00095         return s_float(::acos(static_cast<float>(uiValue.Get())))/(2.0f*s_float::PI);
    00096     }
    00097
    00098     s_float sin(const s_uint& uiValue)
    00099     {
    00100         return ::sin(uiValue.Get()*2*s_float::PI.Get());
    00101     }
    00102
    00103     s_float asin(const s_uint& uiValue)
    00104     {
    00105         return s_float(::asin(static_cast<float>(uiValue.Get())))/(2.0f*s_float::PI);
    00106     }
    00107
    00108     s_float tan(const s_uint& uiValue)
    00109     {
    00110         return ::tan(uiValue.Get()*2.0f*s_float::PI.Get());
    00111     }
    00112
    00113     s_float atan(const s_uint& uiValue)
    00114     {
    00115         return s_float(::atan(static_cast<float>(uiValue.Get())))/(2.0f*s_float::PI);
    00116     }
    00117
    00118     s_float atan2(const s_uint& uiX, const s_uint& uiY)
    00119     {
    00120         return s_float(::atan2(static_cast<float>(uiX.Get()), static_cast<float>(uiY.Get())))/(2.0f*s_float::PI);
    00121     }
    00122
    00123     s_float pow(const s_uint& uiValue, const s_float& fValue)
    00124     {
    00125         return ::pow(static_cast<float>(uiValue.Get()), static_cast<float>(fValue.Get()));
    00126     }
    00127
    00128     s_double pow(const s_uint& uiValue, const s_double& dValue)
    00129     {
    00130         return ::pow(static_cast<double>(uiValue.Get()), static_cast<double>(dValue.Get()));
    00131     }
    00132
    00133     s_float sqrt(const s_uint& uiValue)
    00134     {
    00135         return ::sqrt(static_cast<float>(uiValue.Get()));
    00136     }
    00137
    00138     s_float exp(const s_uint& uiValue)
    00139     {
    00140         return ::exp(static_cast<float>(uiValue.Get()));
    00141     }
    00142
    00143 // s_float
    00144
    00145     s_float cos(const s_float& fValue)
    00146     {
    00147         return ::cos((fValue*2.0f*s_float::PI).Get());
    00148     }
    00149
    00150     s_float acos(const s_float& fValue)
    00151     {
    00152         return s_float(::acos(fValue.Get()))/(2.0f*s_float::PI);
    00153     }
    00154
    00155     s_float sin(const s_float& fValue)
    00156     {
    00157         return ::sin((fValue*2*s_float::PI).Get());
    00158     }
    00159
    00160     s_float asin(const s_float& fValue)
    00161     {
    00162         return s_float(::asin(fValue.Get()))/(2.0f*s_float::PI);
    00163     }
    00164
    00165     s_float tan(const s_float& fValue)
    00166     {
    00167         return ::tan((fValue*2.0f*s_float::PI).Get());
    00168     }
    00169
    00170     s_float atan(const s_float& fValue)
    00171     {
    00172         return s_float(::atan(fValue.Get()))/(2.0f*s_float::PI);
    00173     }
    00174
    00175     s_float atan2(const s_float& fX, const s_float& fY)
    00176     {
    00177         return s_float(::atan2(fX.Get(), fY.Get()))/(2.0f*s_float::PI);
    00178     }
    00179
    00180     s_float fabs(const s_float& fValue)
    00181     {
    00182         return ::fabs(fValue.Get());
    00183     }
    00184
    00185     s_float pow(const s_float& fValue1, const s_float& fValue2)
    00186     {
    00187         return ::pow(static_cast<float>(fValue1.Get()), static_cast<float>(fValue2.Get()));
    00188     }
    00189
    00190     s_double pow(const s_float& fValue, const s_double& dValue)
    00191     {
    00192         return ::pow(static_cast<double>(fValue.Get()), static_cast<double>(dValue.Get()));
    00193     }
    00194
    00195     s_float sqrt(const s_float& fValue)
    00196     {
    00197         return ::sqrt(fValue.Get());
    00198     }
    00199
    00200     s_float exp(const s_float& fValue)
    00201     {
    00202         return ::exp(fValue.Get());
    00203     }
    00204
    00205 // s_double
    00206
    00207     s_double cos(const s_double& dValue)
    00208     {
    00209         return ::cos((dValue*2.0*s_double::PI).Get());
    00210     }
    00211
    00212     s_double acos(const s_double& dValue)
    00213     {
    00214         return s_double(::acos(dValue.Get()))/(2.0*s_double::PI);
    00215     }
    00216
    00217     s_double sin(const s_double& dValue)
    00218     {
    00219         return ::sin((dValue*2.0*s_double::PI).Get());
    00220     }
    00221
    00222     s_double asin(const s_double& dValue)
    00223     {
    00224         return s_double(::asin(dValue.Get()))/(2.0*s_double::PI);
    00225     }
    00226
    00227     s_double tan(const s_double& dValue)
    00228     {
    00229         return ::tan((dValue*2.0*s_double::PI).Get());
    00230     }
    00231
    00232     s_double atan(const s_double& dValue)
    00233     {
    00234         return s_double(::atan(dValue.Get()))/(2.0*s_double::PI);
    00235     }
    00236
    00237     s_double atan2(const s_double& dX, const s_double& dY)
    00238     {
    00239         return s_double(::atan2(dX.Get(), dY.Get()))/(2.0*s_double::PI);
    00240     }
    00241
    00242     s_double fabs(const s_double& dValue)
    00243     {
    00244         return ::fabs(dValue.Get());
    00245     }
    00246
    00247     s_double pow(const s_double& dValue1, const s_double& dValue2)
    00248     {
    00249         return ::pow(static_cast<double>(dValue1.Get()), static_cast<double>(dValue2.Get()));
    00250     }
    00251
    00252     s_double pow(const s_double& dValue, const s_float& fValue)
    00253     {
    00254         return ::pow(static_cast<double>(dValue.Get()), static_cast<double>(fValue.Get()));
    00255     }
    00256
    00257     s_double sqrt(const s_double& dValue)
    00258     {
    00259         return ::sqrt(dValue.Get());
    00260     }
    00261
    00262     s_double exp(const s_double& dValue)
    00263     {
    00264         return ::exp(dValue.Get());
    00265     }
    00266 }