Skip to content
Snippets Groups Projects
Commit b06c7716 authored by Oliver Sander's avatar Oliver Sander Committed by sander@PCPOOL.MI.FU-BERLIN.DE
Browse files

stable implementation of sinc

[[Imported from SVN: r5588]]
parent 337257c2
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,11 @@ ...@@ -6,6 +6,11 @@
template <int dim> template <int dim>
class UnitVector class UnitVector
{ {
/** \brief Computes sin(x/2) / x without getting unstable for small x */
static double sinc(const double& x) {
return (x < 1e-4) ? 1 + (x*x/6) : std::sin(x)/x;
}
public: public:
/** \brief The type used for coordinates */ /** \brief The type used for coordinates */
...@@ -29,7 +34,7 @@ public: ...@@ -29,7 +34,7 @@ public:
const double norm = v.two_norm(); const double norm = v.two_norm();
UnitVector result = p; UnitVector result = p;
result.data_ *= std::cos(norm); result.data_ *= std::cos(norm);
result.data_.axpy(std::sin(norm)/norm, v); result.data_.axpy(sinc(norm), v);
return result; return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment