last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2005-2007 00003 * Peter Doerfler 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 /** 00042 * \file cvrSinCos.h 00043 * Contains platform and/or compiler specific implementations 00044 * of sincos, sincosf, and sincosl - always appending _impl to 00045 * the name. Don't use this file directly but include 00046 * cvrMath.h instead which provides a template function 00047 * sincos() 00048 * 00049 * \author Peter Doerfler 00050 * \date 27.10.2005 00051 * 00052 * $Id: cvrSinCos.h,v 1.1 2007/09/13 23:29:55 alvarado Exp $ 00053 */ 00054 00055 00056 #ifndef _CVR_SIN_COS_H_ 00057 #define _CVR_SIN_COS_H_ 00058 00059 #include "cvrTypes.h" 00060 #include "cvrMacroSymbols.h" 00061 #include <cmath> 00062 00063 00064 namespace cvr { 00065 00066 namespace internal { 00067 // structure: first level: compiler, possibly second level with 00068 // machine type needed. 00069 00070 // MacOSX somehow misses sincos() and sincosf() 00071 #if defined(_CVR_GNUC_3) && !(defined(_CVR_MACOSX)) 00072 00073 // just wrap for constistency 00074 00075 /** 00076 * Calculate the sine and cosine values of \p angle in one step if 00077 * the setup allows it. 00078 */ 00079 void inline sincos_impl(double angle, double& sval, double& cval) { 00080 ::sincos(angle, &sval, &cval); 00081 } 00082 00083 /** 00084 * Calculate the sine and cosine values of \p angle in one step if 00085 * the setup allows it. 00086 */ 00087 void inline sincosf_impl(float angle, float& sval, float& cval) { 00088 ::sincosf(angle, &sval, &cval); 00089 } 00090 00091 #elif defined(_CVR_MSC_VER) 00092 00093 // inline asm implementations 00094 00095 /** 00096 * Calculate the sine and cosine values of \p angle in one step if 00097 * the setup allows it. 00098 */ 00099 void inline sincos_impl(double angle, double& sval, double& cval) { 00100 __asm { 00101 00102 fld QWORD PTR [angle] 00103 fsincos 00104 mov ebx, [cval] 00105 fstp QWORD PTR [ebx] 00106 mov ebx, [sval] 00107 fstp QWORD PTR [ebx] 00108 } 00109 } 00110 00111 /** 00112 * Calculate the sine and cosine values of \p angle in one step if 00113 * the setup allows it. 00114 */ 00115 void inline sincosf_impl(float angle, float& sval, float& cval) { 00116 __asm { 00117 00118 fld DWORD PTR [angle] 00119 fsincos 00120 mov ebx, [cval] 00121 fstp DWORD PTR [ebx] 00122 mov ebx, [sval] 00123 fstp DWORD PTR [ebx] 00124 } 00125 } 00126 00127 #else 00128 00129 // don't know how to do this right so just do the simple thing 00130 void inline sincos_impl(double angle, double& sval, double& cval) { 00131 sval = sin(angle); 00132 cval = cos(angle); 00133 } 00134 void inline sincosf_impl(float angle, float& sval, float& cval) { 00135 sval = sin(angle); 00136 cval = cos(angle); 00137 } 00138 00139 #endif // compilers 00140 00141 } // end of namespace internal 00142 00143 /** 00144 * Calculate the sine and cosine values of \p angle in one step if 00145 * the setup allows it. 00146 * 00147 * @param angle the angle 00148 * @param sval sine of the \p angle 00149 * @param cval cosine of the \p angle 00150 */ 00151 template <class T> 00152 inline void sincos(T angle, T& sval, T& cval) { 00153 internal::sincos_impl(static_cast<double>(angle), 00154 static_cast<double&>(sval), 00155 static_cast<double&>(cval)); 00156 } 00157 00158 // overload for float 00159 inline void sincos(float angle, float& sval, float& cval) { 00160 internal::sincosf_impl(angle,sval,cval); 00161 } 00162 00163 } 00164 00165 #endif // _CVR_SIN_COS_H