diff options
author | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 12:59:44 -0400 |
---|---|---|
committer | Erik Schnetter <schnetter@gmail.com> | 2013-03-21 12:59:44 -0400 |
commit | 56cf54a990096875c0293ff50f839c05aee75def (patch) | |
tree | 228e1a88e839f89f72418f212a1558c35da26823 /mathfuncs_rcp.h | |
parent | 4272d8f94dd4c4b00ef42778c5c5255cfb94feba (diff) | |
download | vecmathlib-56cf54a990096875c0293ff50f839c05aee75def.zip vecmathlib-56cf54a990096875c0293ff50f839c05aee75def.tar.gz |
Simplify remainder() and fmod()
Diffstat (limited to 'mathfuncs_rcp.h')
-rw-r--r-- | mathfuncs_rcp.h | 12 |
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 |