bool Value::isConvertibleTo( ValueType other ) const { switch ( other ) { case nullValue: return ( isNumeric() && asDouble() == 0.0 ) || ( type_ == booleanValue && value_.bool_ == false ) || ( type_ == stringValue && asString() == "" ) || ( type_ == arrayValue && value_.map_->empty() ) || ( type_ == objectValue && value_.map_->empty() ) || type_ == nullValue; case intValue: return isInt() || (type_ == realValue && InRange(value_.real_, minInt, maxInt)) || type_ == booleanValue || type_ == nullValue; case uintValue: return isUInt() || (type_ == realValue && InRange(value_.real_, 0, maxUInt)) || type_ == booleanValue || type_ == nullValue; case realValue: return isNumeric() || type_ == booleanValue || type_ == nullValue; case booleanValue: return isNumeric() || type_ == booleanValue || type_ == nullValue; case stringValue: return isNumeric() || type_ == booleanValue || type_ == stringValue || type_ == nullValue; case arrayValue: return type_ == arrayValue || type_ == nullValue; case objectValue: return type_ == objectValue || type_ == nullValue; } JSON_ASSERT_UNREACHABLE; return false; }
bool cVariant::cast( Type t ) { switch ( t ) { case StringType: asString(); break; case IntType: asInt(); break; case DoubleType: asDouble(); break; default: ( *this ) = cVariant(); } return canCast( t ); }
SEXP asSEXP(const matrix<Type> &a) { int nr=a.rows(); int nc=a.cols(); int size = nr * nc; SEXP val; PROTECT(val = allocVector(REALSXP,size)); double *p = REAL(val); for(int i=0;i<nr;i++) for(int j=0;j<nc;j++) p[i+j*nr]=asDouble(a(i,j)); SEXP dim; PROTECT(dim = allocVector(INTSXP,2)); INTEGER(dim)[0] = nr; INTEGER(dim)[1] = nc; setAttrib(val, R_DimSymbol, dim); UNPROTECT(2); return val; }
std::size_t dynamic::hash() const { switch (type()) { case OBJECT: case ARRAY: case NULLT: throw TypeError("not null/object/array", type()); case INT64: return std::hash<int64_t>()(asInt()); case DOUBLE: return std::hash<double>()(asDouble()); case BOOL: return std::hash<bool>()(asBool()); case STRING: return std::hash<fbstring>()(asString()); default: CHECK(0); abort(); } }
//--------------------------------------------------------- void CSG_Grid::Normalise(void) { if( is_Valid() ) { Update(); if( m_zStats.Get_StdDev() > 0.0 ) { int x, y; if( (Get_NoData_hiValue() > -NORMALISED_NODATA && Get_NoData_hiValue() < NORMALISED_NODATA) || (Get_NoData_Value () > -NORMALISED_NODATA && Get_NoData_Value () < NORMALISED_NODATA) ) { for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { for(x=0; x<Get_NX(); x++) { if( is_NoData(x, y) ) { Set_Value(x, y, -NORMALISED_NODATA); } } } Set_NoData_Value(-NORMALISED_NODATA); } for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { for(x=0; x<Get_NX(); x++) { if( !is_NoData(x, y) ) { Set_Value(x, y, (asDouble(x, y) - m_zStats.Get_Mean()) / m_zStats.Get_StdDev() ); } } } SG_UI_Process_Set_Ready(); Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Normalisation")); } } }
void RinexNavData::getPRNEpoch(const string& currentLine) throw(StringException, FFStreamError) { try { // check for spaces in the right spots... for (int i = 2; i <= 17; i += 3) if (currentLine[i] != ' ') throw(FFStreamError("Badly formatted line")); PRNID = asInt(currentLine.substr(0,2)); short yr = asInt(currentLine.substr(2,3)); short mo = asInt(currentLine.substr(5,3)); short day = asInt(currentLine.substr(8,3)); short hr = asInt(currentLine.substr(11,3)); short min = asInt(currentLine.substr(14,3)); double sec = asDouble(currentLine.substr(17,5)); // years 80-99 represent 1980-1999 const int rolloverYear = 80; if (yr < rolloverYear) yr += 100; yr += 1900; // Real Rinex has epochs 'yy mm dd hr 59 60.0' surprisingly often.... double ds=0; if(sec >= 60.) { ds=sec; sec=0.0; } time = CivilTime(yr,mo,day,hr,min,sec).convertToCommonTime(); if(ds != 0) time += ds; Toc = (static_cast<GPSWeekSecond>(time)).sow; af0 = gpstk::StringUtils::for2doub(currentLine.substr(22,19)); af1 = gpstk::StringUtils::for2doub(currentLine.substr(41,19)); af2 = gpstk::StringUtils::for2doub(currentLine.substr(60,19)); } catch (std::exception &e) { FFStreamError err("std::exception: " + string(e.what())); GPSTK_THROW(err); } }
JSString* JSValue::toStringSlowCase(ExecState* exec, bool returnEmptyStringOnError) const { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); auto errorValue = [&] () -> JSString* { if (returnEmptyStringOnError) return jsEmptyString(exec); return nullptr; }; ASSERT(!isString()); if (isInt32()) { auto integer = asInt32(); if (static_cast<unsigned>(integer) <= 9) return vm.smallStrings.singleCharacterString(integer + '0'); return jsNontrivialString(&vm, vm.numericStrings.add(integer)); } if (isDouble()) return jsString(&vm, vm.numericStrings.add(asDouble())); if (isTrue()) return vm.smallStrings.trueString(); if (isFalse()) return vm.smallStrings.falseString(); if (isNull()) return vm.smallStrings.nullString(); if (isUndefined()) return vm.smallStrings.undefinedString(); if (isSymbol()) { throwTypeError(exec, scope, ASCIILiteral("Cannot convert a symbol to a string")); return errorValue(); } ASSERT(isCell()); JSValue value = asCell()->toPrimitive(exec, PreferString); if (vm.exception()) return errorValue(); ASSERT(!value.isObject()); JSString* result = value.toString(exec); if (vm.exception()) return errorValue(); return result; }
bool Value::equals(Value& value) { if (isNull() && value.isNull()) return true; switch (_type) { case type_int: return (asInteger() == value.asInteger()); case type_text: return (asString().compare(value.asString()) == 0); case type_float: return (asDouble() == value.asDouble()); case type_bool: return (asBool() == value.asBool()); case type_time: return (asTime() == value.asTime()); } return false; }
void JSValue::dumpForBacktrace(PrintStream& out) const { if (!*this) out.print("<JSValue()>"); else if (isInt32()) out.printf("%d", asInt32()); else if (isDouble()) out.printf("%lf", asDouble()); else if (isCell()) { if (asCell()->inherits(JSString::info())) { JSString* string = jsCast<JSString*>(asCell()); const StringImpl* impl = string->tryGetValueImpl(); if (impl) out.print("\"", impl, "\""); else out.print("(unresolved string)"); } else if (asCell()->inherits(Structure::info())) { out.print("Structure[ ", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } else { out.print("Cell[", asCell()->structure()->classInfo()->className); #if USE(JSVALUE64) out.print(" ID: ", asCell()->structureID()); #endif out.print("]: ", RawPointer(asCell())); } } else if (isTrue()) out.print("True"); else if (isFalse()) out.print("False"); else if (isNull()) out.print("Null"); else if (isUndefined()) out.print("Undefined"); else out.print("INVALID"); }
bool MaxLikelihoodSmoothing::Estimate(const ParamVector ¶ms, const NgramLMMask *pMask, ProbVector &probs, ProbVector &bows) { if (!_estimated) { const CountVector &counts(_pLM->counts(_order)); const IndexVector &hists(_pLM->hists(_order)); // Compute inverse of sum of adjusted counts for each history. CountVector histCounts(_pLM->sizes(_order - 1), 0); ProbVector invHistCounts(histCounts.length()); BinCount(hists, histCounts); invHistCounts = 1.0 / asDouble(histCounts); // Compute maximum likelihood probability. 0 backoff. probs = counts * invHistCounts[hists]; bows.set(0); _estimated = true; } return true; }
char* JSValue::description() { static const size_t size = 32; static char description[size]; 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; }
//--------------------------------------------------------- bool CSG_Grid::_Save_ASCII(CSG_File &Stream, int xA, int yA, int xN, int yN, bool bFlip) { int x, y, ix, iy, dy; if( Stream.is_Open() && is_Valid() ) { Set_File_Type(GRID_FILE_FORMAT_ASCII); if( bFlip ) { y = yA + yN - 1; dy = -1; } else { y = yA; dy = 1; } //------------------------------------------------- for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy) { for(ix=0, x=xA; ix<xN; ix++, x++) { Stream.Printf(SG_T("%lf "), asDouble(x, y)); } Stream.Printf(SG_T("\n")); } SG_UI_Process_Set_Ready(); return( true ); } return( false ); }
//--------------------------------------------------------- void CSG_Grid::DeNormalise(double ArithMean, double Variance) { int x, y; if( is_Valid() ) { Variance = sqrt(Variance); for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++) { for(x=0; x<Get_NX(); x++) { if( !is_NoData(x, y) ) { Set_Value(x, y, Variance * asDouble(x, y) + ArithMean); } } } SG_UI_Process_Set_Ready(); Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Denormalisation")); } }
QString Degree::asQString() const { return QString::number( asDouble() ); }
QString Radian::asQString() const { return QString::number( asDouble() ); }
bool map::doScaling() { bool firstTime = false; bool map1d = false; if (scaledTriples.empty()) { firstTime = true; } if (data || loadData()) { int xMax = getXDim(); int yMax = getYDim(); zero = true; flat = true; double prev = 0.0; if (yMax == 1) { yMax = 2; map1d = true; } zValues->clear(); bool firstPoint = true; for (int y = 0; y < yMax; y++) { if (firstTime) { scaledTriples.append(new tripleVector()); } for (int x = 0; x < xMax; x++) { void* point; if (!map1d) { point = (void*) (data->constData() + (x * yMax + y) * wordSize); } else { point = (void*) (data->constData() + x * wordSize); } double raw = asDouble(point); // check for zero map if (raw != 0.0) { zero = false; } // checks for flat maps if (firstPoint) { prev = raw; firstPoint = false; } if (flat) { if (raw != prev) { flat = false; } prev = raw; } Qwt3D::Triple newTriple; newTriple.x = axisValue(0, x); if (!map1d) { newTriple.y = axisValue(1, y); } else { newTriple.y = y; } newTriple.z = raw * scaleFactor + offset; // Vector containing all the z values, used to create tics on the Z axis if (!zValues->contains(newTriple.z)) { zValues->append(newTriple.z); } if (firstTime) { scaledTriples.at(y)->append(newTriple); } else { scaledTriples.at(y)->replace(x, newTriple); } } } qSort(*zValues); dataRead = true; emit changed(); if (firstTime) { for (int i = 0; i < numAxes; i++) { connect(axes[i], SIGNAL(changed()), this, SLOT(axisChanged())); } } return true; } else { return false; } }
template<class T> int isnan(T x) { return std::isnan(asDouble(x)); }
template<class T> int R_finite(T x) { return std::isfinite(asDouble(x)); }
void JSValue::dumpInContextAssumingStructure( PrintStream& out, DumpContext* context, Structure* structure) const { if (!*this) out.print("<JSValue()>"); else if (isInt32()) out.printf("Int32: %d", asInt32()); else if (isDouble()) { #if USE(JSVALUE64) out.printf("Double: %lld, %lf", (long long)reinterpretDoubleToInt64(asDouble()), asDouble()); #else union { double asDouble; uint32_t asTwoInt32s[2]; } u; u.asDouble = asDouble(); out.printf("Double: %08x:%08x, %lf", u.asTwoInt32s[1], u.asTwoInt32s[0], asDouble()); #endif } else if (isCell()) { if (structure->classInfo()->isSubClassOf(JSString::info())) { JSString* string = jsCast<JSString*>(asCell()); out.print("String"); if (string->isRope()) out.print(" (rope)"); const StringImpl* impl = string->tryGetValueImpl(); if (impl) { if (impl->isAtomic()) out.print(" (atomic)"); if (impl->isAtomic()) out.print(" (identifier)"); if (impl->isSymbol()) out.print(" (symbol)"); } else out.print(" (unresolved)"); out.print(": ", impl); } else if (structure->classInfo()->isSubClassOf(Symbol::info())) out.print("Symbol: ", RawPointer(asCell())); else if (structure->classInfo()->isSubClassOf(Structure::info())) out.print("Structure: ", inContext(*jsCast<Structure*>(asCell()), context)); else if (structure->classInfo()->isSubClassOf(JSObject::info())) { out.print("Object: ", RawPointer(asCell())); out.print(" with butterfly ", RawPointer(asObject(asCell())->butterfly())); out.print(" (", inContext(*structure, context), ")"); } else { out.print("Cell: ", RawPointer(asCell())); out.print(" (", inContext(*structure, context), ")"); } #if USE(JSVALUE64) out.print(", ID: ", asCell()->structureID()); #endif } else if (isTrue()) out.print("True"); else if (isFalse()) out.print("False"); else if (isNull()) out.print("Null"); else if (isUndefined()) out.print("Undefined"); else out.print("INVALID"); }
Type rweibull(Type shape, Type scale) { return Rf_rweibull(asDouble(shape), asDouble(scale)); }
Type rt(Type df) { return Rf_rt(asDouble(df)); }
Type rlogis(Type location, Type scale) { return Rf_rlogis(asDouble(location), asDouble(scale)); }
Type rbeta(Type shape1, Type shape2) { return Rf_rbeta(asDouble(shape1), asDouble(shape2)); }
Type rexp(Type rate) { return Rf_rexp(asDouble(rate)); }
Type rgamma(Type shape, Type scale) { return Rf_rgamma(asDouble(shape), asDouble(scale)); }
SEXP stepLength(SEXP x0, SEXP y0, SEXP x1, SEXP y1, SEXP nautical){ return asSEXP(stepLength(asDouble(x0),asDouble(y0),asDouble(x1),asDouble(y1),asBool(nautical))); }
SEXP bearing(SEXP x0, SEXP y0, SEXP x1, SEXP y1, SEXP nautical){ return asSEXP(bearing(asDouble(x0),asDouble(y0),asDouble(x1),asDouble(y1),asBool(nautical))); }
Type rcompois(Type mode, Type nu) { Type loglambda = nu * log(mode); return atomic::compois_utils::simulate(asDouble(loglambda), asDouble(nu)); }
Type rf(Type df1, Type df2) { return Rf_rf(asDouble(df1), asDouble(df2)); }
Type rcompois2(Type mean, Type nu) { Type logmean = log(mean); Type loglambda = compois_calc_loglambda(logmean, nu); return atomic::compois_utils::simulate(asDouble(loglambda), asDouble(nu)); }