本文整理汇总了C++中remainder函数的典型用法代码示例。如果您正苦于以下问题:C++ remainder函数的具体用法?C++ remainder怎么用?C++ remainder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remainder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_errs
/* Test NaN-resulting library calls. */
int test_errs(void) {
int errs = 0;
/*
* Attempt to prevent constant folding and optimization of library
* function bodies (when statically linked).
*/
volatile double x;
volatile double y;
printf("Checking well-defined library errors\n");
x = -3.0; y = 4.4;
errs += CHECK_NAN(pow(x, y));
errs += CHECK_NAN(log(x));
x = -0.001;
errs += CHECK_NAN(sqrt(x));
x = 1.0001;
errs += CHECK_NAN(asin(x));
x = INFINITY;
errs += CHECK_NAN(sin(x));
errs += CHECK_NAN(cos(x));
x = 0.999;
errs += CHECK_NAN(acosh(x));
x = 3.3; y = 0.0;
errs += CHECK_NAN(remainder(x, y));
y = INFINITY;
errs += CHECK_NAN(remainder(y, x));
return errs;
}
示例2: test_remainder
void test_remainder()
{
static_assert((std::is_same<decltype(remainder((double)0, (double)0)), double>::value), "");
static_assert((std::is_same<decltype(remainderf(0,0)), float>::value), "");
static_assert((std::is_same<decltype(remainderl(0,0)), long double>::value), "");
static_assert((std::is_same<decltype(remainder((int)0, (int)0)), double>::value), "");
assert(remainder(0.5,1) == 0.5);
}
示例3: test_fp_remainder
void test_fp_remainder( void )
{
#if __STDC_VERSION__ >= 199901L
printf( "Testing C99 remainder function...\n" );
VERIFY( CompDbl( remainder( 2.01, 1.0 ), 0.01 ) );
VERIFY( CompDbl( remainder( 4.99, 2.0 ), 0.99 ) );
#endif
}
示例4: bp0
void RS_Grid::createIsometricGrid(LC_Rect const& rect, RS_Vector const& gridWidth)
{
double const left=rect.minP().x;
double const right=rect.maxP().x;
//top/bottom reversed
double const top=rect.maxP().y;
double const bottom=rect.minP().y;
int numberY = (RS_Math::round((top-bottom) / gridWidth.y) + 1);
double dx=sqrt(3.)*gridWidth.y;
cellV.set(fabs(dx),fabs(gridWidth.y));
double hdx=0.5*dx;
double hdy=0.5*gridWidth.y;
int numberX = (RS_Math::round((right-left) / dx) + 1);
int number = 2*numberX*numberY;
baseGrid.set(left+remainder(-left,dx),bottom+remainder(-bottom,fabs(gridWidth.y)));
if (number<=0 || number>maxGridPoints) return;
pt.resize(number);
int i=0;
RS_Vector bp0(baseGrid),dbp1(hdx,hdy);
for (int y=0; y<numberY; ++y) {
RS_Vector bp1(bp0);
for (int x=0; x<numberX; ++x) {
pt[i++] = bp1;
pt[i++] = bp1+dbp1;
bp1.x += dx;
}
bp0.y += gridWidth.y;
}
//find metaGrid
if (metaGridWidth.y>minimumGridWidth &&
graphicView->toGuiDY(metaGridWidth.y)>2) {
metaGridWidth.x=(metaGridWidth.x<0.)?-sqrt(3.)*fabs(metaGridWidth.y):sqrt(3.)*fabs(metaGridWidth.y);
RS_Vector baseMetaGrid(left+remainder(-left,metaGridWidth.x)-fabs(metaGridWidth.x),bottom+remainder(-bottom,metaGridWidth.y)-fabs(metaGridWidth.y));
// calculate number of visible meta grid lines:
int numMetaX = (RS_Math::round((right-left) / metaGridWidth.x) + 1);
int numMetaY = (RS_Math::round((top-bottom) / metaGridWidth.y) + 1);
if (numMetaX<=0 || numMetaY<=0) return;
// create meta grid arrays:
metaX.resize(numMetaX);
metaY.resize(numMetaY);
double x0(baseMetaGrid.x);
for (int i=0; i<numMetaX; x0 += metaGridWidth.x) {
metaX[i++] = x0;
}
x0=baseMetaGrid.y;
for (int i=0; i<numMetaY; x0 += metaGridWidth.y) {
metaY[i++] = x0;
}
}
}
示例5: remainder
void DeviceELMOSteeringMotorVel::setProfilePosition(double jointPosition_rad, double jointVelocity_rad_s)
{
const double Ke = -1.0;
double command_pos = remainder(jointPosition_rad,M_PI);
double position_error = remainder(command_pos - getPosition(), 2*M_PI);
double command_vel = Ke * position_error;
if (command_vel > jointVelocity_rad_s) {command_vel = jointVelocity_rad_s;}
if (command_vel <-jointVelocity_rad_s) {command_vel =-jointVelocity_rad_s;}
printf("%d:Pos control: C %.2f S %.2f O %.2f\n",nodeId_,jointPosition_rad,
getPosition(), command_vel);
setProfileVelocity(command_vel);
}
示例6: epos_get_actual_position
bool SailMotor::move_to_angle(float degrees, float reference, int& feedback, int& num_rounds) {
float position;
int target = 0;
if(degrees <= 180 && degrees >= -180) {
// get feedback
epos_get_actual_position(AV_SAIL_NODE_ID);
feedback = epos_read.node[AV_SAIL_NODE_ID-1].actual_position;
position = (feedback / (AV_SAIL_TICKS_PER_DEGREE))-reference;
// num_rounds = (feedback + 180 * AV_SAIL_TICKS_PER_DEGREE) / (360 * AV_SAIL_TICKS_PER_DEGREE);
// num_rounds = (int)round((position+180.0*sign(position))/360.0);
num_rounds = (int)round((position)/360.0);
//rtx_message("num_ro: %d, feedback: %d", num_rounds, feedback);
//num_rounds = (position+180.0)/360.0;
position = remainder(position, 360.0);
if(fabs(degrees - position) > 180.0)
{
num_rounds -= 1*sign(remainder((position - degrees),360.0));
}
//rtx_message("pos: %f, num_ro: %d", position, num_rounds);
// Go to position
target = (int)round(AV_SAIL_TICKS_PER_DEGREE * (degrees + reference + num_rounds*360));
epos_set_target_position(AV_SAIL_NODE_ID, target);
// rtx_message("num_ro: %d, position: %f, target: %f", num_rounds, position, target/AV_SAIL_TICKS_PER_DEGREE*1.0);
//rtx_message("current: %f; %d, goal: %f; %d", position, feedback, degrees, target);
epos_activate_position(AV_SAIL_NODE_ID);
}
else {
rtx_message("WARNING: A Sail angle beyond +-180 deg has been asked for. (at %f) Skipping...", degrees);
return false;
}
#if 0
if(degrees <= AV_MAX_SAIL_ANGLE && degrees >= -AV_MAX_SAIL_ANGLE) {
// Go to position
epos_set_target_position(AV_SAIL_NODE_ID,(int)round((degrees+reference)*AV_SAIL_TICKS_PER_DEGREE));
epos_activate_position(AV_SAIL_NODE_ID);
// and get feedback
epos_get_actual_position(AV_SAIL_NODE_ID);
feedback = epos_read.node[AV_SAIL_NODE_ID-1].actual_position;
}
else {
rtx_message("WARNING: A Sail angle beyond the max sail angle has been asked for. (at %f) Skipping...", degrees);
return false;
}
#endif
return true;
}
示例7: smallestN
int smallestN(double r1, double r2, double r3) {
double radianEPS = 1e-7;
for (int n = 3; n <= 1000; ++n) {
double segmentAngle = M_PI / n;
double rem1 = remainder(r1, segmentAngle);
double rem2 = remainder(r2, segmentAngle);
double rem3 = remainder(r3, segmentAngle);
if (fabs(rem1) < radianEPS && fabs(rem2) < radianEPS
&& fabs(rem3) < radianEPS) return n;
}
return -1;
}
示例8: vp
/**
* find the closest grid point
*@return the closest grid to given point
*@coord: the given point
*/
RS_Vector RS_Grid::snapGrid(const RS_Vector& coord) const {
if( cellV.x<RS_TOLERANCE || cellV.y<RS_TOLERANCE) return coord;
RS_Vector vp(coord-baseGrid);
if(isometric){
//use remainder instead of fmod to locate the left-bottom corner for both positive and negative displacement
RS_Vector vp1( vp-RS_Vector( remainder(vp.x-0.5*cellV.x,cellV.x)+0.5*cellV.x, remainder(vp.y-0.5*cellV.y,cellV.y)+0.5*cellV.y));
RS_VectorSolutions sol({vp1,vp1+cellV,vp1+cellV*0.5, vp1+RS_Vector(cellV.x,0.), vp1+RS_Vector(0.,cellV.y)});
vp1=sol.getClosest(vp);
return baseGrid+vp1;
}else{
return baseGrid+vp-RS_Vector(remainder(vp.x,cellV.x),remainder(vp.y,cellV.y));
}
}
示例9: handle_op_power
double handle_op_power(stack_t **args, int *is_bad_formula)
{
if (*args == NULL)
goto error;
double result = 0.0, operand1, operand2;
char *front;
// Get first operand
front = pop_copy(args);
if (front == NULL)
goto error;
operand1 = atof(front, cgc_strlen(front) + 1, is_bad_formula);
free(front);
if(*is_bad_formula)
goto error;
// Get second operand
front = pop_copy(args);
if (front == NULL)
goto error;
operand2 = atof(front, cgc_strlen(front) + 1, is_bad_formula);
free(front);
if(*is_bad_formula)
goto error;
if (*args != NULL)
goto error; // Too many arguments
if (operand2 == 0.0)
result = 1.0;
else if (operand2 == 1.0)
result = operand1;
else if (isnan(operand2))
result = operand2;
else if (operand1 == 0 && operand2 > 0)
result = 0.0;
else if (operand1 < 0 && remainder(operand2, 1) == 0.0)
result = pow(-operand1, operand2) * (remainder(operand2, 2) == 0 ? 1 : -1);
else
result = pow(operand1, operand2);
goto done;
error:
clear_stack(args);
*is_bad_formula = 1;
result = 0.0;
done:
return result;
}
示例10: test_errs
/* Test NaN-resulting library calls. */
int test_errs() {
int errs = 0;
printf("Checking well-defined library errors\n");
errs += CHECK_NAN(pow(-3.0, 4.4));
errs += CHECK_NAN(log(-3.0));
errs += CHECK_NAN(sqrt(-0.001));
errs += CHECK_NAN(asin(1.0001));
errs += CHECK_NAN(sin(INFINITY));
errs += CHECK_NAN(cos(INFINITY));
errs += CHECK_NAN(acosh(0.999));
errs += CHECK_NAN(remainder(3.3, 0.0));
errs += CHECK_NAN(remainder(INFINITY, 3.3));
return errs;
}
示例11: fabs
/**
* @return Intersection between two lines.
*/
RS_VectorSolutions RS_Information::getIntersectionLineLine(RS_Line* e1,
RS_Line* e2) {
RS_VectorSolutions ret;
if (!(e1 && e2)) {
RS_DEBUG->print("RS_Information::getIntersectionLineLin() for nullptr entities");
return ret;
}
RS_Vector p1 = e1->getStartpoint();
RS_Vector p2 = e1->getEndpoint();
RS_Vector p3 = e2->getStartpoint();
RS_Vector p4 = e2->getEndpoint();
double num = ((p4.x-p3.x)*(p1.y-p3.y) - (p4.y-p3.y)*(p1.x-p3.x));
double div = ((p4.y-p3.y)*(p2.x-p1.x) - (p4.x-p3.x)*(p2.y-p1.y));
if (fabs(div)>RS_TOLERANCE &&
fabs(remainder(e1->getAngle1()-e2->getAngle1(), M_PI))>=RS_TOLERANCE*10.) {
double u = num / div;
double xs = p1.x + u * (p2.x-p1.x);
double ys = p1.y + u * (p2.y-p1.y);
ret = RS_VectorSolutions({RS_Vector(xs, ys)});
}
// lines are parallel
else {
ret = RS_VectorSolutions();
}
return ret;
}
示例12: divisor
std::string CRC::runCRC(std::string message)
{
std::string messageString = message; //Original besked
std::string poly = "111010101"; //Polynomial division
std::string aug = messageString + "00000000"; //Padded besked, bliver senere til remainder indtil denne bliver checksummen
std::string tempRemainderString;
std::string tempAug;
std::bitset<9> divisor(poly); //Bit divisor
std::bitset<9> tempRemainder; //holder til besked
while (aug.size() > 8) //imens beskeden er større end 8 (size of checksum!)
{
std::bitset<9> remainder(std::string(aug, 0, 9)); //Tag de 9 første bit
if (remainder[8] == 1) //Hvis det første bit er sat (!!! Dette læses bitvist, fra højre mod venstre!!!)
{
tempRemainder = remainder ^ divisor; //Udfør polynomial division via "xor"
tempRemainderString = tempRemainder.to_string();
tempAug = "";
tempAug.append(aug, 9, aug.size());
aug = tempRemainderString + tempAug; //Saml resultat og resterende besked
}
else //Hvis det første bit ikke er sat, så skal beskeden shiftes mod venstre
{
aug.erase(aug.begin()); //Sletter det første bit i beskeden
}
}
//std::cout << "checksum: " << aug << std::endl; //Output checksum
return aug;
}
示例13: test_invalid
static void
test_invalid(long double x, long double y)
{
int q;
q = 0xdeadbeef;
assert(isnan(remainder(x, y)));
assert(isnan(remquo(x, y, &q)));
#ifdef STRICT
assert(q == 0xdeadbeef);
#endif
assert(isnan(remainderf(x, y)));
assert(isnan(remquof(x, y, &q)));
#ifdef STRICT
assert(q == 0xdeadbeef);
#endif
assert(isnan(remainderl(x, y)));
assert(isnan(remquol(x, y, &q)));
#ifdef STRICT
assert(q == 0xdeadbeef);
#endif
}
示例14: sin
double
sin(double x)
{
double a,c,z;
if(!finite(x)) /* sin(NaN) and sin(INF) must be NaN */
return x-x;
x=remainder(x,PI2); /* reduce x into [-PI,PI] */
a=copysign(x,one);
if (a >= PIo4) {
if(a >= PI3o4) /* ... in [3PI/4,PI] */
x = copysign((a = PI-a),x);
else { /* ... in [PI/4,3PI/4] */
a = PIo2-a; /* rtn. sign(x)*C(PI/2-|x|) */
z = a*a;
c = cos__C(z);
z *= half;
a = (z >= thresh ? half-((z-half)-c) : one-(z-c));
return copysign(a,x);
}
}
if (a < small) { /* rtn. S(x) */
big+a;
return x;
}
return x+x*sin__S(x*x);
}
示例15: division
static void division( MLDiv const &x, MLDiv const &y,
MLDiv &q, MLDiv &r ) {
UBIG m;
UBIG n;
UBIG y1;
m = length( y );
if( m == 1 ) {
y1 = y.d[ m - 1 ];
if( y1 > 0 ) {
quotient( q, x, y1 );
remainder( r, x, y1 );
} else {
fatal( "divide by 0" );
}
} else {
n = length( x );
if( m > n ) {
zero( q );
r = x;
} else {
assert( 2 <= m && m <= n && n <= w );
longdivide( x, y, q, r, n, m );
}
}
}