Fog::FOGMASK* Fog::calculateFogMask(const int radius) { // array is len * len (w * h) const unsigned short len = radius * 2 + 1; bool** tempArray = new bool*[len]; for (unsigned short i = 0; i < len; i++) { tempArray[i] = new bool[len]; } // set array to false for (unsigned short i = 0; i < len; i++) { memset(tempArray[i], false, len * sizeof(bool)); } // initial values unsigned short x = 0; unsigned short y = radius; int p = (5 - radius * 4) / 4; addValues(tempArray, x, y, radius); while (x < y) { ++x; if (p < 0) { p += 2 * x + 1; } else { --y; p += 2 * (x - y) + 1; } addValues(tempArray, radius - x, radius - y, radius); if (x < y) { addValues(tempArray, radius - y, radius - x, radius); } } FOGMASK* fm = new FOGMASK(); fm->radius = radius; DoubleLinkedList<FOGROW*>& list = fm->data; for (unsigned short yy = 0; yy < len; yy++) { FOGROW* fogrow = new FOGROW(); for (unsigned short xx = 0; xx < len; xx++) { if (tempArray[yy][xx]) { fogrow->offset = xx; fogrow->amount = len - xx * 2; break; } } list.pushTail(fogrow); } for (unsigned short i = 0; i < len; i++) delete [] tempArray[i]; delete [] tempArray; return fm; }
CuckooMap* getCuckooMap(uint64_t* slowMap, uint32_t* freqs, int bitsCollection) { CuckooMap* map = mallocClean(sizeof(CuckooMap)); int numElems = getSignatureMapSize(slowMap) * SPACE_MULTIPLIER; map->table1 = mallocClean(sizeof(uint64_t) * numElems * ELEMS_PER_KEY); map->table2 = mallocClean(sizeof(uint64_t) * numElems * ELEMS_PER_KEY); map->size = numElems; addValues(map, slowMap, freqs, bitsCollection); return map; }
//main int main() { printf("\nWelcome!! This program performs the addition of three integers 2,4,6 \nand division of three numbers 36.0,3.0,2.0\n"); //Addition addValues(2,4,6); //Division callfunc(36.0,3.0,2.0); printf("\nThank you..\n\n"); return 0; }
bool MeshLoaderObj::load(const Ravage::String& filename) { mRenderer = mRenderCore->getRenderer(); Ravage::File file; if (!file.open(filename, Ravage::RAV_FMODE_READ | Ravage::RAV_FMODE_TEXT)) return false; mDrawOperation.primitiveCount = 0; Ravage::String line; while (!file.isEnd()) { file.readLine(line, RAV_TXT("\n")); Ravage::String::size_type trim = line.find_first_of(RAV_TXT("#")); line = line.substr(0, trim); Ravage::StringUtils::trim(line); std::basic_istringstream<Ravage::Symbol> iss(line); Ravage::String cmd; iss >> cmd; if (cmd == RAV_TXT("v") || cmd == RAV_TXT("vt") || cmd == RAV_TXT("vn")) { std::vector<Ravage::Real> values; Ravage::Real val = 0.0f; while (!iss.eof()) { iss >> val; values.push_back(val); } if (!addValues(cmd, values)) return false; } else if (cmd == RAV_TXT("f"))
void toResultLine::poll(void) { try { toQColumnDescriptionList desc; if (!Columns) { desc = Query->describe(); Columns = desc.size(); } if (First) { if (desc.empty()) desc = Query->describe(); clear(); std::list<QString> labels; for (toQColumnDescriptionList::iterator i = desc.begin(); i != desc.end(); i++) if (i != desc.begin()) labels.insert(labels.end(), (*i).Name); setLabels(labels); } while (Query->hasMore()) { unsigned int num = 0; QString lab = (QString)Query->readValue(); num++; std::list<double> vals; while (!Query->eof() && num < Columns) { vals.insert(vals.end(), Query->readValue().toDouble()); num++; } if (Flow) { time_t now = time(NULL); if (now != LastStamp) { if (LastValues.size() > 0) { std::list<double> dispVal; std::list<double>::iterator i = vals.begin(); std::list<double>::iterator j = LastValues.begin(); while (i != vals.end() && j != LastValues.end()) { dispVal.insert(dispVal.end(), (*i - *j) / (now - LastStamp)); i++; j++; } std::list<double> tmp = transform(dispVal); addValues(tmp, lab); } LastValues = vals; LastStamp = now; } } else { std::list<double> tmp = transform(vals); addValues(tmp, lab); } } } catch (const QString &exc) { delete Query; Query = NULL; Utils::toStatusMessage(exc); } }
int main() { //Declares all of the arrays that are to be used char inFileName[MAXFILENAMELENGTH]; char outFileName[MAXFILENAMELENGTH]; int fileContents[NUMINTSINFILE]; int addedContents[NUMINTSAFTERADDITION]; int subtractedContents[NUMINTSAFTERSUBTRACTION]; //Initializes the arrays to 0s initializeArray(addedContents, NUMINTSAFTERADDITION); initializeArray(fileContents, NUMINTSINFILE); initializeArray(subtractedContents, NUMINTSAFTERSUBTRACTION); //Declares the file streams to be used ifstream inFile; ofstream outFile; //Gets the input file name cout << "Please enter the file name to open: "; cin >> inFileName; //Gets the output file name cout << "Please enter the file name to write to: "; cin >> outFileName; //Reads in the values from the input file name to the input values array inFile.open(inFileName); if (!inFile.fail()) { cout << "Input file found." << endl; getIntValues(fileContents, NUMINTSINFILE, inFile); toScreen(fileContents, NUMINTSINFILE); } else { cout << "Input file not found. Ending program." << endl; return 1; } //Adds the values per instruction into another array addValues(fileContents, addedContents, NUMINTSINFILE, NUMINTSAFTERADDITION); //Subtracts the values per instruction into another array subtractValues(fileContents, subtractedContents, NUMINTSINFILE, NUMINTSAFTERSUBTRACTION); //Outputs the added and subtracted values to the output file name outFile.open(outFileName); if (!outFile.fail()) { cout << "Output file found." << endl; toScreen(addedContents, NUMINTSAFTERADDITION); toScreen(subtractedContents, NUMINTSAFTERSUBTRACTION); outFile << "Added values: " << endl; for (int i = 0; i < NUMINTSAFTERADDITION; i++) { outFile << addedContents[i] << " "; } outFile << "\nSubtracted values: " << endl; for (int i = 0; i < NUMINTSAFTERSUBTRACTION; i++) { outFile << subtractedContents[i] << " "; } } else { cout << "Output file not found. Ending program." << endl; return 1; } //Closes the file streams as to clean up system inFile.close(); outFile.close(); return 0; }
jint Java_com_datsumi_calc_Calc_addValues(JNIEnv* env, jobject thiz, jint val1, jint val2) { return addValues(val1, val2); }
void PHN_LineGraph::addValue(float value) { float v[1]; v[0] = value; addValues(v); }
// Adds two bigints and returns the result which is a bigint bigint bigint_add(bigint a, bigint b){ //If they are of the opposite signs, then send them for subtraction if(a.pos==0&&b.pos==1||a.pos==1&&b.pos==0){ if(a.pos==0){ a.pos = 1;//Make it positive and send it for subtraction. return bigint_sub(b,a);//Returns (b-a) } else{ b.pos = 1;//Make it positive and send it for subtraction. return bigint_sub(a,b);//Returns (a-b) } } //If of the same sign, then add. else{ bigint bigger_num, smaller_num;// Here the bigger number is in terms of the absolute quantity. if(!a.pos){ if(compare_bigint(a,b)==1){ bigger_num = b; smaller_num = a; } else if(compare_bigint(a,b)==-1){ bigger_num = a; smaller_num = b; } else{ //Both are equal. Assign any number to any variable. bigger_num = a; smaller_num = b; } } else{ if(compare_bigint(a,b)==1){ bigger_num = a; smaller_num = b; } else if(compare_bigint(a,b)==-1){ bigger_num = b; smaller_num = a; } else{ //Both are equal. Assign any number to any variable. bigger_num = b; smaller_num = a; } } //At this point, bigger_num has the larger number in absolute terms. The 'smaller_num' contains the other. //Now, create a new character array which can hold the sum of the two terms and pass that array to make_bigint //For the new character array, assign memory 1 greater than the length of the bigger_num. //In case the left hand most field doesn't get filled up, then assign 0 to it. make_bigint takes care of that. int new_length = bigger_num.length+1;//This length excludes the negative sign. char* new_value; if(bigger_num.pos==0){ new_value = (char*)malloc((new_length+1+1)*sizeof(char));//+1 for the negative sign and +1 for terminating it with NULL new_value[0] = '-'; new_value[new_length+1] = '\0';//Terminating with a null character } else{ new_value = (char*)malloc((new_length+1)*sizeof(char));//+1 for terminating it with null. new_value[new_length] = '\0';//Terminating with a null character } addValues(bigger_num, smaller_num, new_value, new_length);//Does string addition and stores the result in new_value return make_bigint(new_value); }//Else ends }
void MultiKeyTagFilter::addValues(std::initializer_list<std::string> l) { addValues(l.begin(), l.end()); }
Histogram* Histogram::operator+=(const Histogram& other) { addValues(other.m_values); return this; }
Histogram::Histogram(const vector<int>& values) : m_max(0) , m_sum(0) { addValues(values); }