aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-05-20 15:48:53 -0500
committerErik Schnetter <schnetter@gmail.com>2013-05-20 15:48:53 -0500
commit45ec6d4b74e02f439c7c429bb0a66972ea1ba46b (patch)
treec6cb8964b24284182367072b23cb9f37789bc60b /Carpet/CarpetLib
parentc5ff55274bef4ec6ecd0a714d2452504a0d62ff2 (diff)
CarpetLib: Provide idiv and imod implementations for vect<CCTK_REAL,...>
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r--Carpet/CarpetLib/src/vect.hh23
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