void T_Calibration::putBackIntoCfg(SimpleXMLTransfer* cfgfile) { #if DEBUG_TX_INTERFACE > 0 printf("T_Calibration::putBackIntoCfg(cfg)\n"); printf(" --> %s\n", child_in_cfg.c_str()); #endif int size; SimpleXMLTransfer* item; SimpleXMLTransfer* group; SimpleXMLTransfer* item2; item = cfgfile->getChild(child_in_cfg); group = item->getChild("calibration"); group->setAttributeOverwrite("version", "2"); // clean list size = group->getChildCount(); for (int n = 0; n < size; n++) { item2 = group->getChildAt(0); group->removeChildAt(0); delete item2; } // create new list for (int n = 0; n < TX_MAXAXIS; n++) { item2 = new SimpleXMLTransfer(); item2->setName("axis"); item2->addAttribute("val_min", doubleToString(val_min[n])); item2->addAttribute("val_mid", doubleToString(val_mid[n])); item2->addAttribute("val_max", doubleToString(val_max[n])); group->addChild(item2); } }
void Power::Propeller::ReloadParams_automagic(SimpleXMLTransfer* xml) { SimpleXMLTransfer* p = xml->getChild("battery.shaft.propeller"); D = p->getDouble("D"); H = p->getDouble("H"); J = p->getDouble("J"); double F = xml->getDouble("F"); double V = xml->getDouble("V"); // Der Sturz wird in jedem Fall aus der Modelldatei gelesen, ansonsten muss man ja eine // Propellerdatei fuer jeden Sturz extra haben. CalcDownthrust(p); { // Calculate rotational speed and torque needed: // F = M_PI * 0.25 * D*D * RHO * (V_X + filter.val/2) * filter.val * ETA_PROP; // F = M_PI * 0.25 * D*D * RHO * (V + (Hn-V)/2) * (Hn-V) * ETA_PROP; // F = M_PI * 0.25 * D*D * RHO * (V/2 + Hn/2) * (Hn-V) * ETA_PROP; double n = sqrt( (8*F/(M_PI*D*D*RHO*ETA_PROP)) + V*V)/H; double M = F * (V + (V + H*n)/2) / (2*M_PI*n) * i; // Save these values so the engine can adjust itself to them: p->setAttribute("automagic.n_P", doubleToString(n)); p->setAttribute("automagic.M_P", doubleToString(M)); } omega_fold = p->attributeAsDouble("n_fold", -1)*2*M_PI; }
void Conformation::generateHash(const AtomContainer* mol, String& hash) { String input_string=""; map<const Atom*, Size> atom_map; set<const Bond*> visisted_bonds; Size i = 0; for (AtomConstIterator it = mol->beginAtom(); +it; it++, i++) { const Vector3& pos = it->getPosition(); input_string += it->getElement().getSymbol() +doubleToString(pos[0])+doubleToString(pos[1])+doubleToString(pos[2]); atom_map.insert(make_pair(&*it, i)); } for (AtomConstIterator it = mol->beginAtom(); +it; it++) { for (Atom::BondConstIterator bond_it = it->beginBond(); +bond_it; bond_it++) { if (visisted_bonds.find(&*bond_it) != visisted_bonds.end()) { continue; } Size a1 = atom_map[bond_it->getFirstAtom()]; Size a2 = atom_map[bond_it->getSecondAtom()]; input_string += String(a1)+String(a2)+String(bond_it->getOrder()); visisted_bonds.insert(&*bond_it); } } hash = QCryptographicHash::hash(QByteArray(input_string.c_str()), QCryptographicHash::Sha1).toHex().constData(); }
/** * Converts a double into a string which is as short as possible * * @param value The double value * @param prec Precision e.g. a precision of 1 would mean that a * value of 2.12030 will be converted to "2.1". 2.000 is always just "2"). */ QString RUnit::doubleToString(double value, double prec, bool /*showLeadingZeroes*/, bool /*showTrailingZeroes*/) { QString ret; QString exaStr; int dotPos; int num; if (prec>1.0e-12) { num = RMath::mround(value / prec); } else { num = RMath::mround(value); } exaStr = doubleToString(prec, 10); dotPos = exaStr.indexOf('.'); if (dotPos==-1) { ret.sprintf("%d", RMath::mround(num*prec)); } else { int digits = exaStr.length() - dotPos - 1; ret = doubleToString(num*prec, digits); } return ret; }
void readTempHumid() { temperatureSensor.requestTemperatures(); double tempCelcius = temperatureSensor.getTempCByIndex(0); String toDrawTemp = doubleToString(tempCelcius, 2); double humidityVoltage = (double) analogRead(5) / 1024 * REFERENCE_VOLTAGE; double humidityPercentage = (humidityVoltage / REFERENCE_VOLTAGE - 0.16) / 0.0062; double relativeHumidity = humidityPercentage / (1.0546 - 0.00216 * tempCelcius); if(relativeHumidity > 100) relativeHumidity = 100; else if(relativeHumidity < 0) relativeHumidity = 0; String toDrawHumid = doubleToString(relativeHumidity, 2); if(deviceStatus == TEMP_VIEW) { LCD.rectangle(81, 0, 320, 240, BLACK); LCD.tText(7, 6, WHITE, "Temp(C): " + toDrawTemp + "C"); LCD.tText(7, 7, WHITE, "RH%: " + toDrawHumid + "%"); } if(writeToSD) { String toWrite = toDrawTemp + "\t" + toDrawHumid + "\n"; LCD.appendString2File("Data", toWrite); } }
void ValueTraits<const double>::hugeNumber(double t) { char *s = doNegative(t); s = doubleToString(t, s, 0, 1); s = copyString(s, "."); s = doubleToString(t, s, 1, DIGITS_ON_RIGHT); s = copyString(s, "E"); s = numberToString(requiredDigitsOnLeft(t) - 1, s); }
//========================================================= CapillaryDlg::CapillaryDlg( Capillary & cap, QWidget *parent ) : QDialog( parent ), c( cap ) { ui = new Ui::Capillary; ui->setupUi( this ); ui->alpha->setText(doubleToString( cap.Alpha )); ui->ho->setText(doubleToString( cap.Ho )); ui->krc->setText(doubleToString( cap.Krc )); QValidator *v = new QRegExpValidator(QRegExp(numeric_validator_rx), this); ui->alpha->setValidator(v); ui->ho->setValidator(v); ui->krc->setValidator(v); }
//-------------------------------------------------------------- void ofxStreetViewCollector::savePoint(SVPoint & p){ ofXml x; x.addChild("SVPoint"); x.setTo("//SVPoint"); x.addValue("pos", doubleToString(p.x) +", "+ doubleToString(p.y) +", "+doubleToString(p.z)); x.addValue("id", p.ID); x.addChild("links"); x.setTo("links"); for(int i = 0; i < p.links.size(); i++) { x.addValue("link", p.links[i]); } x.setTo("//SVPoint"); xml.addXml(x); }
std::string oskar_settings_utility_double_to_string_2(double d, char format, int precision) { if (precision < 0) { switch (format) { case 'f': precision = get_precision(d); break; case 'e': precision = 15; break; case 'g': default: precision = 16; } } std::ostringstream ss; std::string s; DoubleForm f; switch (format) { case 'f': f = DFDecimal; break; case 'e': f = DFExponent; break; case 'g': default: f = DFSignificantDigits; } unsigned int flags = 0; s = doubleToString(d, precision, f, -1, flags); return s; }
/** * Formats the given length in engineering format (e.g. 5' 4.5"). * * \param length The length in the current unit of the drawing. * \param prec Precision of the value (e.g. 0.001 or 1/128 = 0.0078125) & \param showUnit Append unit to the value. */ QString RUnit::formatEngineering(double length, RS::Unit unit, int prec, bool /*showUnit*/, bool /*showLeadingZeroes*/, bool /*showTrailingZeroes*/) { if (unit!=RS::Inch) { qWarning() << "RUnit::formatEngineering:" << "Unit must be set to 'Inch' for engineering format"; return ""; } QString ret; bool sign = (length<0.0); int feet = (int)floor(fabs(length)/12); double inches = fabs(length) - feet*12; QString sInches = doubleToString(inches, prec); if (sInches=="12") { feet++; sInches="0"; } if (feet!=0) { ret.sprintf("%d'-%s\"", feet, (const char*)sInches.toLatin1()); } else { ret.sprintf("%s\"", (const char*)sInches.toLatin1()); } if (sign) { ret = "-" + ret; } return ret; }
void T_AxisMapper::putBackIntoCfg(SimpleXMLTransfer* cfgfile) { #if DEBUG_TX_INTERFACE > 0 printf("T_AxisMapper::putBackIntoCfg(SimpleXMLTransfer* config)\n"); printf(" --> %s\n", child_in_cfg.c_str()); #endif SimpleXMLTransfer* item; SimpleXMLTransfer* group; SimpleXMLTransfer* item2; try { item = cfgfile->getChild(child_in_cfg); group = item->getChild("bindings.axes"); for (int i = T_AxisMapper::AILERON; i <= T_AxisMapper::PITCH; i++) { item2 = group->getChild(Global::inputDev->AxisStringsXML[i], true); item2->setAttributeOverwrite("axis", c_func[i]); item2->setAttributeOverwrite("polarity", doubleToString(c_inv[i])); } item2 = item->getChild("bindings"); item2->setAttributeOverwrite("radio_type", RadioTypeStrings[radio_type]); } catch (XMLException e) { fprintf(stderr, "*** T_AxisMapper: XMLException: %s\n", e.what()); } }
void MainWindow::on_experiment_measured(const HallData::MeasuredData &, const HallData::EvaluatedData &evaluatedData, const HallData::SummaryData &summaryData) { ui->dataTableWidget->insertRow(0); ui->dataTableWidget->setItem( 0, 0, new QTableWidgetItem(doubleToString(evaluatedData.B))); ui->dataTableWidget->setItem( 0, 1, new QTableWidgetItem(doubleToString(evaluatedData.Uhall))); ui->dataTableWidget->setItem( 0, 2, new QTableWidgetItem(doubleToString(UnitConv::toDisplay(config.sampleI(), sampleIUnits)))); ui->dataTableWidget->setItem( 0, 3, new QTableWidgetItem(doubleToString(evaluatedData.R))); ui->dataTableWidget->setItem( 0, 4, new QTableWidgetItem(doubleToString(UnitConv::toDisplay(evaluatedData.Rspec, resistivitySpecUnits)))); ui->dataTableWidget->setItem( 0, 5, new QTableWidgetItem(doubleToString(UnitConv::toDisplay(evaluatedData.driftSpeed, driftUnits)))); ui->dataTableWidget->setItem( 0, 6, new QTableWidgetItem(QVariant(round(evaluatedData.errAsymetry * 1000.) / 10.).toString())); ui->dataTableWidget->setItem( 0, 7, new QTableWidgetItem(QVariant(round(evaluatedData.errShottky * 1000.) / 10.).toString())); ui->dataTableWidget->resizeColumnsToContents(); ui->carriercLineEdit->setText(doubleToString(UnitConv::toDisplay(summaryData.carrierc, carriercUnits))); ui->driftLineEdit->setText(doubleToString(UnitConv::toDisplay(summaryData.driftSpeed, driftUnits))); ui->resistivityLineEdit->setText(doubleToString(summaryData.R)); ui->resistivitySpecLineEdit->setText(doubleToString(UnitConv::toDisplay(summaryData.RSpec, resistivitySpecUnits))); if (isfinite(evaluatedData.B)) { ui->coilBDoubleSpinBox->setValue(evaluatedData.B); // TODO: skip NAN data from ploting const QVector<double> &dataB(experiment.data().B()); const double *dataX = dataB.constData(); const int dataSize = dataB.size(); qwtPlotCurveResistivity.setRawSamples( dataX, experiment.data().R().constData(), dataSize); qwtPlotCurveHallU.setRawSamples(dataX, experiment.data().Uhall().constData(), dataSize); ui->qwtPlot->replot(); } else { ui->coilBDoubleSpinBox->setValue(ui->coilBDoubleSpinBox->minimum()); ui->statusBar->showMessage("Warning: NAN in data found! ", 5000); } }
WT_USTRING WLocale::toFixedString(double value, int precision) const { std::stringstream ss; ss.precision(precision); ss << std::fixed << std::showpoint << value; return doubleToString(ss.str()); }
void ValueTraits<const double>::normalNumber( double t ) { char *s = doNegative( t ); s = doubleToString( t, s ); s = copyString( s, "." ); for ( unsigned i = 0; i < DIGITS_ON_RIGHT; ++ i ) s = numberToString( (unsigned)(t *= BASE) % BASE, s ); }
static inline std::ostream & toOstream( std::ostream & os, const std::map<std::string,double> & strDblMap ) { std::map<std::string,double>::const_iterator it; for( it = strDblMap.begin(); it != strDblMap.end(); it++ ) { os << addSpaces( it->first,MAX_STRING_LENGTH ) << " " << doubleToString( it->second,PRECISION_NUMBER ) << std::endl; } return os; }
string Utils::doubleToString(double value, int width, int afterDecimalPoint) { string tempString = doubleToString(value, afterDecimalPoint); char_array result; int dotPosition; if (afterDecimalPoint >= width) { return tempString; } // Initialize result result = char_array(width); for (int i = 0; i < result.size(); i++) { result[i] = ' '; } if (afterDecimalPoint > 0) { // Get position of decimal point and insert decimal point dotPosition = (int)tempString.find("."); if (dotPosition == -1) { dotPosition = (int)tempString.length(); } else { result[width - afterDecimalPoint - 1] = '.'; } } else { dotPosition = (int)tempString.length(); } int offset = width - afterDecimalPoint - dotPosition; if (afterDecimalPoint > 0) { offset--; } // Not enough room to decimal align within the supplied width if (offset < 0) { return tempString; } // Copy characters before decimal point for (int i = 0; i < dotPosition; i++) { result[offset + i] = tempString[i]; } // Copy characters after decimal point for (int i = dotPosition + 1; i < tempString.length(); i++) { result[offset + i] = tempString[i]; } return string(result.begin(), result.end()); }
void ZLDoubleOption::setValue(double value) { if (myIsSynchronized && (myValue == value)) { return; } myValue = value; myIsSynchronized = true; if (myValue == myDefaultValue) { unsetConfigValue(); } else { setConfigValue(doubleToString(myValue)); } }
void NPredicate::codeGen(CodeGenerator &c) { if (lhs) { lhs->codeGen(c); } std::string childParams = getChildParams(c, lhs, NULL); int channel = c.getChannel(variable); std::string line = std::string("node *n") + id() + std::string(" = ") + std::string("node_predicate_new") + std::string("(") + childParams + op + std::string(", ") + intToString(channel) + std::string(", ") + doubleToString(condition) + std::string(");"); c.emitLine(line); }
String toString() const { switch (type_) { case Type::BooleanTrue: return "true"; case Type::BooleanFalse: return "false"; case Type::NumberInt: return String(std::to_string(number_.i)); case Type::NumberFloat: return doubleToString(number_.f); default: return string_; } }
void NPredicate::print(std::ostream &os, AST *ast) { if (lhs) { os << "\t" + intToString(nodeId) + std::string(" -> ") + intToString(lhs->nodeId) + "\n"; lhs->print(os, ast); } std::string label; label = intToString(nodeId) + std::string("\n"); label += operator_type_strings[enumIndex(type)] + std::string("\n"); label += operator_subtype_strings[subTypeIndex(subtype)] + std::string("\n"); label += std::string("variable: ") + variable + std::string("\n"); label += std::string("operator: ") + op + std::string("\n"); label += std::string("condition: ") + doubleToString(condition); os << std::string("\t") + intToString(nodeId) + " [label=\"" + label + "\"];" + std::string("\n"); }
/** * Formats the given length in decimal (normal) format (e.g. 2.5). * * \param length The length in the current unit of the drawing. * \param prec Precision of the value (e.g. 0.001) & \param showUnit Append unit to the value. */ QString RUnit::formatDecimal(double length, RS::Unit unit, int prec, bool showUnit, bool showLeadingZeroes, bool showTrailingZeroes) { QString ret; // unit appended to value (e.g. 'mm'): ret = doubleToString(length, prec, showLeadingZeroes, showTrailingZeroes); if(showUnit) { ret+=unitToSymbol(unit); } return ret; }
void NEvent::codeGen(CodeGenerator &c) { std::string channel; std::string condition; if (lhs) { if (lhs->isBoolAtom()) { Node *lhs_ = c.ast->getNode((static_cast<NBoolAtom*>(lhs))->variable); int channel_ = c.getChannel((static_cast<NPredicate*>(lhs_))->variable); channel = std::string(", ") + intToString(channel_); condition = std::string(", ") + doubleToString((static_cast<NPredicate*>(lhs_))->condition); } } std::string childParams = getChildParams(c, NULL, NULL); std::string line = std::string("node *n") + id() + std::string(" = ") + std::string("node_event_new") + std::string("(") + childParams + operator_subtype_strings[subTypeIndex(subtype)] + channel + condition + std::string(");"); c.emitLine(line); }
deBool qpTestLog_writeValueFloat (qpTestLog* log, double value) { char tmpString[512]; doubleToString(value, tmpString, (int)sizeof(tmpString)); deMutex_lock(log->lock); DE_ASSERT(ContainerStack_getTop(&log->containerStack) == CONTAINERTYPE_SAMPLE); if (!qpXmlWriter_writeStringElement(log->writer, "Value", &tmpString[0])) { qpPrintf("qpTestLog_writeSampleValue(): Writing XML failed\n"); deMutex_unlock(log->lock); return DE_FALSE; } deMutex_unlock(log->lock); return DE_TRUE; }
void CodeGenerator::writeBoolProp(const std::string &filename) { BoolProperty p; for (auto kv : ast->defineDecl) { if (kv.second->type == operator_type::pred_t) { std::string name = kv.first; int port = getChannel(static_cast<NPredicate*>(kv.second)->variable); auto analogOpNode = static_cast<NPredicate*>(kv.second)->lhs; std::string analogOp = static_cast<NAnalog*>(analogOpNode)->op; std::string binOp = static_cast<NPredicate*>(kv.second)->op; std::string binOpCond = doubleToString(static_cast<NPredicate*>(kv.second)->condition); p.add(name, intToString(port), analogOp, binOp, binOpCond); } } p.writeXML(filename); }
bool TCPMessageUser::setAckMessage( std::map<int, std::shared_ptr<data::IPlayer>>& players) { if (queryType != QUERY_MSG_TYPE_USER::GET_PLAYERS_QUERY) return false; ackType = queryToAckMsgType(queryType); std::string tmp = ackMsgTypeUserToString(ackType); tmp += ":"; for (auto& i : players) { tmp += intToString(i.second->getKey()); tmp += " " + i.second->getName(); tmp += " " + intToString(i.second->getWins()); tmp += " " + intToString(i.second->getLooses()); tmp += " " + intToString(i.second->getPlayedGames()); tmp += " " + doubleToString(1.0);//i.second->getWinRatio()); // TODO tmp += " " + intToString(i.second->isLoggedIn()); tmp += "#"; } return TCPMessage::setAckMessage(tmp); }
std::string solve(std::string x){ x = calcengine::removeSpaces(x); std::stack<double> numberStack; std::stack<char> operatorStack; //setting priority std::map<char,int>priority; priority['+']=1; priority['-']=1; priority['*']=2; priority['/']=2; priority['^']=3; unsigned int i=0; if(x[0]=='+'||x[i]=='-'||x[i]=='*'||x[i]=='/'||x[i]=='^'||x[i]=='%') numberStack.push(last_result); for (;i<x.length();i++) { if((x[i]<='9'&&x[i]>='0')) { int j=i,times=0; //if this character is a number or unary operator while((x[j+1]<='9'&&x[j+1]>='0')||x[j+1]=='.') { times++; j++; } numberStack.push(atof(x.substr(i,times+1).c_str())); i=j; } //if this character is binary operator else if(x[i]=='+'||x[i]=='-'||x[i]=='*'||x[i]=='/'||x[i]=='^'||x[i]=='%') { if(i!=0) if(x[i-1]=='+'||x[i-1]=='-'||x[i-1]=='*'||x[i-1]=='/'||x[i-1]=='^'||x[i-1]=='%') return "Syntax Error"; if(!operatorStack.empty()) if(priority[operatorStack.top()]>=priority[x[i]]) solveStack(numberStack,operatorStack); operatorStack.push(x[i]); } //if this character is ')' else if(x[i]=='(') operatorStack.push(x[i]); //if this character is '(' solve the stack till ')' else if(x[i]==')') { while(operatorStack.top()!='(') { solveStack(numberStack,operatorStack); } operatorStack.pop(); } else return "Syntax Error"; } //solve the remaining in the stack while(numberStack.size()>1) { solveStack(numberStack,operatorStack); } //return the answer , the last elemenet in the stack last_result=0; return doubleToString(numberStack.top()); }
template<> std::string toString(double f) { return doubleToString(f); }
/** Replace all variables in given ArgList with their values. */ ArgList VariableArray::ReplaceVariables(ArgList const& argIn, DataSetList const& DSL, int debug) { if (debug > 0) mprintf("DEBUG: Before variable replacement: [%s]\n", argIn.ArgLine()); ArgList modCmd = argIn; for (int n = 0; n < modCmd.Nargs(); n++) { size_t pos = modCmd[n].find("$"); while (pos != std::string::npos) { // Argument is/contains a variable. Find first non-alphanumeric char size_t len = 1; for (size_t pos1 = pos+1; pos1 < modCmd[n].size(); pos1++, len++) if (!isalnum(modCmd[n][pos1])) break; std::string var_in_arg = modCmd[n].substr(pos, len); // See if variable occurs in CurrentVars_ Varray::const_iterator vp = CurrentVars_.begin(); for (; vp != CurrentVars_.end(); ++vp) if (vp->first == var_in_arg) break; // If found replace with value from CurrentVars_ if (vp != CurrentVars_.end()) { if (debug > 0) mprintf("DEBUG: Replaced variable '%s' with value '%s'\n", var_in_arg.c_str(), vp->second.c_str()); std::string arg = modCmd[n]; arg.replace(pos, vp->first.size(), vp->second); modCmd.ChangeArg(n, arg); } else { // Not found in CurrentVars_; see if this is a DataSet. for (size_t pos1 = pos+len; pos1 < modCmd[n].size(); pos1++, len++) if (!isalnum(modCmd[n][pos1]) && modCmd[n][pos1] != '[' && modCmd[n][pos1] != ':' && modCmd[n][pos1] != ']' && modCmd[n][pos1] != '_' && modCmd[n][pos1] != '-' && modCmd[n][pos1] != '%') break; var_in_arg = modCmd[n].substr(pos+1, len-1); DataSet* ds = DSL.GetDataSet( var_in_arg ); if (ds == 0) { mprinterr("Error: Unrecognized variable in command: %s\n", var_in_arg.c_str()); return ArgList(); } else { if (ds->Type() != DataSet::STRING && ds->Group() != DataSet::SCALAR_1D) { mprinterr("Error: Only 1D data sets supported.\n"); return ArgList(); } if (ds->Size() < 1) { mprinterr("Error: Set is empty.\n"); return ArgList(); } if (ds->Size() > 1) mprintf("Warning: Only using first value.\n"); std::string value; if (ds->Type() == DataSet::STRING) value = (*((DataSet_string*)ds))[0]; else value = doubleToString(((DataSet_1D*)ds)->Dval(0)); if (debug > 0) mprintf("DEBUG: Replaced variable '$%s' with value '%s' from DataSet '%s'\n", var_in_arg.c_str(), value.c_str(), ds->legend()); std::string arg = modCmd[n]; arg.replace(pos, var_in_arg.size()+1, value); modCmd.ChangeArg(n, arg); } } pos = modCmd[n].find("$"); } // END loop over this argument } return modCmd; }
String StringConv::floatToString(float _val, size_t _precision) { return doubleToString(_val, _precision); }
/* * processLine() * * Take a string, tokenise it, validate it and pass it on for calculation. This * is the glue function of ralcalc really. */ int processLine(const char *line, int quiet, displayMode dm, char siPrefix, int precision) { tokenItem tokenList; int rc; FILE *rcptr; double result; double lastResult = 0.0; int hasError = 0; char resultStr[100]; char formatStr[20]; if(!line) return errBadInput; if(rcpath){ rcptr = fopen(rcpath, "rb"); if(rcptr){ rc = fread(&lastResult, sizeof(double), 1, rcptr); if(rc != 1){ fprintf(stderr, "Warning: Previous value file corrupt, ignoring.\n"); lastResult = 0.0; } fclose(rcptr); } } /* First element always defined and not dynamic for less hassle */ tokenList.next = NULL; tokenList.type = tkEndToken; rc = tokenise(&tokenList, line, lastResult, quiet); if(rc != errNoError) hasError = 1; rc = validate(&tokenList, line, quiet); if(rc != errNoError) hasError = 1; rc = assignPrecedence(&tokenList); if(rc != errNoError) hasError = 1; if(!hasError && tokenList.next){ result = process(&(tokenList.next)); switch(dm){ case dmSI: doubleToString(result, resultStr, 100, siPrefix, precision); break; case dmExponent: if(precision == -1){ snprintf(resultStr, 100, "%lg", result); }else{ snprintf(formatStr, 20, "%%.%dlg", precision); snprintf(resultStr, 100, formatStr, result); } break; case dmRaw: if(precision == -1){ snprintf(resultStr, 100, "%f", result); }else{ snprintf(formatStr, 20, "%%.%df", precision); snprintf(resultStr, 100, formatStr, result); } break; } if(!quiet){ printf("%s = %s\n", line, resultStr); }else{ printf("%s\n", resultStr); } if(rcpath){ rcptr = fopen(rcpath, "wb"); if(rcptr){ rc = fwrite(&result, sizeof(double), 1, rcptr); if(rc != 1){ fprintf(stderr, "Error writing last value file.\n"); } fclose(rcptr); } } } if(tokenList.next) freeList(tokenList.next); return hasError; }