本文整理汇总了C++中numeric::Ptr::isZero方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::isZero方法的具体用法?C++ Ptr::isZero怎么用?C++ Ptr::isZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numeric::Ptr
的用法示例。
在下文中一共展示了Ptr::isZero方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: divide
/** Returns a Numeric object which is the quotient of this and other */
Numeric::Ptr ATFloatOrDerivedImpl::divide(const Numeric::Ptr &other, const DynamicContext* context) const {
if(other->getPrimitiveTypeIndex() == AnyAtomicType::DECIMAL) {
// if other is a decimal, promote it to xs:float
return this->divide((const Numeric::Ptr )other->castAs(this->getPrimitiveTypeIndex(), context), context);
} else if (other->getPrimitiveTypeIndex() == AnyAtomicType::DOUBLE) {
// if other is a double, promote this to xs:double
return ((const Numeric::Ptr )this->castAs(other->getPrimitiveTypeIndex(), context))->divide(other, context);
} else if (other->getPrimitiveTypeIndex() == AnyAtomicType::FLOAT) {
// same primitive type, can make comparison
ATFloatOrDerivedImpl* otherImpl = (ATFloatOrDerivedImpl*)(const Numeric*)other;
if(otherImpl->_state == NaN) return notANumber(context);
switch (_state) {
case NaN:
return notANumber(context);
case INF: {
switch(otherImpl->_state) {
case NaN:
return notANumber(context); // case taken care of above
case NEG_NUM:
case NUM:
return other->isPositive() ? infinity(context) : negInfinity(context); // INF / NUM = +/-INF
case INF:
return notANumber(context); // INF / INF = NaN
case NEG_INF:
return notANumber(context); // INF / (-INF) = NaN
default:
assert(false);
return 0; // should never get here
} // switch
}// case
case NEG_INF: {
switch(otherImpl->_state) {
case NaN:
return notANumber(context); //case taken care of above
case NEG_NUM:
case NUM:
return other->isPositive() ? negInfinity(context) : infinity(context); // -INF / NUM = -INF
case INF:
return notANumber(context); // -INF / INF = NaN
case NEG_INF:
return notANumber(context); // -INF / (-INF) = NaN
default:
assert(false);
return 0; // should never get here
} // switch
} // case
case NEG_NUM:
case NUM: {
switch(otherImpl->_state) {
case NaN:
return notANumber(context); // case taken care of above
case INF: { // NUM / INF = +/-0
if(this->isNegative()) {
return negZero(context);
} else {
return newFloat(0, context);
}
}// case
case NEG_INF: { // NUM / -INF = +/-0
if(this->isPositive()) {
return negZero(context);
} else {
return newFloat(0, context);
}
}// case
case NEG_NUM:
case NUM: {
if(other->isZero()) {
if(this->isZero()) return notANumber(context);
if((this->isNegative() && other->isPositive()) ||
(this->isPositive() && other->isNegative())) {
return negInfinity(context); // NUM / (-0) or (-NUM) / 0 = -INF
} else {
return infinity(context); // NUM / 0 or (-NUM) / (-0) = INF
}
}
else if(this->isZero())
{
if((this->isNegative() && other->isPositive()) ||
(this->isPositive() && other->isNegative())) {
return negZero(context); // 0 / (-NUM) or (-0) / NUM = -0
} else {
return newFloat(0, context); // 0 / NUM or (-0) / (-NUM) = 0
}
}
return newFloat(_float / otherImpl->_float, context);
}// case
default:
assert(false);
return 0; // should never get here
}// switch
}// case
default:
assert(false);
return 0; // should never get here
}// switch
} else {
assert(false); // should never get here, numeric types are xs:decimal, xs:float, xs:integer and xs:double
//.........这里部分代码省略.........