summaryrefslogtreecommitdiffstats
path: root/mathfuncs_rcp.h
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-03-21 12:59:44 -0400
committerErik Schnetter <schnetter@gmail.com>2013-03-21 12:59:44 -0400
commit56cf54a990096875c0293ff50f839c05aee75def (patch)
tree228e1a88e839f89f72418f212a1558c35da26823 /mathfuncs_rcp.h
parent4272d8f94dd4c4b00ef42778c5c5255cfb94feba (diff)
downloadvecmathlib-56cf54a990096875c0293ff50f839c05aee75def.zip
vecmathlib-56cf54a990096875c0293ff50f839c05aee75def.tar.gz
Simplify remainder() and fmod()
Diffstat (limited to 'mathfuncs_rcp.h')
-rw-r--r--mathfuncs_rcp.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/mathfuncs_rcp.h b/mathfuncs_rcp.h
index a7d7ba3..81f77ea 100644
--- a/mathfuncs_rcp.h
+++ b/mathfuncs_rcp.h
@@ -47,15 +47,19 @@ namespace vecmathlib {
template<typename realvec_t>
realvec_t mathfuncs<realvec_t>::vml_remainder(realvec_t x, realvec_t y)
{
- return x - rint(x / y) * y;
+ // return x - rint(x / y) * y;
+ realvec_t r = x / y;
+ return y * (r - rint(r));
}
template<typename realvec_t>
realvec_t mathfuncs<realvec_t>::vml_fmod(realvec_t x, realvec_t y)
{
- realvec_t r = fabs(x);
- y = fabs(y);
- return copysign(r - floor(r / y) * y, x);
+ // realvec_t r = fabs(x);
+ // y = fabs(y);
+ // return copysign(r - floor(r / y) * y, x);
+ realvec_t r = x / y;
+ return y * (r - trunc(r));
}
}; // namespace vecmathlib
OpenPOWER on IntegriCloud