Match matchType(BasicType lhs, BasicType rhs) { if (lhs == rhs) return Match::Exact; if (isNumeric(lhs) && isNumeric(rhs)) { const u16_t lhs_size = BasicTypeSize[static_cast<u16_t>(lhs)]; const u16_t rhs_size = BasicTypeSize[static_cast<u16_t>(rhs)]; if (isIntegral(lhs) && isIntegral(rhs)) { if (isSigned(lhs) == isSigned(rhs)) { if (lhs_size >= rhs_size) return Match::Exact; } return Match::Convert; } if (isFloat(lhs) && isFloat(rhs)) { if (lhs_size >= rhs_size) return Match::Exact; return Match::Convert; } if (isFloat(lhs) && isIntegral(rhs)) { if (lhs_size >= rhs_size) return Match::Exact; return Match::Convert; } } return Match::No; }
inline T required_integer(cref value, size_t index) { auto integer = value[index]; if (!integer.isIntegral()) { BOOST_THROW_EXCEPTION(bklib::json::bad_type()); } return get_integer<T>(integer); }
Integer DeltaRational::euclidianDivideRemainder(const DeltaRational& y) const { if(isIntegral() && y.isIntegral()){ Integer ti = floor(); Integer yi = y.floor(); return ti.euclidianDivideRemainder(yi); }else{ throw DeltaRationalException("euclidianDivideRemainder", *this, y); } }
void CoordinatedGraphicsLayer::computePixelAlignment(FloatPoint& position, FloatSize& size, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset) { if (isIntegral(effectiveContentsScale())) { position = m_position; size = m_size; anchorPoint = m_anchorPoint; alignmentOffset = FloatSize(); return; } FloatPoint positionRelativeToBase = computePositionRelativeToBase(); FloatRect baseRelativeBounds(positionRelativeToBase, m_size); FloatRect scaledBounds = baseRelativeBounds; // Scale by the effective scale factor to compute the screen-relative bounds. scaledBounds.scale(effectiveContentsScale()); // Round to integer boundaries. // NOTE: When using enclosingIntRect (as mac) it will have different sizes depending on position. FloatRect alignedBounds = enclosingIntRect(scaledBounds); // Convert back to layer coordinates. alignedBounds.scale(1 / effectiveContentsScale()); // Convert back to layer coordinates. alignmentOffset = baseRelativeBounds.location() - alignedBounds.location(); position = m_position - alignmentOffset; size = alignedBounds.size(); // Now we have to compute a new anchor point which compensates for rounding. float anchorPointX = m_anchorPoint.x(); float anchorPointY = m_anchorPoint.y(); if (alignedBounds.width()) anchorPointX = (baseRelativeBounds.width() * anchorPointX + alignmentOffset.width()) / alignedBounds.width(); if (alignedBounds.height()) anchorPointY = (baseRelativeBounds.height() * anchorPointY + alignmentOffset.height()) / alignedBounds.height(); anchorPoint = FloatPoint3D(anchorPointX, anchorPointY, m_anchorPoint.z() * effectiveContentsScale()); }
bool Value::isNumeric() const { return isIntegral() || isDouble(); }
bool Value::isDouble() const { return type_ == realValue || isIntegral(); }
void CInterval:: init() { bool integral = isIntegral(); timeType_ = TimeType::SECONDS; startTime_.year = 0; startTime_.month = 0; startTime_.day = 0; startTime_.hour = 0; startTime_.minute = 0; startTime_.second = 0; // Ensure min/max are in the correct order double min = std::min(data_.start, data_.end); double max = std::max(data_.start, data_.end); if (isIntegral()) { min = std::floor(min); max = std::ceil (max); } else if (isDate()) { int y = timeLengthToYears (min, max); int m = timeLengthToMonths (min, max); int d = timeLengthToDays (min, max); startTime_.year = timeToYear (min); startTime_.month = timeToMonths (min); startTime_.day = timeToDays (min); min = 0; if (y >= 5) { //std::cout << "years\n"; timeType_ = TimeType::YEARS; max = y; } else if (m >= 3) { //std::cout << "months\n"; timeType_ = TimeType::MONTHS; max = m; } else if (d >= 4) { //std::cout << "days\n"; timeType_ = TimeType::DAYS; max = d; } integral = true; } else if (isTime()) { int h = timeLengthToHours (min, max); int m = timeLengthToMinutes(min, max); int s = timeLengthToSeconds(min, max); startTime_.hour = timeToHours (min); startTime_.minute = timeToMinutes(min); startTime_.second = timeToSeconds(min); min = 0; if (h >= 12) { //std::cout << "hours\n"; timeType_ = TimeType::HOURS; max = h; } else if (m >= 10) { //std::cout << "minutes\n"; timeType_ = TimeType::MINUTES; max = m; } else { //std::cout << "seconds\n"; timeType_ = TimeType::SECONDS; max = s; } integral = true; } //--- // use fixed increment double majorIncrement = this->majorIncrement(); if (majorIncrement > 0.0 && (! isDate() && ! isTime())) { calcData_.start = min; calcData_.end = max; calcData_.increment = majorIncrement; calcData_.numMajor = CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment); calcData_.numMinor = 5; return; } //--- if (data_.numMajor > 0) { goodTicks_.opt = data_.numMajor; goodTicks_.min = std::max(goodTicks_.opt/10, 1); goodTicks_.max = goodTicks_.opt*10; } else { goodTicks_ = GoodTicks(); } //--- calcData_.numMajor = -1; calcData_.numMinor = 5; //--- calcData_.increment = data_.increment; if (calcData_.increment <= 0.0) { calcData_.increment = initIncrement(min, max, integral); //--- // Calculate other test increments for (int i = 0; i < numIncrementTests; i++) { // disable non-integral increments for integral if (integral && ! isInteger(incrementTests[i].factor)) { incrementTests[i].incFactor = 0.0; continue; } // disable non-log increments for log if (isLog() && ! incrementTests[i].isLog) { incrementTests[i].incFactor = 0.0; continue; } incrementTests[i].incFactor = calcData_.increment*incrementTests[i].factor; } //--- // Test each increment in turn (Set default start/end to force update) int tickIncrement = this->tickIncrement(); GapData axisGapData; for (int i = 0; i < numIncrementTests; i++) { // skip disable tests if (incrementTests[i].incFactor <= 0.0) continue; // if tick increment set then skip if not multiple of increment if (tickIncrement > 0) { if (! isInteger(incrementTests[i].incFactor)) continue; int incFactor1 = int(incrementTests[i].incFactor); if (incFactor1 % tickIncrement != 0) continue; } // test factor, ticks and update best if (testAxisGaps(min, max, incrementTests[i].incFactor, incrementTests[i].numTicks, axisGapData)) { //axisGapData.print(" Best) "); } } //--- calcData_.start = axisGapData.start; calcData_.end = axisGapData.end; calcData_.increment = axisGapData.increment; calcData_.numMinor = (! isLog() ? axisGapData.numMinor : 10); } else { calcData_.start = min; calcData_.end = max; calcData_.numMinor = 5; } calcData_.numMajor = CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment); if (isDate()) { if (timeType_ == TimeType::YEARS) { calcData_.numMinor = 12; } else if (timeType_ == TimeType::MONTHS) { calcData_.numMinor = 4; } else if (timeType_ == TimeType::DAYS) { calcData_.numMinor = 4; } } else if (isTime()) { if (timeType_ == TimeType::HOURS) { calcData_.numMinor = 6; } else if (timeType_ == TimeType::MINUTES) { calcData_.numMinor = 12; } else if (timeType_ == TimeType::SECONDS) { calcData_.numMinor = 12; } } }
int main() { char * inFp = "C:\\abc.txt"; //char * inFpZeroes= "C:\\abc_zeroes.txt"; char * inFpCrc = "C:\\abc_crc.txt"; char * outFp = "C:\\abc_compressed.txt"; char * decompressedFpCrc = "C:\\abc_decompressed_crc.txt"; char * decompressedFp = "C:\\abc_decompressed.txt"; copyFile(inFp, inFpCrc); //appendZeroes(inFpZeroes, SIZECRC); unsigned char * restPoly = calculateCrc(inFp); printf("Generated polynomial:\n"); printPolynomial(restPoly, SIZECRC); appendCrcToFile(inFpCrc, SIZECRC, restPoly); int lettersFrequencies[LETTERS_COUNT]; // = {81, 15, 28, 43, 128, 23, 20, 61, 71, 2, 1, 40, 24, 69, 76, 20, 1, 61, 64, 91, 28, 10, 24, 1, 20, 1, 130};; //char letters[LETTERS_COUNT] = {'?', '?', '?', '?', '?', '?', '?', '?', '?', '?','?', '?', '?', '?', '?','?', '?', '?', '?', '?','?', '?', '?', '?', '?','?', '?', '?', '?', '?', '?', '?', '!', '"', '#', '$', '%', '&', '(', ')', '*', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' '}; //printTabInt(lettersFrequencies, LETTERS_COUNT); //printTabChar(letters, LETTERS_COUNT); //printf("Letter indices: "); calculateFreq(inFpCrc, lettersFrequencies); //printTabInt(lettersFrequencies, 255); Node *nodes[LETTERS_COUNT]; int i; for(i=0; i<LETTERS_COUNT; i++) { nodes[i] = malloc(sizeof(Node)); nodes[i]->value = lettersFrequencies[i]; nodes[i]->letterIndex = i; nodes[i]->left = NULL; nodes[i]->right = NULL; } //printLetterIndices(nodes); Node *tree = buildHuffmanTree(nodes); int codeTable[LETTERS_COUNT]; int invertedCodeTable2[LETTERS_COUNT]; resetIntTable(codeTable, LETTERS_COUNT); //printf("codeTable: \n"); //printTabInt(codeTable, LETTERS_COUNT); fillTable(codeTable, tree, 0); invertCodeTable(codeTable, invertedCodeTable2); //printf("codeTable: \n"); //printTabInt(codeTable, LETTERS_COUNT); //printf("inverted codeTable: \n"); //printTabInt(invertedCodeTable2, LETTERS_COUNT); //printCodeTable(letters, codeTable, LETTERS_COUNT); //printCodeTableForIdx(codeTable, LETTERS_COUNT); //printTabInt(codeTable, LETTERS_COUNT); //createCrcFile(inFpCrc, SIZECRC, restPoly); //appendFileToFile(inFp, inFpCrc); compressFile(inFpCrc, outFp, invertedCodeTable2); printf("\n\ndecompressed file:\n"); decompressFile(outFp, decompressedFpCrc, tree); unsigned char * restPolyFromDec = calulateRest(decompressedFpCrc); printf("\n\nRest from decopressed file:\n"); printPolynomial(restPolyFromDec, SIZECRC); if(!isIntegral()){ printf("Integrity check failed!"); exit(EXIT_FAILURE); }else{ copySkip(decompressedFpCrc, decompressedFp, SIZECRC); } //checkIntegrity(); //FILE * output = fopen("C:\\codeblocks\\Huffman\\huffman\\to.txt","w"); //compressFile(input, output, codeTable); return 0; }
bool Type::isArithmetic() const { return isIntegral() || isFloatingPoint(); }
bool VariantValue::isArithmetical() const { return isIntegral() || isFloatingPoint(); }
Json::Value JsonSerializer::toValue(AnyValue val) const { auto info = val.type_info(); if (val.isType<bool>()) { bool v = val.as<bool>(); return Json::Value(v); } else if (info.isIntegral()) { if (info.isUnsigned()) { uint64_t v = val.as<uint64_t>(); return Json::Value((Json::Value::UInt64)v); } else { int64_t v = val.as<int64_t>(); return Json::Value((Json::Value::Int64)v); } } else if (info.isFloatingPoint()) { double v = val.as<double>(); return Json::Value(v); } else if (val.isType<std::vector<AnyValue>>()) { Json::Value res = Json::arrayValue; std::vector<AnyValue> v = val.as < std::vector<AnyValue>>(); for (AnyValue any : v) res.append(this->toValue(any)); return res; } else if (val.isType<Bundle>()) { Json::Value res = Json::objectValue; Bundle b = val.as<Bundle>(); for (const auto& val : b) { res[val.first] = this->toValue(val.second); } return res; } else if (val.isType<std::nullptr_t>()) { return Json::nullValue; } else if (val.isSerializable()) { return this->toValue(val.serialize()); } else if (val.isConvertibleTo<std::string>()) { std::string v = val.as<std::string>(); return Json::Value(v); } else { throw std::logic_error("Type is not convertible."); } }