diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-05-20 15:48:53 -0500 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-05-20 15:48:53 -0500 |
commit | 45ec6d4b74e02f439c7c429bb0a66972ea1ba46b (patch) | |
tree | c6cb8964b24284182367072b23cb9f37789bc60b /Carpet/CarpetLib/src | |
parent | c5ff55274bef4ec6ecd0a714d2452504a0d62ff2 (diff) |
CarpetLib: Provide idiv and imod implementations for vect<CCTK_REAL,...>
Diffstat (limited to 'Carpet/CarpetLib/src')
-rw-r--r-- | Carpet/CarpetLib/src/vect.hh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh index a8b708cca..2981f4a8f 100644 --- a/Carpet/CarpetLib/src/vect.hh +++ b/Carpet/CarpetLib/src/vect.hh @@ -762,6 +762,29 @@ inline vect<CCTK_REAL,dim> operator%(const vect<CCTK_REAL,dim>& a, const vect<CC return r; } +template<> +inline vect<CCTK_REAL,dim> idiv(const vect<CCTK_REAL,dim>& a, const vect<CCTK_REAL,dim>& b) { + vect<CCTK_REAL,dim> r; + for (int d=0; d<dim; ++d) { + r[d]=floor(a[d]/b[d]); + if (r[d]>b[d]*(CCTK_REAL)(1.0-1.0e-10)) r[d]=(CCTK_REAL)0; + if (r[d]<b[d]*(CCTK_REAL)( 1.0e-10)) r[d]=(CCTK_REAL)0; + } + return r; +} + +template<> +inline vect<CCTK_REAL,dim> imod(const vect<CCTK_REAL,dim>& a, const vect<CCTK_REAL,dim>& b) { + vect<CCTK_REAL,dim> r; + for (int d=0; d<dim; ++d) { + r[d]=a[d]/b[d]; + r[d]=b[d]*(r[d]-floor(r[d])); + if (r[d]>b[d]*(CCTK_REAL)(1.0-1.0e-10)) r[d]=(CCTK_REAL)0; + if (r[d]<b[d]*(CCTK_REAL)( 1.0e-10)) r[d]=(CCTK_REAL)0; + } + return r; +} + #endif // VECT_HH |