void camiaoi_modifica(MainTreePt camioes, TabelaHashPTR localidades){ char *matricula=NULL, *local=NULL, vazia[1]={'\0'}; LinkedListPTR localidade=NULL; double custo, peso; printf("Introduza a matricula do camiao a modificar > "); lerStr( &matricula); printf("Custo (por Km) > "); if( isDouble(custo = readDouble()) == 0 ) printf("Erro: Valor inválido (veja as instruções acima)"); //erro printf("Peso máximo da carga > "); if( isDouble(peso = readDouble()) == 0 ) printf("Erro: Valor inválido (veja as instruções acima)"); //erro printf("Localidade actual > "); lerStr( &local ); while( (localidade = procuraTabelaHash( localidades, crialocalidade(local) ) ) == NULL && strcmp(local,vazia) != 0 ){ printf("Erro: Localidade não foi encontrada. Para cancelar apenas pressione [ENTER].\nLocalidade actual > "); lerStr( &local ); } free(localidade); if( strcmp(local,vazia) == 0 ){ printf("Cancelou a introdução.\n"); free(matricula); free(local); }else{ camiao_substituiPelaMatricula( camioes, matricula, custo, peso, local ); printf("Modificado!"); } }
void TScannerParameters::loadData(TIStream &is) { std::string tagName; while (is.matchTag(tagName)) { if (tagName == "dpi") { std::string s = is.getTagAttribute("value"); if (isDouble(s)) m_dpi.m_value = std::stof(s); } else if (tagName == "brightness") { std::string s = is.getTagAttribute("value"); if (isDouble(s)) m_brightness.m_value = std::stof(s); } else if (tagName == "threshold") { std::string s = is.getTagAttribute("value"); if (isDouble(s)) m_threshold.m_value = std::stof(s); } else if (tagName == "contrast") { std::string s = is.getTagAttribute("value"); if (isDouble(s)) m_contrast.m_value = std::stof(s); } else if (tagName == "autoFeeder") { m_paperFeeder.m_value = 1.0; } else if (tagName == "reverseOrder") { m_reverseOrder = true; } else if (tagName == "mode") { std::string scanTypeString = is.getTagAttribute("value"); m_scanType = None; if (scanTypeString == BlackAndWhite) m_scanType = BW; else if (scanTypeString == Graytones) m_scanType = GR8; else if (scanTypeString == Rgbcolors) m_scanType = RGB24; } else if (tagName == "paper") { std::string paperFormat = is.getTagAttribute("fmt"); if (paperFormat != "") setPaperFormat(paperFormat); } } m_validatedByCurrentScanner = false; }
void AstNodeDType::dumpSmall(ostream& str) { str<<"(" <<(generic()?"G/":"") <<((isSigned()&&!isDouble())?"s":"") <<(isNosign()?"n":"") <<(isDouble()?"d":"") <<"w"<<(widthSized()?"":"u")<<width(); if (!widthSized()) str<<"/"<<widthMin(); str<<")"; }
bool GenericType::can_cast_to(opt_type other) const { switch (other) { case OT_BOOLEAN: return isBool() || isInt() || isDouble(); case OT_BOOLVECTOR: return isIntVector() || isDoubleVector(); case OT_INTEGER: case OT_REAL: return isInt() || isDouble(); case OT_INTEGERVECTOR: case OT_REALVECTOR: return isDoubleVector() || isIntVector(); default: return type_ == other; } }
long long TVar::asInteger() const { long long ret = 0; if (isInteger()) { ret = inum; } else if (isDouble()) { ret = static_cast<long long>(dnum); } else if (isString()) { try { ret = std::stoll(str); } catch (std::exception&) { // TODO: log } } else { // TODO: log } return ret; };
/* Set the units of an image to the data stored in an mxArray, * * Parameters: * -mx: An array of IM_NDIMS dimensions, type double. * -im: The Image struct to which the units are written. * * Return: SIFT3D_SUCCESS on success, SIFT3D_FAILURE otherwise. */ int mx2units(const mxArray *const mx, Image *const im) { const mwSize *mxDims; double *mxData; mwIndex mxNDims; int i; // Verify inputs mxNDims = (int) mxGetNumberOfDimensions(mx); if (mxNDims != 2 || !isDouble(mx)) return SIFT3D_FAILURE; // Verify the dimensions mxDims = mxGetDimensions(mx); if (mxDims[0] != IM_NDIMS || mxDims[1] != 1) return SIFT3D_FAILURE; // Get the data if ((mxData = mxGetData(mx)) == NULL) return SIFT3D_FAILURE; // Copy the data to im for (i = 0; i < IM_NDIMS; i++) { mwIndex idx; const mwIndex subs[] = {i, 0}; const mwIndex nSubs = sizeof(subs) / sizeof(mwIndex); idx = mxCalcSingleSubscript(mx, nSubs, subs); SIFT3D_IM_GET_UNITS(im)[i] = mxData[idx]; } return SIFT3D_SUCCESS; }
bool GenericType::operator!=(const GenericType& op2) const{ if(isString() && op2.isString()){ return toString().compare(op2.toString()) != 0; } if(isInt() && op2.isInt()){ return toInt() != op2.toInt(); } if(isDouble() && op2.isDouble()){ return toDouble() != op2.toDouble(); } if(isDoubleVector() && op2.isDoubleVector()){ const vector<double> &v1 = toDoubleVector(); const vector<double> &v2 = op2.toDoubleVector(); if(v1.size() != v2.size()) return true; for(int i=0; i<v1.size(); ++i) if(v1[i] != v2[i]) return true; return false; } if(isIntVector() && op2.isIntVector()){ const vector<int> &v1 = toIntVector(); const vector<int> &v2 = op2.toIntVector(); if(v1.size() != v2.size()) return true; for(int i=0; i<v1.size(); ++i) if(v1[i] != v2[i]) return true; return false; } // Different types return true; }
double TVar::asDouble() const { double ret = 0; if (isDouble()) { ret = dnum; } else if (isInteger()) { ret = static_cast<double>(inum); } else if (isString()) { try { ret = std::stod(str); } catch (std::exception&) { // TODO: log } } else { // TODO: log } return ret; };
char* JSValue::description() { static const size_t size = 32; static char description[size]; if (!*this) snprintf(description, size, "<JSValue()>"); else if (isInt32()) snprintf(description, size, "Int32: %d", asInt32()); else if (isDouble()) snprintf(description, size, "Double: %lf", asDouble()); else if (isCell()) snprintf(description, size, "Cell: %p", asCell()); else if (isTrue()) snprintf(description, size, "True"); else if (isFalse()) snprintf(description, size, "False"); else if (isNull()) snprintf(description, size, "Null"); else { ASSERT(isUndefined()); snprintf(description, size, "Undefined"); } return description; }
/**jsdoc * A material or set of materials such as may be used by a {@link Entities.EntityType|Material} entity. * @typedef {object} MaterialResource * @property {number} materialVersion=1 - The version of the material. <em>Currently not used.</em> * @property {Material|Material[]} materials - The details of the material or materials. */ NetworkMaterialResource::ParsedMaterials NetworkMaterialResource::parseJSONMaterials(const QJsonDocument& materialJSON, const QUrl& baseUrl) { ParsedMaterials toReturn; if (!materialJSON.isNull() && materialJSON.isObject()) { QJsonObject materialJSONObject = materialJSON.object(); for (auto& key : materialJSONObject.keys()) { if (key == "materialVersion") { auto value = materialJSONObject.value(key); if (value.isDouble()) { toReturn.version = (uint)value.toInt(); } } else if (key == "materials") { auto materialsValue = materialJSONObject.value(key); if (materialsValue.isArray()) { QJsonArray materials = materialsValue.toArray(); for (auto material : materials) { if (!material.isNull() && material.isObject()) { auto parsedMaterial = parseJSONMaterial(material.toObject(), baseUrl); toReturn.networkMaterials[parsedMaterial.first] = parsedMaterial.second; toReturn.names.push_back(parsedMaterial.first); } } } else if (materialsValue.isObject()) { auto parsedMaterial = parseJSONMaterial(materialsValue.toObject(), baseUrl); toReturn.networkMaterials[parsedMaterial.first] = parsedMaterial.second; toReturn.names.push_back(parsedMaterial.first); } } } } return toReturn; }
const Double& Value::toDouble() const { if (not isDouble()) { throw utils::CastError(_("Value is not a double")); } return static_cast<const Double&>(*this); }
double GenericType::toDouble() const{ if(isInt()){ return double(toInt()); } else { casadi_assert_message(isDouble(),"type mismatch"); return static_cast<const DoubleType*>(get())->d_; } }
void RepoQuery::getDouble(int iCol, double& val) { if (!isDouble(iCol)) { throw RepoExc( "RepoQuery::%s(repo=%p) error: Column %d is not a double in '%s'", __func__, &m_stmt.repo(), iCol, m_stmt.sql().c_str()); } val = sqlite3_column_double(m_stmt.get(), iCol); }
bool SequenceBinomialDistribution::validateValues(){ if (!isDouble(form->getTextBoxValue("txtExperimentsNumber"))) return false; // Zahl der Versuche muss ganzzahlig und >0 sein double expNum = Double::Parse(form->getTextBoxValue("txtExperimentsNumber")); if (Math::Ceiling(expNum) != expNum || expNum <= 0) return false; if (!isDouble(form->getTextBoxValue("txtSuccessProbability"))) return false; // Erfolgswahrscheinlichkeit soll zwischen 0 und 1 liegen double succProb = Double::Parse(form->getTextBoxValue("txtSuccessProbability")); if (succProb < 0 || succProb > 1) return false; return SequenceDistribution::validateValues(); }
bool AsmJsType::isSubType(AsmJsType type) const { switch (type.which_) { case Js::AsmJsType::Double: return isDouble(); break; case Js::AsmJsType::MaybeDouble: return isMaybeDouble(); break; case Js::AsmJsType::DoubleLit: return isDoubleLit(); break; case Js::AsmJsType::Float: return isFloat(); break; case Js::AsmJsType::MaybeFloat: return isMaybeFloat(); break; case Js::AsmJsType::Floatish: return isFloatish(); break; case Js::AsmJsType::FloatishDoubleLit: return isFloatishDoubleLit(); break; case Js::AsmJsType::Fixnum: return which_ == Fixnum; break; case Js::AsmJsType::Int: return isInt(); break; case Js::AsmJsType::Signed: return isSigned(); break; case Js::AsmJsType::Unsigned: return isUnsigned(); break; case Js::AsmJsType::Intish: return isIntish(); break; case Js::AsmJsType::Void: return isVoid(); break; case AsmJsType::Int32x4: return isSIMDInt32x4(); break; case AsmJsType::Float32x4: return isSIMDFloat32x4(); break; case AsmJsType::Float64x2: return isSIMDFloat64x2(); break; default: break; } return false; }
bool SequenceDouble::validateValues(){ if (!isDouble(form->getTextBoxValue("txtCount"))) return false; // Anzahl muss ganzzahlig und >0 sein double cnt = Double::Parse(form->getTextBoxValue("txtCount")); if (Math::Ceiling(cnt) != cnt || cnt <= 0) return false; return true; }
uint32_t VFPRegister::getRegisterDumpOffsetInBytes() { if (isSingle()) return id() * sizeof(float); if (isDouble()) return id() * sizeof(double); MOZ_ASSUME_UNREACHABLE(); }
int32_t CppVariant::toInt32() const { if (isInt32()) return value.intValue; if (isDouble()) return static_cast<int32_t>(value.doubleValue); BLINK_ASSERT_NOT_REACHED(); return 0; }
double CppVariant::toDouble() const { if (isInt32()) return static_cast<double>(value.intValue); if (isDouble()) return value.doubleValue; WEBKIT_ASSERT_NOT_REACHED(); return 0; }
double JSValue::toNumberSlowCase(ExecState* exec) const { ASSERT(!isInt32() && !isDouble()); if (isCell()) return asCell()->toNumber(exec); if (isTrue()) return 1.0; return isUndefined() ? PNaN : 0; // null and false both convert to 0. }
uint32_t FloatRegister::getRegisterDumpOffsetInBytes() { if (isSingle()) return id() * sizeof(float); if (isDouble()) return id() * sizeof(double); MOZ_CRASH(); }
double toScalar() const { if (isInteger()) return toInteger(); if (isDouble()) return toDouble(); qWarning("can't cast term to scalar"); return 0.0; }
Tree sigIntCast(Tree t) { Node n = t->node(); int i; if (isInt(n, &i)) return t; double x; if (isDouble(n, &x)) return tree(int(x)); if (isSigIntCast(t)) return t; return tree(SIGINTCAST, t); }
Tree sigFloatCast(Tree t) { Node n = t->node(); int i; if (isInt(n, &i)) return tree(double(i)); double x; if (isDouble(n, &x)) return t; if (isSigFloatCast(t)) return t; if (isSigInput(t, &i)) return t; return tree(SIGFLOATCAST, t); }
__int64 TVar::getInteger() const { __int64 ret = inum; if (isString()) ret = str ? _wtoi64(str) : 0; else if (isDouble()) ret=(__int64)dnum; return ret; };
JSObject* JSValue::toThisObjectSlowCase(ExecState* exec) const { ASSERT(!isCell()); if (isInt32() || isDouble()) return constructNumber(exec, asValue()); if (isTrue() || isFalse()) return constructBooleanFromImmediateBoolean(exec, asValue()); ASSERT(isUndefinedOrNull()); return exec->globalThisValue(); }
void OSCServerThread::run() { oscpkt::UdpSocket server; server.bindTo(this->port); if (!server.isOk()) { std::cerr << "Error opening OSC server at " << port << std::endl; return; } std::cout << "Started OSC Server at " << port << std::endl; oscpkt::PacketReader reader; oscpkt::PacketWriter writer; while (server.isOk() && !mustQuit) { if (server.receiveNextPacket(30)) { reader.init(server.packetData(), server.packetSize()); oscpkt::Message *msg; while (reader.isOk() && (msg = reader.popMessage()) != 0) { QVariantList message; message.append(QString::fromStdString( msg->addressPattern())); auto args = msg->arg(); while (!args.isOkNoMoreArgs()) { if (args.isInt32()) { int32_t i; args = args.popInt32(i); message.append(i); } else if (args.isInt64()) { int64_t i; args = args.popInt64(i); message.append( static_cast<qlonglong>(i)); } else if (args.isFloat()) { float f; args = args.popFloat(f); message.append(f); } else if (args.isDouble()) { double d; args = args.popDouble(d); message.append(d); } else if (args.isStr()) { std::string s; args = args.popStr(s); message.append( QString::fromStdString(s)); } } emit messageIn(message); } } } }
void ParamWrapper::setValue(double value) { if(isDouble()) { *double_param = value; } else { crusde_error("ParamWrapper::setValue : try setting double when param is not double\n"); } }
void TPaperFormatManager::readPaperFormat(const TFilePath &path) { if (path.getType() != "pap") return; Tifstream is(path); std::string name; TDimensionD size(0, 0); while (is) { char buffer[1024]; is.getline(buffer, sizeof buffer); // i e' il carattere successivo alla fine della linea unsigned int i = 0; for (i = 0; i < sizeof buffer && buffer[i]; i++) { } if (i > 0 && buffer[i - 1] == '\n') i--; while (i > 0 && buffer[i - 1] == ' ') i--; unsigned int j = 0; unsigned int k = 0; // j e' il carattere successivo alla fine del primo token for (j = 0; j < i && buffer[j] != ' '; j++) { } // k e' l'inizio del secondo token (se c'e', altrimenti == i) for (k = j; k < i && buffer[k] == ' '; k++) { } std::string value; if (k < i) value = std::string(buffer + k, i - k); if (buffer[0] == '#') { if (k < i && name == "") name = value; } else if (std::string(buffer).find("WIDTH") == 0) { if (isDouble(value)) size.lx = std::stod(value); } else if (std::string(buffer).find("LENGTH") == 0) { if (isDouble(value)) size.ly = std::stod(value); } } if (name == "" || size.lx == 0 || size.ly == 0) { // TMessage::error("Error reading paper format file : %1",path); } else m_formats[name] = Format(size); }
int GenericType::toInt() const{ if(isDouble()){ double v = toDouble(); casadi_assert_message(v == std::floor(v),"The value is not an integer"); return int(v); } else if (isBool()) { return int(toBool()); } else { casadi_assert_message(isInt(),"type mismatch"); return static_cast<const IntType*>(get())->d_; } }