00001
00002
00003
00012 #ifndef CXXUTILS_SINCOS_H
00013 #define CXXUTILS_SINCOS_H
00014
00015
00016 #include <cmath>
00017
00018
00019 namespace CxxUtils {
00020
00021
00070 struct sincos
00071 {
00073 sincos (double x)
00074 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
00075
00076 { __asm __volatile__ ("fsincos\n\t" : "=t" (cs), "=u" (sn) : "0" (x)); }
00077 #elif defined(__USE_GNU)
00078
00079 { sincos(x, &sn, &cs); }
00080 #else
00081
00082 : sn (std::sin (x)), cs (std::cos (x)) {}
00083 #endif
00084
00086 double sn;
00087
00089 double cs;
00090
00092 double apply (double a, double b) const { return a*sn + b*cs; }
00093
00095 double apply2 (double a, double b, double c) const
00096 { return a*sn*sn + b*sn*cs + c*cs*cs; }
00097 };
00098
00099
00100 }
00101
00102
00103 #endif //not CXXUTILS_SINCOS_H