本文整理汇总了C++中std::isinf方法的典型用法代码示例。如果您正苦于以下问题:C++ std::isinf方法的具体用法?C++ std::isinf怎么用?C++ std::isinf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::isinf方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: luaV_tostring
int luaV_tostring (lua_State *L, StkId obj) {
if (!ttisnumber(obj))
return 0;
else {
char s[LUAI_MAXNUMBER2STR];
lua_Number n = nvalue(obj);
// SPRING -- synced safety change
// -- need a custom number formatter?
if (isfinite(n)) {
lua_number2str(s, n);
}
else {
if (isnan(n)) {
strcpy(s, "nan");
}
else {
const int inf_type = isinf(n);
if (inf_type == 1) {
strcpy(s, "+inf");
} else if (inf_type == -1) {
strcpy(s, "-inf");
} else {
strcpy(s, "weird_number");
}
}
}
setsvalue2s(L, obj, luaS_new(L, s));
return 1;
}
}
示例2: while
/* solve a multi contact problem by using a global successive overrelaxation method
* with a local nonlinear solver
*/
prox_result reference_sequential_g_sor_prox::solve_multi_contact_problem_sor() {
bool converged = false;
bool diverged = false;
unsigned int iteration = 0;
while(!converged && !diverged && iteration < m_max_global_iterations) {
converged = true;
for(index_t i = 0; i < m_contacts.size(); ++i) {
contact & ci = m_contacts[i];
vec3 rhs = ci.c;
index_t cbegin = m_gij_rows[i];
index_t cend = m_gij_rows[i + 1];
//step 0. get contributions from all the other contacts (gij off-diagonal terms)
for(index_t j = cbegin; j < cend; ++j) {
index_t cj = m_gij_columns[j];
rhs = rhs + m_gij_blocks[j] * m_percussions[cj];
}
vec3 pold = m_percussions[i];
//step 1. solve a single contact under the assumption, that all others are known
vec3 pnew = solve_one_contact_problem_alart_curnier(ci, pold, rhs, m_tol_rel, m_tol_abs);
using std::abs;
//step 2. check for global convergence
converged &=
abs(pnew[0] - pold[0]) <= m_tol_rel * abs(pnew[0]) + m_tol_abs
&& abs(pnew[1] - pold[1]) <= m_tol_rel * abs(pnew[1]) + m_tol_abs
&& abs(pnew[2] - pold[2]) <= m_tol_rel * abs(pnew[2]) + m_tol_abs;
//and check whether a force became infinite or NaN
using std::isinf; using std::isnan;
diverged
|= isinf(pnew[0]) || isnan(pnew[0])
|| isinf(pnew[1]) || isnan(pnew[1])
|| isinf(pnew[2]) || isnan(pnew[2]);
m_percussions[i] = pnew;
}
++iteration;
}
std::cout << "done\n # iterations = " << iteration << std::endl;
return
converged ? CONVERGED
: (diverged ? DIVERGED
: (!(iteration < m_max_global_iterations) ? ITERATION_LIMIT_REACHED
/*: (time_limit_reached ? TIME_LIMIT_REACHED */: OOPS/*)*/));
}
示例3: requestRate
double Stat::requestRate(const uint64_t elapsed_t) const {
double rate = (getCount() / (double)elapsed_t);
if (isinf(rate)) {
return 1.0;
} else {
return rate;
}
}
示例4: solve_one_contact_problem_alart_curnier
std::pair<bool, bool> multicolor_parallel_g_sor_prox::work_function(
sub_problem const & sub,
index_t & l_i,
index_t & g_i,
index_t l_end,
std::vector<vec3> & percussions,
real tol_rel, real tol_abs,
index_t max_local_iterations
) {
bool diverged = false;
bool converged = true;
for(; l_i < l_end; ++l_i, ++g_i) {
contact const & ci = sub.contacts[l_i];
vec3 rhs = ci.c;
index_t cbegin = sub.gij_rows[l_i];
index_t cend = sub.gij_rows[l_i + 1];
//step 0. get contributions from all the other contacts (gij off-diagonal terms)
for(index_t j = cbegin; j < cend; ++j) {
index_t g_j = sub.gij_columns[j];
rhs = rhs + sub.gij_blocks[j] * percussions[g_j];
}
vec3 pold = percussions[g_i];
//step 1. solve a single contact under the assumption, that all others are known
vec3 pnew = solve_one_contact_problem_alart_curnier(ci, pold, rhs, tol_rel, tol_abs, max_local_iterations);
using std::abs;
//step 2. check for global convergence
converged &=
abs(pnew[0] - pold[0]) <= tol_rel * abs(pnew[0]) + tol_abs
&& abs(pnew[1] - pold[1]) <= tol_rel * abs(pnew[1]) + tol_abs
&& abs(pnew[2] - pold[2]) <= tol_rel * abs(pnew[2]) + tol_abs;
//and check whether a force became infinite or NaN
using std::isinf; using std::isnan;
diverged
|= isinf(pnew[0]) || isnan(pnew[0])
|| isinf(pnew[1]) || isnan(pnew[1])
|| isinf(pnew[2]) || isnan(pnew[2]);
percussions[g_i] = pnew;
}
return std::make_pair(converged, diverged);
}
示例5: if
// function that standarize printing NaN and Inf values on
// Windows (where they are in 1.#INF, 1.#NAN format) and all
// others platform
inline void
safe_double_print (double val)
{
if (isnan (val))
std::cout << "nan";
else if (isinf (val))
std::cout << "inf";
else
std::cout << val;
std::cout << '\n';
}
示例6: isinf
void R2d2lri::setBoundary(const Boundary& boundary)
{
if(boundary.isValid())
{
const double a = boundary.l(0);
const double b = boundary.u(0);
this->a = isinf(a) ? copysign(INFINITE, a) : a;
this->b = isinf(b) ? copysign(INFINITE, b) : b;
adapterSetFunctor(g, Constant(boundary.l(1)));
adapterSetFunctor(h, Constant(boundary.u(1)));
if(this->hasIntegrand())
{
this->setIntegrand(this->getIntegrand());
}
}
else
{
this->a = NaN;
this->b = NaN;
}
}
示例7: update
void EntityFollowSystem::update() {
for (Entity& e : this->getEntities()) {
// For each entity we have...
EntityFollowComponent& ef = e.getComponent<EntityFollowComponent>();
if (isinf(ef.maxSpeed) && ef.target.isValid() && ef.target.hasComponent<PositionComponent>()) {
// If the entity we're trying to face exists and has a position...
PositionComponent& pos = e.getComponent<PositionComponent>();
PositionComponent& follow_pos = ef.target.getComponent<PositionComponent>();
pos.position = follow_pos.position;
}
}
}
示例8: fromAscii
String::String(const double d) {
if (isinf(d)) {
if (copysign(1.0, d) == -1.0) {
fromAscii("-Infinity");
} else {
fromAscii("Infinity");
}
} else if (isnan(d)) {
fromAscii("NaN");
} else {
char * buf = static_cast<char*>(GC_MALLOC_ATOMIC(20));
sprintf(buf,"%.16g",d);
fromAscii(buf);
}
}
示例9: math_modf
static int math_modf (lua_State *L) {
// FIXME -- streflop does not have modf()
// double fp = math::modf(luaL_checknumber(L, 1), &ip);
const float in = (float)luaL_checknumber(L, 1);
if (isnan(in)) {
lua_pushnumber(L, in);
lua_pushnumber(L, in);
}
else if (isinf(in)) {
lua_pushnumber(L, in);
lua_pushnumber(L, 0.0f);
}
else {
const float fp = math::fmod(in, 1.0f);
const float ip = (in - fp);
lua_pushnumber(L, ip);
lua_pushnumber(L, fp);
}
return 2;
}
示例10: multi_student_t_log
typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
multi_student_t_log(const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
const T_dof& nu,
const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
const
Eigen::Matrix<T_scale,
Eigen::Dynamic,Eigen::Dynamic>& Sigma) {
static const char* function = "stan::prob::multi_student_t(%1%)";
using stan::math::check_size_match;
using stan::math::check_finite;
using stan::math::check_not_nan;
using stan::math::check_symmetric;
using stan::math::check_positive;
using boost::math::tools::promote_args;
using boost::math::lgamma;
using stan::math::log_determinant_ldlt;
using stan::math::mdivide_left_ldlt;
using stan::math::LDLT_factor;
typename promote_args<T_y,T_dof,T_loc,T_scale>::type lp(0.0);
if (!check_size_match(function,
y.size(), "Size of random variable",
mu.size(), "size of location parameter",
&lp))
return lp;
if (!check_size_match(function,
y.size(), "Size of random variable",
Sigma.rows(), "rows of scale parameter",
&lp))
return lp;
if (!check_size_match(function,
y.size(), "Size of random variable",
Sigma.cols(), "columns of scale parameter",
&lp))
return lp;
if (!check_finite(function, mu, "Location parameter", &lp))
return lp;
if (!check_not_nan(function, y, "Random variable", &lp))
return lp;
if (!check_symmetric(function, Sigma, "Scale parameter", &lp))
return lp;
LDLT_factor<T_scale,Eigen::Dynamic,Eigen::Dynamic> ldlt_Sigma(Sigma);
if (!ldlt_Sigma.success()) {
std::ostringstream message;
message << "Scale matrix is not positive definite. "
<< "Sigma(0,0) is %1%.";
std::string str(message.str());
stan::math::dom_err(function,Sigma(0,0),"Scale matrix",str.c_str(),"",&lp);
return lp;
}
// allows infinities
if (!check_not_nan(function, nu,
"Degrees of freedom parameter", &lp))
return lp;
if (!check_positive(function, nu,
"Degrees of freedom parameter", &lp))
return lp;
using std::isinf;
if (isinf(nu)) // already checked nu > 0
return multi_normal_log(y,mu,Sigma);
double d = y.size();
if (include_summand<propto,T_dof>::value) {
lp += lgamma(0.5 * (nu + d));
lp -= lgamma(0.5 * nu);
lp -= (0.5 * d) * log(nu);
}
if (include_summand<propto>::value)
lp -= (0.5 * d) * LOG_PI;
using stan::math::multiply;
using stan::math::dot_product;
using stan::math::subtract;
using Eigen::Array;
if (include_summand<propto,T_scale>::value) {
lp -= 0.5*log_determinant_ldlt(ldlt_Sigma);
}
if (include_summand<propto,T_y,T_dof,T_loc,T_scale>::value) {
Eigen::Matrix<typename promote_args<T_y,T_loc>::type,
Eigen::Dynamic,
1> y_minus_mu = subtract(y,mu);
Eigen::Matrix<typename promote_args<T_scale,T_y,T_loc>::type,
Eigen::Dynamic,
1> invSigma_dy = mdivide_left_ldlt(ldlt_Sigma, y_minus_mu);
lp -= 0.5
* (nu + d)
* log(1.0 + dot_product(y_minus_mu,invSigma_dy) / nu);
}
return lp;
//.........这里部分代码省略.........
示例11: ContactCondition
//.........这里部分代码省略.........
// transform meshes
NodeList transformNodes = bodyNode.getChildrenByName("transform");
for(auto& transformNode: transformNodes)
{
string transformType = transformNode["type"];
if ( transformType == "translate" )
{
real x = lexical_cast<real>(transformNode["moveX"]);
real y = lexical_cast<real>(transformNode["moveY"]);
real z = lexical_cast<real>(transformNode["moveZ"]);
LOG_DEBUG("Moving body: [" << x << "; " << y << "; " << z << "]");
localScene.transfer(x, y, z);
}
if ( transformType == "scale" )
{
real x0 = lexical_cast<real>(transformNode["x0"]);
real y0 = lexical_cast<real>(transformNode["y0"]);
real z0 = lexical_cast<real>(transformNode["z0"]);
real scaleX = lexical_cast<real>(transformNode["scaleX"]);
real scaleY = lexical_cast<real>(transformNode["scaleY"]);
real scaleZ = lexical_cast<real>(transformNode["scaleZ"]);
LOG_DEBUG("Scaling body: [" << x0 << "; " << scaleX << "; "
<< y0 << "; " << scaleY << "; " << z0 << "; " << scaleZ << "]");
localScene.scale(x0, y0, z0, scaleX, scaleY, scaleZ);
}
}
LOG_DEBUG("Mesh preloaded. Mesh size: " << localScene << " Number of nodes: " << numberOfNodes);
engine.getDispatcher()->addBodyOutline(id, localScene);
engine.getDispatcher()->addBodySlicingDirection(id, slicingDirection);
engine.getDispatcher()->addBodyNodesNumber(id, numberOfNodes);
if( isinf(globalScene.maxX) )
{
globalScene = localScene;
}
else
{
for( int k = 0; k < 3; k++ )
{
if( globalScene.min_coords[k] > localScene.min_coords[k] )
globalScene.min_coords[k] = localScene.min_coords[k];
if( globalScene.max_coords[k] < localScene.max_coords[k] )
globalScene.max_coords[k] = localScene.max_coords[k];
}
}
}
// add body to scene
engine.addBody(body);
}
engine.setScene(globalScene);
LOG_DEBUG("Total scene: " << engine.getScene());
// run dispatcher
engine.getDispatcher()->prepare(engine.getNumberOfWorkers(), &globalScene);
engine.getDataBus()->syncOutlines();
for( int i = 0; i < engine.getNumberOfWorkers(); i++)
{
LOG_DEBUG("Area scheduled for worker " << i << ": " << *(engine.getDispatcher()->getOutline(i)));
}
// read meshes for all bodies
for(auto& bodyNode: bodyNodes)
示例12: multi_student_t_log
typename boost::math::tools::promote_args<T_y,T_dof,T_loc,T_scale>::type
multi_student_t_log(const Eigen::Matrix<T_y,Eigen::Dynamic,1>& y,
const T_dof& nu,
const Eigen::Matrix<T_loc,Eigen::Dynamic,1>& mu,
const
Eigen::Matrix<T_scale,
Eigen::Dynamic,Eigen::Dynamic>& Sigma,
const Policy&) {
static const char* function = "stan::prob::multi_student_t(%1%)";
using stan::math::check_size_match;
using stan::math::check_finite;
using stan::math::check_not_nan;
using stan::math::check_symmetric;
using stan::math::check_positive;
using stan::math::check_pos_definite;
using boost::math::tools::promote_args;
typename promote_args<T_y,T_dof,T_loc,T_scale>::type lp(0.0);
if (!check_size_match(function,
y.size(), "Size of random variable",
mu.size(), "size of location parameter",
&lp, Policy()))
return lp;
if (!check_size_match(function,
y.size(), "Size of random variable",
Sigma.rows(), "rows of scale parameter",
&lp, Policy()))
return lp;
if (!check_size_match(function,
y.size(), "Size of random variable",
Sigma.cols(), "columns of scale parameter",
&lp, Policy()))
return lp;
if (!check_finite(function, mu, "Location parameter", &lp, Policy()))
return lp;
if (!check_not_nan(function, y, "Random variable", &lp, Policy()))
return lp;
if (!check_symmetric(function, Sigma, "Scale parameter", &lp, Policy()))
return lp;
if (!check_pos_definite(function, Sigma, "Scale parameter", &lp, Policy()))
return lp;
// allows infinities
if (!check_not_nan(function, nu,
"Degrees of freedom parameter", &lp,
Policy()))
return lp;
if (!check_positive(function, nu,
"Degrees of freedom parameter", &lp,
Policy()))
return lp;
using std::isinf;
if (isinf(nu)) // already checked nu > 0
return multi_normal_log(y,mu,Sigma,Policy());
/*
Eigen::LLT< Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> > LLT = Sigma.llt();
if (LLT.info() != Eigen::Success) {
lp = stan::math::policies::raise_domain_error<T_scale>(function,
"Sigma is not positive definite (%1%)",
0,Policy());
return lp;
}
Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> L = LLT.matrixL();
*/
double d = y.size();
if (include_summand<propto,T_dof>::value) {
lp += lgamma(0.5 * (nu + d));
lp -= lgamma(0.5 * nu);
lp -= (0.5 * d) * log(nu);
}
if (include_summand<propto>::value)
lp -= (0.5 * d) * LOG_PI;
using stan::math::multiply;
// using stan::math::dot_self;
using stan::math::dot_product;
using stan::math::subtract;
using Eigen::Array;
// using stan::math::mdivide_left_tri;
using stan::math::mdivide_left;
using stan::math::log_determinant;
if (include_summand<propto,T_scale>::value) {
// lp -= L.diagonal().array().log().sum();
lp -= 0.5*log_determinant(Sigma);
}
if (include_summand<propto,T_y,T_dof,T_loc,T_scale>::value) {
// Eigen::Matrix<T_scale,Eigen::Dynamic,Eigen::Dynamic> I(d,d);
// I.setIdentity();
Eigen::Matrix<typename promote_args<T_y,T_loc>::type,
Eigen::Dynamic,
//.........这里部分代码省略.........
示例13: WsolveWKT
int WsolveWKT(double *W, double *gamma, double *T,
double qdotn, double qdotb, double Q2, double B2, double D)
{
Iterations = 0;
int fail = 0;
int count = 0;
int Nmax = 30;
int Nmax2 = 30;
int Nmaxsafe = 100;
int Nextra = 5;
double x = *W;
double y = pow(*gamma,2.0)-1.0;
double z = *T;
double Told = z;
double err1,err2,err3;
double error = 1.0;
double deltax,deltay,deltaz;
while (error>NR_TOL && fail==0) {
fghWKT(x,y,z,&deltax,&deltay,&deltaz,qdotn,qdotb,Q2,B2,D,&err1,&err2,&err3);
count++;
error = NR_ERROR;
if (verbose) {
printf("W=%e K=%e T=%e dx=%e dy=%e dz=%e error=%e\n",
x,y,z,deltax,deltay,deltaz,error);
}
if (isnan(deltax) || isinf(deltax)) { deltax=0.0; error=1.0; }
if (isnan(deltay) || isinf(deltay)) { deltay=0.0; error=1.0; }
if (isnan(deltaz) || isinf(deltaz)) { deltaz=0.0; error=1.0; }
x += deltax;
y += deltay;
z += deltaz;
if (y < 0.0) y = 0.0;
if (y>YMAX || count>=Nmax) {
fail = 1;
}
++Iterations;
}
if (fail==1) {
if (verbose) {
printf("Resetting...\n");
}
count = 0;
fail = 0;
error = 1.0;
y = (qdotb*qdotb + 2.0*Q2*D)/(B2*D*D + 2.0*D*D*D);
z = Told;
double a = qdotn + .5*B2*(y+2.0)/(y+1.0);
double b = -qdotb;
x = - (b + a*a*a)/(pow(b*b,1./3.)+a*a);
while (error>NR_TOL && fail==0) {
fghWKT(x,y,z,&deltax,&deltay,&deltaz,qdotn,qdotb,Q2,B2,D,&err1,&err2,&err3);
count++;
error = NR_ERROR;
if (verbose) {
printf("W=%e K=%e T=%e dx=%e dy=%e dz = %e error = %e\n",
x,y,z,deltax,deltay,deltaz,error);
}
if (isnan(deltax) || isinf(deltax)) { deltax=0.0; error=1.0; }
if (isnan(deltay) || isinf(deltay)) { deltay=0.0; error=1.0; }
if (isnan(deltaz) || isinf(deltaz)) { deltaz=0.0; error=1.0; }
x += deltax;
y += deltay;
z += deltaz;
if (y < 0.0) y = 0.0;
if (y>YMAX || count>=Nmax2) {
fail = 1;
}
++Iterations;
}
}
if (fail==1) {
if (verbose) {
printf("Resetting...\n");
}
count = 0;
fail = 0;
z = eos->Temperature_u(D / *gamma, -qdotn-D-.5*B2);
double P = eos->Pressure(D, z);
//.........这里部分代码省略.........
示例14: hasInf
bool hasInf() const {
using std::isinf;
return isinf(this->x) || isinf(this->y) || isinf(this->z);
}