summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/mod.h
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/mod.h')
-rw-r--r--Build/source/utils/asymptote/mod.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/mod.h b/Build/source/utils/asymptote/mod.h
new file mode 100644
index 00000000000..89d017c6ced
--- /dev/null
+++ b/Build/source/utils/asymptote/mod.h
@@ -0,0 +1,41 @@
+/*****
+ * mod.h
+ * Andy Hammerlindl 2005/03/16
+ *
+ * Definition of implementation-independent mod function.
+ *****/
+
+#ifndef MOD_H
+#define MOD_H
+
+#include <cmath>
+
+#include "common.h"
+
+using std::fmod;
+
+inline Int Mod(Int x, Int y) {return x % y;}
+inline double Mod(double x, double y) {return fmod(x,y);}
+
+template<typename T>
+inline T portableMod(T x,T y)
+{
+// Implementation-independent definition of mod; ensure that result has
+// same sign as divisor
+ T val=Mod(x,y);
+ if((y > 0 && val < 0) || (y < 0 && val > 0)) val += y;
+ return val;
+}
+
+inline Int imod(Int x, Int y)
+{
+ return portableMod<Int>(x,y);
+}
+
+inline Int imod(Int i, size_t n) {
+ i %= (Int) n;
+ if(i < 0) i += (Int) n;
+ return i;
+}
+
+#endif