double LLBC_Variant::AsDouble() const { if (IsNil()) { return 0.0; } else if (IsDict()) { return 0.0; } else if (IsStr()) { return LLBC_Str2Double(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return _holder.raw.doubleVal; } if (IsSignedRaw()) { return static_cast<double>(_holder.raw.int64Val); } return static_cast<double>(_holder.raw.uint64Val); }
const LLBC_String &LLBC_Variant::AsStr() const { if (IsRaw()) { LLBC_Variant *nonConstThis = const_cast<LLBC_Variant *>(this); if (IsBool()) { nonConstThis->_holder.str = (_holder.raw.uint64Val ? "true" : "false"); } else if (IsFloat() || IsDouble()) { return nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.doubleVal); } else if (IsSignedRaw()) { nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.int64Val); } else { nonConstThis->_holder.str = LLBC_Num2Str(_holder.raw.uint64Val); } } else if (!IsStr()) { LLBC_Variant *nonConstThis = const_cast<LLBC_Variant *>(this); nonConstThis->CleanStrData(); } return _holder.str; }
int p_sincos(value val_arg, type tag_arg, value val_sin, type tag_sin, value val_cos, type tag_cos) { extern void sincos(); /* from the math library */ double s, c; Prepare_Requests; Error_If_Ref(tag_arg); Check_Output_Float(tag_sin); Check_Output_Float(tag_cos); if (IsDouble(tag_arg)) sincos(Dbl(val_arg), &s, &c); else if (IsInteger(tag_arg)) sincos((double) val_arg.nint, &s, &c); else { Error(TYPE_ERROR); } Request_Unify_Float(val_sin, tag_sin, s); Request_Unify_Float(val_cos, tag_cos, c); Return_Unify; }
LLBC_Variant &LLBC_Variant::BecomeDouble() { if (!IsDouble()) { *this = AsDouble(); } return *this; }
double ribi::QuadraticSolverMainDialog::AskUserForDouble() noexcept { while (1) { const std::string s = AskUserForString(); if (IsDouble(s)==false) continue; return boost::lexical_cast<double>(s); } }
std::string SEXPR::AsString( size_t aLevel ) { std::string result; if( IsList() ) { if( aLevel != 0 ) { result = "\n"; } result.append( aLevel* 4, ' ' ); aLevel++; result += "("; SEXPR_VECTOR const* list = GetChildren(); for( std::vector<SEXPR *>::const_iterator it = list->begin(); it != list->end(); ++it ) { result += (*it)->AsString( aLevel ); if( it != list->end() - 1 ) { result += " "; } } result += ")"; aLevel--; } else if( IsString() ) { result += "\"" + GetString() + "\""; } else if( IsSymbol() ) { result += GetSymbol(); } else if( IsInteger() ) { std::stringstream out; out << GetInteger(); result += out.str(); } else if( IsDouble() ) { std::stringstream out; out << std::setprecision( 16 ) << GetDouble(); result += out.str(); } return result; }
void Value::Read(ods::Ns &ns, ods::Attrs &attrs) { DeleteData(); auto *type_attr = attrs.Get(ns.office(), ods::ns::kValueType); if (type_attr == nullptr) { // shouldn't happen type_ = ods::Type::Fail; return; } type_ = ods::TypeFromString(type_attr->value()); auto *value_attr = attrs.Get(ns.office(), ods::ns::kValue); if (value_attr == nullptr) { type_ = ods::Type::Fail; return; } if (IsDouble() || IsPercentage() || IsCurrency()) { double num; if (!value_attr->ToDouble(num)) { mtl_warn("ToDouble()"); return; } set(new double(num), type_); } else if (IsString()) { set(new QString(value_attr->value()), ods::Type::String); } else if (IsDate()) { auto *custom_attr = attrs.Get(ns.office(), ods::ns::kDateValue); if (custom_attr == nullptr) { mtl_warn("custom_attr == nullptr"); return; } auto dt = QDateTime::fromString(custom_attr->value(), Qt::ISODate); set(new QDateTime(dt), type_); } else if (IsDuration()) { auto *custom_attr = attrs.Get(ns.office(), ods::ns::kTimeValue); if (custom_attr == nullptr) { mtl_warn("custom_attr == nullptr"); return; } auto *t = new ods::Duration(); t->Decode(custom_attr->value()); set(t, type_); } else { type_ = ods::Type::NotSet; } }
// make vector of columns (for tableData) // else - make vector of rows int ReadFile( const char *file, vector<vector<double>> &vec, const char *mes, int makeVectorOfColumns) { if(!file) throw info_except("File name is null?\n%s\n", mes); FILE *in = open(file, "r", mes); vec.clear(); if(!in) { if(mes != NULL) throw info_except("Cannot open file %s.\n%s\n", file, mes); else return 0; } std::vector<Stroka> line; vector<double> cur; Stroka err = ""; if(mes) err = mes; while(GetLine(in, line)) { cur.clear(); for(size_t i = 0; i < line.size(); i++) { double f; if(!IsDouble(line[i].c_str(), f, 1)) { cur.clear(); break; } cur.push_back(f); } if(cur.size() == 0) continue; if(makeVectorOfColumns) { if(vec.size() == 0) vec.resize(cur.size()); if(cur.size() != vec.size()) throw info_except( "File <%s>\nstr <%s>\nsize of str %i vector size %i\n%s", file, Str::JoinLine(line).c_str(), cur.size(), vec.size(), err.c_str()); for(size_t i = 0; i < line.size(); i++) vec[i].push_back(cur[i]); } else vec.push_back(cur); } close(in); return 1; }
//获取类型 BYTE CGameLogic::GetCardType(BYTE cbCardData[], BYTE cbCardCount) { //类型判断 if (IsTongHuaShun(cbCardData,cbCardCount)) return CT_TONG_HUA_SHUN; if (IsTieZhi(cbCardData,cbCardCount)) return CT_TIE_ZHI; if (IsHuLu(cbCardData,cbCardCount)) return CT_HU_LU; if (IsTongHua(cbCardData,cbCardCount)) return CT_TONG_HUA; if (IsShunZhi(cbCardData,cbCardCount)) return CT_SHUN_ZI; if (IsSanTiao(cbCardData,cbCardCount)) return CT_THREE_TIAO; if (IsDouble(cbCardData,cbCardCount)) return CT_DOUBLE; if (cbCardCount==1) return CT_SINGLE; return CT_ERROR; }
int Value::AsInt() const { if (IsNull()) return 0; else { if (IsInt() || IsDouble()) { std::stringstream sstr(valueStr); int val; sstr >> val; return val; } else throw ValueException();
void Value::DeleteData() { if (!Ok()) return; if (IsDouble() || IsPercentage()) delete AsDouble(); else if (IsString()) delete AsString(); else if (IsDate()) delete AsDate(); else if (IsDuration()) delete AsDuration(); data_ = nullptr; type_ = ods::Type::NotSet; }
///--------------------------------------------------------------------------------- /// ///--------------------------------------------------------------------------------- bool DeveloperConsoleArguments::GetDouble( double& doub ) { std::string string = ""; if (PeekString( string )) { if (IsDouble( string )) { doub = strtod( string.c_str(), nullptr ); m_currentIndex++; return true; } return false; } return false; }
QString Value::toString() const { if (!Ok()) return ""; if (IsDouble() || IsPercentage()) return QString::number(*AsDouble()); if (IsString()) return *AsString(); if (IsDate()) return AsDate()->toString(Qt::ISODate); if (IsCurrency()) mtl_qline("Currency not supported yet"); if (IsDuration()) return AsDuration()->ToString(); return ""; }
//获取牌型 BYTE CUpGradeGameLogic::GetCardShape(BYTE iCardList[], int iCardCount) { /*************************************************** 同花顺>铁支>葫芦>同花>顺子>三条>两对>对子>散牌 ***************************************************/ if (iCardCount <= 0) return UG_ERROR_KIND;//非法牌 if (IsSameHuaContinue(iCardList,iCardCount)) return SH_SAME_HUA_CONTINUE;//同花顺 if (IsSmallSameHuaContinue(iCardList,iCardCount)&&(m_dwCardShape&(0x00000001<<1))) return SH_SMALL_SAME_HUA_CONTINUE;//同花最小顺子 if (IsTieZhi(iCardList,iCardCount)) return SH_TIE_ZHI;//铁支 if (IsHuLu(iCardList,iCardCount)) return SH_HU_LU;//葫芦 if (IsSameHua(iCardList,iCardCount)) return SH_SAME_HUA;//同花 if (IsSingleContinue(iCardList,iCardCount)) return SH_CONTINUE;//顺子 if (IsSmallSingleContinue(iCardList,iCardCount)&&(m_dwCardShape&(0x00000001<<1))) return SH_SMALL_CONTINUE; //最小顺子 if (IsThree(iCardList,iCardCount)) return SH_THREE;//三条 if (IsCompleDouble(iCardList,iCardCount)) return SH_TWO_DOUBLE;//两对 if (IsDouble(iCardList,iCardCount)) return SH_DOUBLE;//对子 return SH_OTHER;//散牌 }
static void SendMessage(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> & _pendingMessages, const osc::ReceivedMessage & message) { const FName address(message.AddressPattern()); TArray<FOscDataElemStruct> data; const auto argBegin = message.ArgumentsBegin(); const auto argEnd = message.ArgumentsEnd(); for(auto it = argBegin; it != argEnd; ++it) { FOscDataElemStruct elem; if(it->IsFloat()) { elem.SetFloat(it->AsFloatUnchecked()); } else if(it->IsDouble()) { elem.SetFloat(it->AsDoubleUnchecked()); } else if(it->IsInt32()) { elem.SetInt(it->AsInt32Unchecked()); } else if(it->IsInt64()) { elem.SetInt(it->AsInt64Unchecked()); } else if(it->IsBool()) { elem.SetBool(it->AsBoolUnchecked()); } else if(it->IsString()) { elem.SetString(FName(it->AsStringUnchecked())); } data.Add(elem); } // save it in pending messages _pendingMessages.Enqueue(std::make_pair(address, data)); }
void Value::CopyTo(ods::Value &v) { v.type_set(type_); if (NoValue()) return; if (IsDouble()) v.SetDouble(*AsDouble()); else if (IsString()) v.SetString(*AsString()); else if (IsCurrency()) v.SetCurrency(*AsCurrency()); else if (IsPercentage()) v.SetPercentage(*AsPercentage()); else if (IsDate()) v.SetDate(*AsDate()); else if (IsDuration()) v.SetDuration(*AsDuration()); else mtl_warn("Not implemented"); }
uint64 LLBC_Variant::AsUInt64() const { if (IsNil()) { return 0; } else if (IsDict()) { return 0; } else if (IsStr()) { return LLBC_Str2UInt64(_holder.str.c_str()); } if (IsDouble() || IsFloat()) { return static_cast<uint64>(_holder.raw.doubleVal); } return _holder.raw.uint64Val; }
bool isDoubleObject() const { return IsDouble( this->ref ); }
bool PluginPreference::IsString() { return !IsBoolean() && !IsInteger() && !IsDouble(); }
bool ValidateParameters(DilutionAlgorithms algorithm, const vector<string> & parameters, string& ErrorMessage) { //unsigned int i = 0; unsigned int sum =0; int denom=0; if(parameters.size() == 0){ cerr<<"There are no parameters for the alogorithm."<<endl; return false; } switch (algorithm) { case MINMIX: /* * Each Concentration Value must be an integer. All values must be * declared before the names are declared. */ for(unsigned int i = 0; i< parameters.size(); ++i) if(!IsInteger(parameters[i])) break; for(unsigned int i = 0; i<parameters.size(); ++i) if(IsInteger(parameters[i])){ ErrorMessage = "Concentration values mixed with concetration names."; return false; } break; case REMIA: case WARA: case GORMA: /* * Each Concentration Value must be an integer. Numerator must be smaller * than denominator. Denominator must be a power of 2 */ for(unsigned int i = 0; i< parameters.size(); ++i) if(!IsInteger(parameters[i])){ ErrorMessage = "Parameter " + parameters[i] + " is not an integer."; return false; } for(unsigned int i = 0; i<parameters.size()-1; ++i) if(atoi(parameters[i].c_str()) >= atoi(parameters[parameters.size()-1].c_str())){ ErrorMessage = "Numerator can not be greater or equal to denominator."; return false; } if(!IsDivisibleofPower(atoi(parameters[parameters.size()-1].c_str()), 2)){ ErrorMessage = "Denominator is not power of 2."; return false; } break; case GDA: break; case CODOS: if(IsInteger(parameters[0])){ for(unsigned int i = 0 ; i < parameters.size(); ++i) { if(!IsInteger(parameters[i])){ ErrorMessage = parameters[i] + " is not an integer"; return false; } sum += atoi (parameters[i].c_str()); } } else { for(unsigned int i = 1; i < parameters.size(); i+=2) { if(!IsInteger(parameters[i])){ ErrorMessage = "\"" + parameters[i] + "\" is not an integer"; return false; } sum += atoi (parameters[i].c_str()); if(!IsDouble(parameters[i+1])){ ErrorMessage = parameters[i] + " is not an Price(double)."; return false; } } } if(!IsDivisibleofPower(sum, 2)){ ErrorMessage = "Sum of concentration values are not a power of two."; return false; } break; case NRT_ISI: for(unsigned int i =0; i < parameters.size(); ++i){ if(!IsInteger(parameters[i])){ ErrorMessage = "\"" + parameters[i] + "\" is not an integer"; return false; } } break; case ISINCKU: //TODO:: Check OutOfRange validation. for(unsigned int i =0; i < parameters.size(); ++i){ if(!IsInteger(parameters[i])){ ErrorMessage = "\"" + parameters[i] + "\" is not an integer"; return false; } } break; case IDMA:/*numOps, tolerance, DesiredConcentrate*/ case GRIFFITH: case DMRW: if(parameters.size()<3){ ErrorMessage = "Incorrect number of parameters."; return false; } if(!IsInteger(parameters[0])) { ErrorMessage = "NumOps is not an integer."; return false; } for( unsigned int i= 1; i < parameters.size(); ++i) { if(!IsDouble(parameters[i])){ ErrorMessage = parameters[i] + " is not a double."; return false; } } break; case MTC: if(IsInteger(parameters[0])){ denom = atoi(parameters[0].c_str()); if(!IsDivisibleofPower(denom, 2)){ ErrorMessage = "Denominator: " + parameters[0] + " needs to be a power of 2."; return false; } } else { ErrorMessage = parameters[0] + "is not an integer."; return false; } for(unsigned int i = 1; i<parameters.size(); ++i) { if(!IsInteger(parameters[i])) { ErrorMessage = "\"" + parameters[i] + "\" is not an integer."; return false; } if(denom <= atoi(parameters[i].c_str())){ ErrorMessage = "The numerator: " + parameters[i] + " needs to be smaller than the denominator " + parameters[0] + "."; return false; } } break; default: break; } return true; }
/* SetTokenDouble function */ void SetTokenData(struct ST_SUIM *pS, char *pchLine, int inTokenSt) { int inFlag = IsNullOrEmpty(pchLine); if(inFlag!= 0) return; int inCntToken = 0; char *pchSt = pchLine; char *pchEd = strchr(pchSt, ' '); while(1) { char pchWord[MAX_WORD]; if(pchEd== NULL) { strcpy(pchWord, pchSt); } else { int inLength = pchEd- pchSt; strncpy(pchWord, pchSt, inLength); pchWord[inLength] = '\0'; } //copy token word strcpy(&pS->pchListTokenWord[MAX_WORD * (inTokenSt + inCntToken)], pchWord); //setup token type if(isalpha(pchWord[0]) && isalpha(pchWord[1])) { pS->pchListTokenType[inTokenSt + inCntToken] = 2; } else { if(pchWord[0]== '-' && isalpha(pchWord[1]) && isalpha(pchWord[2])) { pS->pchListTokenType[inTokenSt + inCntToken] = 3; } else { int isDouble = IsDouble(pchWord); if(isDouble) { pS->pchListTokenType[inTokenSt + inCntToken] = 1; pS->pdoListToken[inTokenSt + inCntToken] = atof(pchSt); } else { if(pchWord[0]== '+') { pS->pchListTokenType[inTokenSt + inCntToken] = 4; } else { if(pchWord[0]== '=' && pchWord[1]== '=') { pS->pchListTokenType[inTokenSt + inCntToken] = 5; } else { if(pchWord[0]== '!' && pchWord[1]== '=') { pS->pchListTokenType[inTokenSt + inCntToken] = 6; } else { if(pchWord[0]== '-') { pS->pchListTokenType[inTokenSt + inCntToken] = 7; } else { if(pchWord[0]== '*') { pS->pchListTokenType[inTokenSt + inCntToken] = 8; } else { if(pchWord[0]== '/') { pS->pchListTokenType[inTokenSt + inCntToken] = 9; } else { if(pchWord[0]== '%') { pS->pchListTokenType[inTokenSt + inCntToken] = 10; } else { if(pchWord[0]== '>' && pchWord[1]== '=') { pS->pchListTokenType[inTokenSt + inCntToken] = 11; } else { if(pchWord[0]== '<' && pchWord[1]== '=') { pS->pchListTokenType[inTokenSt + inCntToken] = 12; } else { if(pchWord[0]== '>') { pS->pchListTokenType[inTokenSt + inCntToken] = 13; } else { if(pchWord[0]== '<') { pS->pchListTokenType[inTokenSt + inCntToken] = 14; } else { if(pchWord[0]== '&' && pchWord[1]== '&') { pS->pchListTokenType[inTokenSt + inCntToken] = 15; } else { if(pchWord[0]== '|' && pchWord[1]== '|') { pS->pchListTokenType[inTokenSt + inCntToken] = 16; } } } } } } } } } } } } } } } } inCntToken++; if(pchEd== NULL) break; pchSt = pchEd + 1; pchEd = strchr(pchSt, ' '); } }