gfloat.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: gfloat
00004 
00005     DESCRIPTION: Single Precision Floating Point Routines
00006 
00007     CREATED BY: Don Brittain & Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 
00016 // if on Intel, and not compiling managed code, use assembly language
00017 #undef __USE_ASM_CODE_
00018 
00019 #ifndef _MANAGED
00020     #ifdef _M_IX86
00021         #define __USE_ASM_CODE_
00022     #else
00023         #include <math.h>
00024     #endif
00025 #endif
00026 
00027 //-------------------------------------------------------------------------------
00028 // Single precision floating point stuff...
00029 //
00030 inline void SinCos (float angle, float *sine, float *cosine) 
00031 {
00032 #ifdef __USE_ASM_CODE_
00033     __asm {
00034         push        ecx
00035         fld         dword ptr angle
00036         fsincos
00037         mov         ecx, dword ptr[cosine]
00038         fstp        dword ptr [ecx]
00039         mov         ecx, dword ptr[sine]
00040         fstp        dword ptr [ecx]
00041         pop         ecx
00042     }
00043 #else
00044     *sine   = (float)sin (angle);
00045     *cosine = (float)cos (angle);
00046 #endif
00047 }
00048 
00049 inline float Sin(float angle)
00050 {
00051 #ifdef __USE_ASM_CODE_
00052     float s, c;
00053     SinCos(angle, &s, &c);
00054     return s;
00055 #else
00056     return (float)sin((double)angle);
00057 #endif
00058 }
00059 
00060 inline float Cos(float angle)
00061 {
00062 #ifdef __USE_ASM_CODE_
00063     float s, c;
00064     SinCos(angle, &s, &c);
00065     return c;
00066 #else
00067     return (float)cos((double)angle);
00068 #endif
00069 }
00070 
00071 inline float Sqrt(float arg)
00072 {
00073 #ifdef __USE_ASM_CODE_
00074     float ans;
00075     __asm {
00076         fld         dword ptr arg
00077         fsqrt
00078         fstp        dword ptr [ans]
00079         }
00080     return ans;
00081 #else
00082     return (float)sqrt((double)arg);
00083 #endif
00084 }
00085 
00086