本文整理汇总了C++中remainder函数的典型用法代码示例。如果您正苦于以下问题:C++ remainder函数的具体用法?C++ remainder怎么用?C++ remainder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remainder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Lind-Project,项目名称:native_client,代码行数:29,代码来源:float_math.c
示例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);
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:8,代码来源:math_h.pass.cpp
示例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
}
开发者ID:jossk,项目名称:open-watcom-v2,代码行数:9,代码来源:mathtest.c
示例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;
}
}
}
开发者ID:Aly1029,项目名称:LibreCAD,代码行数:57,代码来源:rs_grid.cpp
示例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);
}
开发者ID:shijinqiao,项目名称:libcanplusplus,代码行数:12,代码来源:DeviceELMOSteeringMotorVel.cpp
示例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;
}
开发者ID:keily,项目名称:avalon-1,代码行数:53,代码来源:SailMotor.cpp
示例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;
}
开发者ID:c-a,项目名称:Impa,代码行数:12,代码来源:uva-12395.cpp
示例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));
}
}
开发者ID:Aly1029,项目名称:LibreCAD,代码行数:19,代码来源:rs_grid.cpp
示例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;
}
开发者ID:trailofbits,项目名称:cb-multios,代码行数:50,代码来源:accelfunc.c
示例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;
}
开发者ID:eseidel,项目名称:native_client_patches,代码行数:16,代码来源:float_math.c
示例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;
}
开发者ID:Joeycc,项目名称:LibreCAD,代码行数:37,代码来源:rs_information.cpp
示例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;
}
开发者ID:Lordgreger,项目名称:Projekt-E15,代码行数:35,代码来源:CRC.cpp
示例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
}
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:25,代码来源:test-rem.c
示例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);
}
开发者ID:mikekmv,项目名称:aeriebsd-src,代码行数:28,代码来源:n_sincos.c
示例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 );
}
}
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:26,代码来源:mldiv.cpp
示例16: LTFAT_NAME_COMPLEX
LTFAT_API int
LTFAT_NAME_COMPLEX(fftrealcircshift)( const LTFAT_COMPLEX* in, ltfat_int L,
const double shift, LTFAT_COMPLEX* out)
{
ltfat_div_t domod;
double shiftLoc;
int status = LTFATERR_SUCCESS;
CHECKNULL(in); CHECKNULL(out);
CHECK(LTFATERR_BADSIZE, L > 0, "L must be positive");
domod = ltfat_idiv(L, 2);
shiftLoc = remainder(shift, L);
if (shiftLoc != 0)
{
LTFAT_COMPLEX phasefact = -I * (LTFAT_REAL)(2.0 * M_PI * shiftLoc) / ((
LTFAT_REAL) L);
out[0] = in[0];
for (int ii = 1; ii < domod.quot + 1; ii++)
out[ii] = exp((LTFAT_REAL)ii * phasefact) * in[ii];
}
else
{
if (in != out)
memcpy(out, in, (domod.quot + 1) * sizeof * out);
}
error:
return status;
}
开发者ID:ltfat,项目名称:ltfat,代码行数:32,代码来源:utils.c
示例17: main
int main (int argc, char* argv[])
{
int code, shares;
float prevCPS, currCPS,prevCPSVal, currCPSVal, percentChange;
scanf("%d %d %f %f", &code, &shares, &prevCPS, &currCPS);
prevCPSVal = prevCPS*shares;
currCPSVal = currCPS*shares;
if (prevCPSVal > 999)
{
double prevFloor = floor(prevCPS);
double prevRem = remainder (prevCPSVal,1000);
}
//What percent of 12000, is 11930?
//11930/12000 = .994166667
//1-.994166667 = .005833 which is almost .6%
//equation, (1-(prevworth/currworth))
percentChange = ((currCPSVal-prevCPSVal)/prevCPSVal)*10;
printf("%s", "Code Shares Prev CPS Curr CPS Prev Worth Curr Worth Change(%)\n");
printf("%s", "-----------------------------------------------------------------\n");
printf("%d %d $%.2f $%.2f $%.2f $%.2f %.1f\n", code, shares, prevCPS, currCPS, prevCPSVal, currCPSVal, percentChange*10);
return 0;
}
开发者ID:Adondriel,项目名称:CollegePortfolio,代码行数:25,代码来源:lab2.c
示例18: main
int main(){
int x,y;
printf("Please input two integer numbers:");
scanf("%d %d",&x,&y);
printf("Remainde=%d\n",remainder(x,y));
return 0;
}
开发者ID:Jing0,项目名称:C_Program_Design_E4,代码行数:7,代码来源:lab8-3.c
示例19: lex
// -----------------------------------------------------------------------------
// SIPCodecUtils::ValueWithoutQuotes
// -----------------------------------------------------------------------------
//
TInt SIPCodecUtils::ValueWithoutQuotes(
const TDesC8& aValue,
TPtrC8& aWithoutQuotes)
{
if (aValue.Length() > 0)
{
TLex8 lex(aValue);
lex.SkipSpace();
if (lex.Get() == '"')
{
// Remove first quote
TPtrC8 remainder(aValue.Mid(1));
// Ensure that ending quote exists.
if(remainder.LocateReverse('"') != (remainder.Length()-1))
{
return KErrArgument;
}
aWithoutQuotes.Set(remainder.Left(remainder.Length()-1));
}
else
{
return KErrArgument;
}
}
return KErrNone;
}
开发者ID:kuailexs,项目名称:symbiandump-mw1,代码行数:30,代码来源:SIPCodecUtils.cpp
示例20: cos
double
cos(double x)
{
double a,c,z,s = 1.0;
if(!finite(x)) /* cos(NaN) and cos(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] */
a = PI-a;
s = negone;
}
else { /* ... in [PI/4,3PI/4] */
a = PIo2-a;
return a+a*sin__S(a*a); /* rtn. S(PI/2-|x|) */
}
}
if (a < small) {
big+a;
return s; /* rtn. s*C(a) */
}
z = a*a;
c = cos__C(z);
z *= half;
a = (z >= thresh ? half-((z-half)-c) : one-(z-c));
return copysign(a,s);
}
开发者ID:mikekmv,项目名称:aeriebsd-src,代码行数:29,代码来源:n_sincos.c
注:本文中的remainder函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论