Macaulay2 Engine
Loading...
Searching...
No Matches

◆ mod()

const mpreal mpfr::mod ( const mpreal & x,
const mpreal & y,
mp_rnd_t rnd_mode = mpreal::get_default_rnd() )
inline

Definition at line 2634 of file mpreal.h.

2635{
2636 (void)rnd_mode;
2637
2638 /*
2639
2640 m = mod(x,y) if y != 0, returns x - n*y where n = floor(x/y)
2641
2642 The following are true by convention:
2643 - mod(x,0) is x
2644 - mod(x,x) is 0
2645 - mod(x,y) for x != y and y != 0 has the same sign as y.
2646
2647 */
2648
2649 if(iszero(y)) return x;
2650 if(x == y) return 0;
2651
2652 mpreal m = x - floor(x / y) * y;
2653
2654 return copysign(abs(m),y); // make sure result has the same sign as Y
2655}
mpreal copysign(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
Definition mpreal.h:2135
bool iszero(const mpreal &op)
Definition mpreal.h:1747
const mpreal floor(const mpreal &v)
Definition mpreal.h:2733
volatile int x
#define abs(x)
Definition polyroots.cpp:51