本文整理汇总了C++中Double类的典型用法代码示例。如果您正苦于以下问题:C++ Double类的具体用法?C++ Double怎么用?C++ Double使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Double类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: abs
void Double::operator -=(const Double other)
{
int rate = digs - other.getDig();
if(rate == 0){
lv -= other.getlv();
// if(digs > 2){
// lv = reduce(lv,digs-2);
// digs=2;
// }
}
else{
int rates=1;
int c = abs(rate);
for(int i = 0; i < c; ++i)
rates *= 10;
if(rate > 0)
lv -= other.getlv()*rates;
else{
lv *= rates;
lv -= other.getlv();
}
//lv = reduce(lv,c);
digs = max(digs,other.getDig());
}
}
示例2: reduce
void Double::operator *=(const Double other)
{
lv *= other.getlv();
lv = reduce(lv,digs+other.getDig()-2);
digs = 2;
}
示例3: sci_inspectorGetUnreferencedItem
Function::ReturnValue sci_inspectorGetUnreferencedItem(typed_list &in, int _iRetCount, typed_list &out)
{
if (in.size() != 1)
{
Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "inspectorGetItem", 1);
return Function::Error;
}
if (in[0]->isDouble() == false)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "inspectorGetItem", 1);
return Function::Error;
}
Double *pD = in[0]->getAs<Double>();
if (pD->isScalar() == false)
{
Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), "inspectorGetItem", 1);
Function::Error;
}
int iPos = (int)pD->get(0) - 1;
out.push_back(Inspector::getUnreferencedItem(iPos));
return Function::OK;
}
示例4:
Double Double::operator=( Double const & cpy )
{
this->val_str = cpy.getValStr();
this->val = cpy.getVal();
this->type = cpy.getType();
return (*this);
}
示例5: adjustValue
bool Double::operator <=(const Double &other) const
{
int rate = digs - other.getDig();
if(rate == 0)
return lv <= other.getlv();
qint64 v1=lv,v2=other.getlv();
adjustValue(rate,v1,v2);
return v1<=v2;
}
示例6: Date
result
User::updateFromDictionary(HashMap *dictionary)
{
result success = E_FAILURE;
if (dictionary && !dictionary->ContainsKey(kHTTPParamNameError)) {
Double *idValue = static_cast<Double *>(dictionary->GetValue(kHTTPParamNameUserID));
if (idValue) {
_id = idValue->ToInt();
success = E_SUCCESS;
}
String *usernameValue = static_cast<String *>(dictionary->GetValue(kHTTPParamNameUsername));
if (usernameValue) {
_username = *usernameValue;
success = E_SUCCESS;
}
String *emailValue = static_cast<String *>(dictionary->GetValue(kHTTPParamNameEmail));
if (emailValue) {
_email = *emailValue;
success = E_SUCCESS;
}
String *avatarUrlValue = static_cast<String *>(dictionary->GetValue(kHTTPParamNameAvatarUrl));
if (avatarUrlValue) {
_avatarUrl = *avatarUrlValue;
success = E_SUCCESS;
}
HashMap *dateDictionary = static_cast<HashMap *>(dictionary->GetValue(kHTTPParamNameDateCreated));
if (dateDictionary) {
_dateCreated = new Date();
result dateSuccess = _dateCreated->updateFromDictionary(dateDictionary);
if (IsFailed(dateSuccess)) {
delete _dateCreated;
_dateCreated = NULL;
} else {
success = E_SUCCESS;
}
}
if (!IsFailed(success)) {
if (_listeners) {
IEnumerator *iter = _listeners->GetEnumeratorN();
while (iter->MoveNext() == E_SUCCESS) {
UserListener *listener = static_cast<UserListener *>(iter->GetCurrent());
listener->onUserUpdate(this);
}
delete iter;
}
}
}
return success;
}
示例7: getDouble
double getDouble(Atom *a)
{
Double *d = dynamic_cast<Double*>(a);
#ifdef _DEBUG
if (d == 0) {
throw std::exception("Double以外の型を変換しようとしました");
}
#endif
return d->getValue();
}
示例8: div
bool Double::div(const Double &other)
{
if (other.getDouble() == 0)
{
return false;
}
else
{
data /= other.getDouble();
return true;
}
}
示例9: Test002
static void Test002(TestUnit *tu)
{
tu->runTestCase(__FUNCTION__);
StringSeparator ss("0.25");
Atom *a = ListGenerator::generate(ss);
tu->assertTrue(a->getType() == "Double", __LINE__);
Double *it = dynamic_cast<Double*>(a);
tu->assertTrue(it->getValue() == 0.25, __LINE__);
return ;
}
示例10: Q_ASSERT
/**
* @brief Double::operator /
* 为保留精度,被除数的小数位数必须比除数多3以上,这里为了尽可能保留精度,
* 将被除数相对于除数扩大10000倍,这样可以将商保留4位小数
* @param other
* @return
*/
Double Double::operator /(const Double &other) const
{
Q_ASSERT(other != 0);
qint64 v,v1,v2;
int rate = digs-other.getDig();
v1=lv; v2=other.getlv();
if(rate<4){
for(int i = rate; i<4; ++i)
v1*=10;
}
v = v1/v2;
v = reduce(v,2);
return Double(v,2);
}
示例11: Double
types::InternalType* opposite_M<types::Bool, types::Double>(types::Bool* _pL)
{
Double* pOut = new Double(_pL->getDims(), _pL->getDimsArray());
int iSize = _pL->getSize();
int* pI = _pL->get();
double* pD = pOut->get();
for (int i = 0 ; i < iSize ; ++i)
{
pD[i] = pI[i] == 0 ? 1 : 0;
}
return pOut;
}
示例12: Test004
static void Test004(TestUnit *tu)
{
tu->runTestCase(__FUNCTION__);
Atom *a = Evaluator::eval(
ListGenerator::generate(
StringSeparator("(* 10 3 1.5)")
));
Double *result = dynamic_cast<Double*>(a);
tu->assertTrue(result->getType() == "Double", __LINE__);
tu->assertTrue(result->getValue() == 45.0, __LINE__);
return ;
}
示例13: main
int main()
{
// Gets a NumberFormatInfo associated with the en-US culture.
CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
NumberFormatInfo^ nfi = MyCI->NumberFormat;
// Displays a value with the default separator (S".").
Double myInt = 0.1234;
Console::WriteLine( myInt.ToString( "P", nfi ) );
// Displays the same value with a blank as the separator.
nfi->PercentDecimalSeparator = " ";
Console::WriteLine( myInt.ToString( "P", nfi ) );
}
示例14: add_ellipse
void ARCBuilder::add_ellipse(Vector center, Vector sm_axis, Double axis_ratio,
Double start_angle, Double end_angle,
Vector extrusion)
{
if (start_angle.is_equal_with_epsilon(0.0, constants::EPSILON) &&
end_angle.is_equal_with_epsilon(2*constants::PI, constants::EPSILON)) {
Vector a = center - sm_axis;
Vector b = center +
Vector(-a.y()+center.y(),a.x()-center.x(), 0.0)*axis_ratio; // Only 2D
add_ellipse(center, a, b);
} else {
// TODO Elliptic Arc
}
}
示例15: Exception
/*---------------------------------------------------------*/
NOMAD::success_type NOMAD::Barrier::insert_feasible ( const NOMAD::Eval_Point & x )
{
Double fx;
Double fx_bf;
if ( _p.get_robust_mads() )
{
if ( x.get_smoothing_status() != NOMAD::SMOOTHING_OK )
return NOMAD::UNSUCCESSFUL;
if ( _best_feasible )
fx_bf = _best_feasible->get_fsmooth();
else
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
fx = x.get_fsmooth();
}
else
{
if ( _best_feasible )
fx_bf = _best_feasible->get_f();
else
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
fx= x.get_f();
}
if ( !fx.is_defined() || ! fx_bf.is_defined() )
throw NOMAD::Exception ( __FILE__ , __LINE__ ,
"insert_feasible(): one point has no f value" );
if ( fx.value() < fx_bf.value() )
{
_best_feasible = &x;
return NOMAD::FULL_SUCCESS;
}
return NOMAD::UNSUCCESSFUL;
}