Shape::Shape(const EllipseInfo& info) noexcept : mEllipseInfo(info), mType(Type::ELLIPSE) { TRJ_ASSERT(isPositive(info.horizontalRadius), "Invalid horizontal radius"); TRJ_ASSERT(isPositive(info.verticalRadius), "Invalid vertical radius"); }
// note that the statistics is given for disjunctions, // so inversed (neg) values are taken into account bool DLDag :: less ( BipolarPointer p1, BipolarPointer p2 ) const { # ifdef ENABLE_CHECKING fpp_assert ( isValid(p1) && isValid(p2) ); # endif // idea: any positive entry should go first if ( preferNonGen ) { if ( isNegative(p1) && isPositive(p2) ) return true; if ( isPositive(p1) && isNegative(p2) ) return false; } const DLVertex& v1 = (*this)[p1]; const DLVertex& v2 = (*this)[p2]; /* // prefer non-cyclical if ( !v1.isInCycle(false) && v2.isInCycle(false) ) return true; if ( !v2.isInCycle(false) && v1.isInCycle(false) ) return false; */ DLVertex::StatType key1 = v1.getStat(iSort); DLVertex::StatType key2 = v2.getStat(iSort); // return "less" wrt sortAscend if ( sortAscend ) return key1 < key2; else return key2 < key1; }
bool ZActionActivator::isPositive(const ZStackFrame *frame) const { if (frame == NULL) { return false; } return isPositive(frame->document().get()) && isPositive(frame->presenter()); }
void FluctuatingChargeParameters::validate() { CheckParameter(Propagator, isEqualIgnoreCase("NVT") || isEqualIgnoreCase("Langevin") || isEqualIgnoreCase("Minimizer") || isEqualIgnoreCase("Exact") ); CheckParameter(Friction, isNonNegative()); CheckParameter(Tolerance, isPositive()); CheckParameter(MaxIterations, isPositive()); CheckParameter(TargetTemp, isNonNegative()); CheckParameter(TauThermostat, isPositive()); CheckParameter(DragCoefficient, isPositive()); }
void POP3ClientSession::login(const std::string& username, const std::string& password) { std::string response; _socket.receiveMessage(response); if (!isPositive(response)) throw POP3Exception("The POP3 service is unavailable", response); sendCommand("USER", username, response); if (!isPositive(response)) throw POP3Exception("Login rejected for user", response); sendCommand("PASS", password, response); if (!isPositive(response)) throw POP3Exception("Password rejected for user", response); }
bool SignedInteger<MD, DT, NT>::operator>(const SignedInteger<MD, DT, NT> &n) const { if (isNegative() && n.isPositive()) return(false); else if (isPositive() && n.isNegative()) return(true); else if (isPositive()) return number_ > n.number_; else return number_ < n.number_; }
bool RobotWidget::setInt(QLabel* label, double value) { bool converted = false; double current = label->text().replace(QString("%"), QString("")).toDouble(&converted); // Conversion to double failed if (!converted) { ROS_ERROR("Cannot convert received value to double, update has been aborted"); return false; } // Invalid range if (!isPositive(value)) { ROS_ERROR("Non positive values are not allowed, update has been aborted"); ROS_ERROR("%f", value); return false; } // Value has been changed if (current != value) { QString displayed_value = QString::number(ceil(value)); label->setText(displayed_value+"%"); return true; } // No update needed return false; }
Rect TextNode::generateBoundingBox() { Rect boundingBox = Node::generateBoundingBox(); if(mFontColor.isVisible()) { NVGcontext& nanoVgContext = Application::getNanoVgContext(); nvgSave(&nanoVgContext); float bounds[4]; setupContext(nanoVgContext); for(const Text& text : mTexts) { const char* charArray = text.getString().getCharArray(); float positionX = text.getPosition().getX(); float positionY = text.getPosition().getY(); if(isPositive(text.getBoxWidth())) { nvgTextBoxBounds(&nanoVgContext, positionX, positionY, text.getBoxWidth(), charArray, nullptr, bounds); } else { nvgTextBounds(&nanoVgContext, positionX, positionY, charArray, nullptr, bounds); } boundingBox.join(Rect(Point(bounds[0], bounds[1]), Point(bounds[2], bounds[3]))); } nvgRestore(&nanoVgContext); } return boundingBox; }
// general purpose facet-drop which calls xy_normal_length(), normal_length(), // and center_height() on the subclass bool MillingCutter::facetDrop(CLPoint &cl, const Triangle &t) const { // Drop cutter at (cl.x, cl.y) against facet of Triangle t Point normal = t.upNormal(); // facet surface normal if ( isZero_tol( normal.z ) ) // vertical surface return false; //can't drop against vertical surface assert( isPositive( normal.z ) ); if ( ( isZero_tol(normal.x) ) && ( isZero_tol(normal.y) ) ) { // horizontal plane special case CCPoint cc_tmp( cl.x, cl.y, t.p[0].z, FACET); return cl.liftZ_if_inFacet(cc_tmp.z, cc_tmp, t); } else { // general case // plane containing facet: a*x + b*y + c*z + d = 0, so // d = -a*x - b*y - c*z, where (a,b,c) = surface normal double d = - normal.dot(t.p[0]); normal.normalize(); // make length of normal == 1.0 Point xyNormal( normal.x, normal.y, 0.0); xyNormal.xyNormalize(); // define the radiusvector which points from the cc-point to the cutter-center Point radiusvector = this->xy_normal_length*xyNormal + this->normal_length*normal; CCPoint cc_tmp = cl - radiusvector; // NOTE xy-coords right, z-coord is not. cc_tmp.z = (1.0/normal.z)*(-d-normal.x*cc_tmp.x-normal.y*cc_tmp.y); // cc-point lies in the plane. cc_tmp.type = FACET; double tip_z = cc_tmp.z + radiusvector.z - this->center_height; return cl.liftZ_if_inFacet(tip_z, cc_tmp, t); } }
bool SignedInteger<MD, DT, NT>::operator==(const SignedInteger<MD, DT, NT> &n) const { return (((isPositive() && n.isPositive()) || (isNegative() && n.isNegative())) && number_ == n.number_); }
void TextNode::renderItself(RenderContext& renderContext) { NVGcontext& nanoVgContext = renderContext.getNanoVgContext(); nvgSave(&nanoVgContext); setupContext(nanoVgContext); Color finalColor = mFontColor.getBlendedColor(renderContext.getBlendColors()); nvgFillColor(&nanoVgContext, nvgRGBAf(finalColor.getRed(), finalColor.getGreen(), finalColor.getBlue(), finalColor.getAlpha())); for(const Text& text : mTexts) { const char* charArray = text.getString().getCharArray(); float positionX = text.getPosition().getX(); float positionY = text.getPosition().getY(); if(isPositive(text.getBoxWidth())) { nvgTextBox(&nanoVgContext, positionX, positionY, text.getBoxWidth(), charArray, nullptr); } else { nvgText(&nanoVgContext, positionX, positionY, charArray, nullptr); } } nvgRestore(&nanoVgContext); Node::renderItself(renderContext); }
void bignum::roundUpToIndex(int index) { //first checks to see if the number is already rounded bignum round_test; round_test.setBase(base); round_test.setDigit(index, 1); //checks to see if number is already rounded without using modulo to prevent stack overflow for (int i = 0; i < index; i++) { if (digits[i] != 0) break; else if (i == index - 1) return; } for (int i = 0; i < index; i++) setDigit(i, 0); if (isPositive()) { bignum increment; increment.setDigit(index, 1); increment.setBase(base); *this += increment; } updateDigits(); }
void TextNode::setFontSize(float fontSize) noexcept { TRJ_ASSERT(isPositive(fontSize), "Invalid font size"); mFontSize = fontSize; invalidateBoundingBox(); }
void ImageNode::setHeight(float height) noexcept { TRJ_ASSERT(isPositive(height), "Invalid height"); float width = (height * mImageRegion.getWidth()) / mImageRegion.getHeight(); setSize(Size(width, height)); }
modelCacheState modelCacheIan :: canMerge ( const modelCacheInterface* p ) const { if ( hasNominalClash(p) ) // fail to merge due to nominal precense return csFailed; // check if something goes wrong if ( p->getState () != csValid || getState () != csValid ) return mergeStatus ( p->getState (), getState () ); // here both models are valid; switch ( p->getCacheType() ) { case mctConst: // check for TOP (as the model is valid) return csValid; case mctSingleton: // check for the Singleton { BipolarPointer Singleton = static_cast<const modelCacheSingleton*>(p)->getValue(); return isMergableSingleton ( getValue(Singleton), isPositive(Singleton) ); } case mctIan: return isMergableIan ( static_cast<const modelCacheIan*>(p) ); default: // something unexpected return csUnknown; } }
modelCacheState modelCacheIan :: merge ( const modelCacheInterface* p ) { fpp_assert ( p != NULL ); // check for nominal clash if ( hasNominalClash(p) ) { curState = csFailed; return getState(); } switch ( p->getCacheType() ) { case mctConst: // adds TOP/BOTTOM curState = mergeStatus ( getState(), p->getState() ); break; case mctSingleton: // adds Singleton { BipolarPointer Singleton = static_cast<const modelCacheSingleton*>(p)->getValue(); mergeSingleton ( getValue(Singleton), isPositive(Singleton) ); break; } case mctIan: mergeIan(static_cast<const modelCacheIan*>(p)); break; default: fpp_unreachable(); } updateNominalStatus(p); return getState(); }
// ------------------------------- parseArgs() ------------------------------- // parse the command-line arguments, and assign the global variables from them // return FALSE if any problem with the command-line arguments int parseArgs(int argc, char *argv[]) { if (argc < 2) return FALSE; // try zero-argument commands: list and stat if (argc == 2) { if (strcmp(argv[1], "stat") == 0) { command = STAT; return TRUE; } else { sprintf(errmsg, "Unrecognized argument: %s", argv[1]); return FALSE; } } // try the one-argument commands: delete and display else if (argc == 3) { if (strcmp(argv[1],"delete") == 0 && isPositive(argv[2])) { command = DELETE; item_start = atoi(argv[2]); return TRUE; } else if (strcmp(argv[1],"display") == 0 && isPositive(argv[2])) { command = DISPLAY; item_start = atoi(argv[2]); return TRUE; } else { sprintf(errmsg, "Unrecognized 2-argument call: %s %s", argv[1],argv[2]); return FALSE; } } // try the two-argument command: add else if (argc == 4) { if (strcmp(argv[1],"add") == 0) { command = ADD; subject = argv[2]; body = argv[3]; return TRUE; } else { sprintf(errmsg, "Unrecognized 3-argument call: %s %s %s",argv[1],argv[2],argv[3]); return FALSE; } } else return FALSE; }
/** * Currently, getDouble() depends on atof() to do its conversion. * * WARNING!! * This is an extremely costly function. ~1/2 of the conversion time * can be linked to this function. */ double DigitList::getDouble() const { // TODO: fix thread safety. Can probably be finessed some by analyzing // what public const functions can see which DigitLists. // Like precompute fDouble for DigitLists coming in from a parse // or from a Formattable::set(), but not for any others. if (fHaveDouble) { return fDouble; } DigitList *nonConstThis = const_cast<DigitList *>(this); if (isZero()) { nonConstThis->fDouble = 0.0; if (decNumberIsNegative(fDecNumber)) { nonConstThis->fDouble /= -1; } } else if (isInfinite()) { if (std::numeric_limits<double>::has_infinity) { nonConstThis->fDouble = std::numeric_limits<double>::infinity(); } else { nonConstThis->fDouble = std::numeric_limits<double>::max(); } if (!isPositive()) { nonConstThis->fDouble = -fDouble; } } else { MaybeStackArray<char, MAX_DBL_DIGITS+18> s; // Note: 14 is a magic constant from the decNumber library documentation, // the max number of extra characters beyond the number of digits // needed to represent the number in string form. Add a few more // for the additional digits we retain. // Round down to appx. double precision, if the number is longer than that. // Copy the number first, so that we don't modify the original. if (getCount() > MAX_DBL_DIGITS + 3) { DigitList numToConvert(*this); numToConvert.reduce(); // Removes any trailing zeros, so that digit count is good. numToConvert.round(MAX_DBL_DIGITS+3); uprv_decNumberToString(numToConvert.fDecNumber, s); // TODO: how many extra digits should be included for an accurate conversion? } else { uprv_decNumberToString(this->fDecNumber, s); } U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18); loadDecimalChar(); if (gDecimal != '.') { char *decimalPt = strchr(s, '.'); if (decimalPt != NULL) { *decimalPt = gDecimal; } } char *end = NULL; nonConstThis->fDouble = uprv_strtod(s, &end); } nonConstThis->fHaveDouble = TRUE; return fDouble; }
Shape::Shape(const ArcInfo& info) noexcept : mArcInfo(info), mType(Type::ARC) { TRJ_ASSERT(isPositive(info.radius), "Invalid radius"); TRJ_ASSERT(info.startAngle >= 0 && info.startAngle < 2 * kPi, "Invalid start angle"); TRJ_ASSERT(info.endAngle >= 0 && info.endAngle < 2 * kPi, "Invalid start angle"); }
bool ZActionActivator::isPositive(const Z3DWindow *window) const { if (window == NULL) { return false; } return isPositive(window->getDocument()); }
void TBox :: setRelevant ( BipolarPointer p ) { fpp_assert ( isValid(p) ); if ( p == bpTOP || p == bpBOTTOM ) return; const DLVertex& v = DLHeap[p]; bool pos = isPositive(p); ++nRelevantBCalls; collectLogicFeature(v,pos); switch ( v.Type() ) { case dtDataType: // types and values are not relevant case dtDataValue: case dtDataExpr: case dtNN: // not appear in any expression => not relevant break; case dtPConcept: // negated primitive entries -- does nothing case dtPSingleton: // if ( !pos ) // break; // fall through case dtNConcept: // named concepts case dtNSingleton: setRelevant(const_cast<TConcept*>(static_cast<const TConcept*>(v.getConcept()))); break; case dtForall: case dtLE: setRelevant(const_cast<TRole*>(v.getRole())); setRelevant (v.getC()); break; case dtProj: // no need to set (inverse) roles as it doesn't really matter case dtChoose: setRelevant(v.getC()); break; case dtIrr: setRelevant(const_cast<TRole*>(v.getRole())); break; case dtAnd: for ( DLVertex::const_iterator q = v.begin(); q != v.end(); ++q ) setRelevant(*q); break; default: std::cerr << "Error setting relevant vertex of type " << v.getTagName() << "(" << v.Type () << ")"; fpp_unreachable(); } }
void POP3ClientSession::retrieveMessage(int id, std::ostream& ostr) { std::string response; sendCommand("RETR", NumberFormatter::format(id), response); if (!isPositive(response)) throw POP3Exception("Cannot get message list", response); DialogInputStream sis(_socket); MailInputStream mis(sis); StreamCopier::copyStream(mis, ostr); }
void POP3ClientSession::retrieveMessage(int id, MailMessage& message, PartHandler& handler) { std::string response; sendCommand("RETR", NumberFormatter::format(id), response); if (!isPositive(response)) throw POP3Exception("Cannot get message list", response); DialogInputStream sis(_socket); MailInputStream mis(sis); message.read(mis, handler); while (mis.good()) mis.get(); // read any remaining junk }
/** * Currently, getDouble() depends on strtod() to do its conversion. * * WARNING!! * This is an extremely costly function. ~1/2 of the conversion time * can be linked to this function. */ double DigitList::getDouble() const { { Mutex mutex; if (fHave == kDouble) { return fUnion.fDouble; } } double tDouble = 0.0; if (isZero()) { tDouble = 0.0; if (decNumberIsNegative(fDecNumber)) { tDouble /= -1; } } else if (isInfinite()) { if (std::numeric_limits<double>::has_infinity) { tDouble = std::numeric_limits<double>::infinity(); } else { tDouble = std::numeric_limits<double>::max(); } if (!isPositive()) { tDouble = -tDouble; //this was incorrectly "-fDouble" originally. } } else { MaybeStackArray<char, MAX_DBL_DIGITS+18> s; // Note: 14 is a magic constant from the decNumber library documentation, // the max number of extra characters beyond the number of digits // needed to represent the number in string form. Add a few more // for the additional digits we retain. // Round down to appx. double precision, if the number is longer than that. // Copy the number first, so that we don't modify the original. if (getCount() > MAX_DBL_DIGITS + 3) { DigitList numToConvert(*this); numToConvert.reduce(); // Removes any trailing zeros, so that digit count is good. numToConvert.round(MAX_DBL_DIGITS+3); uprv_decNumberToString(numToConvert.fDecNumber, s.getAlias()); // TODO: how many extra digits should be included for an accurate conversion? } else { uprv_decNumberToString(this->fDecNumber, s.getAlias()); } U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18); char *end = NULL; tDouble = decimalStrToDouble(s.getAlias(), &end); } { Mutex mutex; DigitList *nonConstThis = const_cast<DigitList *>(this); nonConstThis->internalSetDouble(tDouble); } return tDouble; }
bool convert(const String &input, LONGLONG &outResult, size_t size, bool ignoreWhiteSpace, size_t base) { ZS_THROW_INVALID_USAGE_IF((0 == size) || (size > sizeof(QWORD))) CSTR str = input; if (NULL == str) return false; if (ignoreWhiteSpace) skipSpace(str); bool hadSign = false; bool positive = isPositive(str, hadSign); base = shouldForceBase(str, base, hadSign); LONGLONG result = 0; BYTE digit = 0; if (positive) { while ((digit = gDigitToValue[*str]) < base) { LONGLONG lastResult = result; result *= base; result += static_cast<LONGLONG>(digit); if (result < lastResult) return false; // value had to flip ++str; } if (result > gMaxLongLongs[size-1]) return false; } else { while ((digit = gDigitToValue[*str]) < base) { LONGLONG lastResult = result; result *= base; result -= static_cast<LONGLONG>(digit); if (lastResult < result) return false; // value had to flip ++str; } if (result < static_cast<LONGLONG>(gMinLongLongs[size-1])) return false; } if (ignoreWhiteSpace) skipSpace(str); if (0 != *str) return false; outResult = result; return true; }
void POP3ClientSession::retrieveHeader(int id, MessageHeader& header) { std::string response; sendCommand("TOP", NumberFormatter::format(id), "0", response); if (!isPositive(response)) throw POP3Exception("Cannot get message list", response); DialogInputStream sis(_socket); MailInputStream mis(sis); header.read(mis); // skip stuff following header mis.get(); // \r mis.get(); // \n }
int POP3ClientSession::messageCount() { std::string response; sendCommand("STAT", response); if (!isPositive(response)) throw POP3Exception("Cannot determine message count", response); std::string::const_iterator it = response.begin(); std::string::const_iterator end = response.end(); int count = 0; while (it != end && !Poco::Ascii::isSpace(*it)) ++it; while (it != end && Poco::Ascii::isSpace(*it)) ++it; while (it != end && Poco::Ascii::isDigit(*it)) count = count*10 + *it++ - '0'; return count; }
void DLDag :: updateVertexStat ( BipolarPointer p ) { DLVertex& v = (*this)[p]; bool pos = isPositive(p); DLVertex::StatType d = 0, s = 1, b = 0, g = 0; if ( !v.omitStat(pos) ) { if ( isValid(v.getC()) ) updateVertexStat ( v, v.getC(), pos ); else for ( DLVertex::const_iterator q = v.begin(), q_end = v.end(); q < q_end; ++q ) updateVertexStat ( v, *q, pos ); } // correct values wrt POS d = v.getDepth(pos); switch ( v.Type() ) { case dtAnd: if ( !pos ) ++b; // OR is branching break; case dtForall: ++d; // increase depth if ( !pos ) ++g; // SOME is generating break; case dtLE: ++d; // increase depth if ( !pos ) ++g; // >= is generating else if ( v.getNumberLE() != 1 ) ++b; // <= is branching break; case dtProj: if ( pos ) ++b; // projection sometimes involves branching break; default: break; } v.updateStatValues ( d, s, b, g, pos ); }
void DLDag :: computeVertexStat ( BipolarPointer p ) { DLVertex& v = (*this)[p]; bool pos = isPositive(p); // this vertex is already processed if ( v.isProcessed(pos) ) return; // in case of cycle: mark concept as such if ( v.isVisited(pos) ) { v.setInCycle(pos); return; } v.setVisited(pos); // ensure that the statistic is gather for all sub-concepts of the expression switch ( v.Type() ) { case dtAnd: // check all the conjuncts case dtSplitConcept: for ( DLVertex::const_iterator q = v.begin(), q_end = v.end(); q < q_end; ++q ) computeVertexStat ( *q, pos ); break; case dtProj: if ( !pos ) // ~Proj -- nothing to do break; // fallthrough case dtName: case dtForall: case dtChoose: case dtLE: // check a single referenced concept computeVertexStat ( v.getC(), pos ); break; default: // nothing to do break; } v.setProcessed(pos); // here all the necessary statistics is gathered -- use it in the init updateVertexStat(p); }
int main() { printf("Test with main.\n"); printf("bitAnd Result: %d\n", bitAnd(15,3)); printf("getByte Result: %d \n",getByte(0x12345678,22)); printf("bitcount Result: %d \n", bitCount(1)); printf("bang result is: %d \n", bang(3)); printf("minimum two's complement integer is: %d \n",tmin()); printf("fitbits result is: %d \n",fitsBits(-4,3)); printf("divpwr2 result is: %d \n",divpwr2(-33,4)); printf("negate result is: %d \n",negate(4)); printf("isPositive result is: %d \n",isPositive(-4)); printf("isLessOrEqual result is: %d \n",isLessOrEqual(5,5)); printf("float_neg result is: %d \n",float_neg(13)); printf("float_i2f result is: %d \n",float_i2f(15)); printf("float_twice result is: %d \n",float_twice(9.84)); }