static Value f(Context *ctx, const List<Value>& args) { if (args.getCount() != 2) { ctx->throwException(createException(ExcType::ValueError, "Function takes only one argument.")); } return createFloat(F(asNumber(ctx, args[0]), asNumber(ctx, args[1]))); }
const double *WStandardChartProxyModel::markerScaleFactor(int row, int column) const { boost::any result = sourceModel_->data(row, column, MarkerScaleFactorRole); if (result.empty()) { return WAbstractChartModel::markerScaleFactor(row, column); } else { #ifndef WT_TARGET_JAVA return new double(asNumber(result)); #else double tmp = asNumber(result); return &tmp; #endif } }
bool VirtualValue::operator==(const VirtualValue& that) const { if ( mKind == that.mKind ) { switch ( mKind ) { case eEmpty: return true; case eNumber: return asNumber() == that.asNumber(); case eReal: return asReal() == that.asReal(); case eChar: return asChar() == that.asChar(); case eBool: return asBoolean() == that.asBoolean(); case eString: return asString() == that.asString(); case eObject: return &asObject() == &that.asObject(); case eArray: return &asArray() == &that.asArray(); } } return false; }
ConversionResultFlags JValue::asNumber<NumericString>(NumericString& number) const { std::string num; ConversionResultFlags result; result = asNumber(num); number = num; return result; }
static msg_t check_bounds(SEXP x, SEXP lower, SEXP upper) { double tmp; tmp = asNumber(lower, "lower"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } } tmp = asNumber(upper, "upper"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } } return MSGT; }
SEXP c_check_integerish(SEXP x, SEXP tol, SEXP lower, SEXP upper, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { double dtol = asNumber(tol, "tol"); if (!isIntegerish(x, dtol) && !all_missing_atomic(x)) return make_type_error(x, "integerish"); assert(check_vector_len(x, len, min_len, max_len)); assert(check_vector_names(x, names)); assert(check_vector_missings(x, any_missing, all_missing)); assert(check_bounds(x, lower, upper)); assert(check_vector_unique(x, unique)); return ScalarLogical(TRUE); }
SEXP c_check_int(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP tol) { Rboolean is_na = is_scalar_na(x); double dtol = asNumber(tol, "tol"); if (xlength(x) != 1 || (!is_na && !isIntegerish(x, dtol))) return make_type_error(x, "single integerish value"); if (is_na) { if (!asFlag(na_ok, "na.ok")) return make_result("May not be NA"); } assert(check_bounds(x, lower, upper)); return ScalarLogical(TRUE); }
std::optional<double> JSValue::toNumberFromPrimitive() const { if (isEmpty()) return std::nullopt; if (isNumber()) return asNumber(); if (isBoolean()) return asBoolean(); if (isUndefined()) return PNaN; if (isNull()) return 0; return std::nullopt; }
SEXP c_check_count(SEXP x, SEXP na_ok, SEXP positive, SEXP tol) { Rboolean is_na = is_scalar_na(x); double dtol = asNumber(tol, "tol"); if (xlength(x) != 1 || (!is_na && !isIntegerish(x, dtol))) return make_type_error(x, "count"); if (is_na) { if (!asFlag(na_ok, "na.ok")) return make_result("May not be NA"); } else { const int pos = (int) asFlag(positive, "positive"); if (asInteger(x) < pos) return make_result("Must be >= %i", pos); } return ScalarLogical(TRUE); }
// - LuaValue::operator== --------------------------------------------------- bool LuaValue::operator== (const LuaValue& rhs) const { std::string lhsTypeName = typeName(); std::string rhsTypeName = rhs.typeName(); if (typeName() != rhs.typeName()) return false; else switch (type()) { case LUA_TNIL: return true; case LUA_TBOOLEAN: return asBoolean() == rhs.asBoolean(); case LUA_TNUMBER: return asNumber() == rhs.asNumber(); case LUA_TSTRING: return asString() == rhs.asString(); case LUA_TTABLE: return asTable() == rhs.asTable(); case LUA_TFUNCTION: return asFunction() == rhs.asFunction(); case LUA_TUSERDATA: return asUserData() == rhs.asUserData(); default: { assert( false && "Invalid type found in a call to 'LuaValue::operator==()'."); return 0; // make compilers happy } } }
bool VirtualValue::operator>=(const VirtualValue& that) const { ASSERT(!isArray() && !isObject() && !isBoolean()); ASSERT(mKind == that.mKind); switch ( mKind ) { case eNumber: return asNumber() >= that.asNumber(); case eReal: return asReal() >= that.asReal(); case eChar: return asChar() >= that.asChar(); case eString: return asString() >= that.asString(); } return false; }
FALCON_FUNC Image::setColorMask( VMachine* vm ) { Mod::hpdf::Dict* self = dyncast<Mod::hpdf::Dict*>( vm->self().asObject() ); Item* i_rmin = vm->param( 0 ); Item* i_rmax = vm->param( 1 ); Item* i_gmin = vm->param( 2 ); Item* i_gmax = vm->param( 3 ); Item* i_bmin = vm->param( 4 ); Item* i_bmax = vm->param( 5 ); if ( vm->paramCount() < 6 || !i_rmin->isScalar() || !i_rmax->isScalar() || !i_gmin->isScalar() || !i_gmax->isScalar() || !i_bmin->isScalar() || !i_bmax->isScalar() ) throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) .extra("N,N,N,N,N,N") ); HPDF_Image_SetColorMask( self->handle(), asNumber(i_rmin), asNumber(i_rmax), asNumber(i_gmin), asNumber(i_gmax), asNumber(i_bmin), asNumber(i_bmax)); }
inline void resetNumber () { asNumber ().~Number (); value_type = Type_undefined; }
std::string JValue::asNumber<std::string>() const { std::string result; asNumber(result); return result; }
double JValue::asNumber<double>() const { double result = 0; asNumber(result); return result; }
int64_t JValue::asNumber<int64_t>() const { int64_t result = 0; asNumber(result); return result; }
// - LuaValue::operator> ---------------------------------------------------- bool LuaValue::operator> (const LuaValue& rhs) const { std::string lhsTypeName = typeName(); std::string rhsTypeName = rhs.typeName(); if (lhsTypeName > rhsTypeName) return true; else if (lhsTypeName < rhsTypeName) return false; else // lhsTypeName == rhsTypeName { if (lhsTypeName == "nil") return false; else if (lhsTypeName == "boolean") return asBoolean() > rhs.asBoolean(); else if (lhsTypeName == "number") return asNumber() > rhs.asNumber(); else if (lhsTypeName == "string") return asString() > rhs.asString(); else if (lhsTypeName == "function") return asFunction() > rhs.asFunction(); else if (lhsTypeName == "userdata") return asUserData() > rhs.asUserData(); else if (lhsTypeName == "table") { const LuaValueMap lhsMap = asTable(); const LuaValueMap rhsMap = rhs.asTable(); if (lhsMap.size() > rhsMap.size()) return true; else if (lhsMap.size() < rhsMap.size()) return false; else // lhsMap.size() == rhsMap.size() { typedef LuaValueMap::const_iterator iter_t; iter_t pLHS = lhsMap.begin(); iter_t pRHS = rhsMap.begin(); const iter_t end = lhsMap.end(); while (pLHS != end) { // check the key first if (pLHS->first > pRHS->first) return true; else if (pLHS->first < pRHS->first) return false; // then check the value if (pLHS->second > pRHS->second) return true; else if (pLHS->second < pRHS->second) return false; // make the iterators iterate ++pRHS; ++pLHS; } return false; } } else { assert (false && "Unsupported type found at a call " "to 'LuaValue::operator>()'"); return false; // make the compiler happy. } } }
double WStandardChartProxyModel::data(int row, int column) const { return asNumber(sourceModel_->data(row, column, DisplayRole)); }
void VirtualValue::int2real() { ASSERT(isNumber()); setReal(static_cast<float>(asNumber())); }