• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyLong_AsDouble函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyLong_AsDouble函数的典型用法代码示例。如果您正苦于以下问题:C++ PyLong_AsDouble函数的具体用法?C++ PyLong_AsDouble怎么用?C++ PyLong_AsDouble使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyLong_AsDouble函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: nb_multiply

static PyObject*
nb_multiply (PyObject* o1, PyObject* o2) {
    float o1w = 0, o1h = 0, o1d = 0;
    float o2w = 0, o2h = 0, o2d = 0;
    PyObject *args, *result;
    PySoy_atoms_Size_Object *so1, *so2;

    // parse object 1
    if (PyLong_Check(o1)) {
        o1w = o1h = o1d = PyLong_AsDouble(o1);
    }
    else if (PyFloat_Check(o1)) {
        o1w = o1h = o1d = PyFloat_AsDouble(o1);
    }
    else if (PySoy_atoms_Size_Check(o1)) {
        so1 = (PySoy_atoms_Size_Object*)o1;
        o1w = soy_atoms_size_get_width(so1->g);
        o1h = soy_atoms_size_get_height(so1->g);
        o1d = soy_atoms_size_get_depth(so1->g);
    }
    else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // parse object 2
    if (PyLong_Check(o2)) {
        o2w = o2h = o2d = PyLong_AsDouble(o2);
    }
    else if (PyFloat_Check(o2)) {
        o2w = o2h = o2d = PyFloat_AsDouble(o2);
    }
    else if (PySoy_atoms_Size_Check(o2)) {
        so2 = (PySoy_atoms_Size_Object*)o2;
        o2w = soy_atoms_size_get_width(so2->g);
        o2h = soy_atoms_size_get_height(so2->g);
        o2d = soy_atoms_size_get_depth(so2->g);
    } else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // build args with calculated values
    args = Py_BuildValue("((fff))", o1w * o2w, o1h * o2h, o1d * o2d);

    // create result object
    result = tp_new(&PySoy_atoms_Size_Type, args, NULL);

    // decref args tuple and tmp
    Py_DECREF(args);

    // return calculated result
    return result;
}
开发者ID:couchjd,项目名称:playground,代码行数:54,代码来源:Size.c


示例2: PickVarInfo_SetMixValues

/*static*/ PyObject *
PickVarInfo_SetMixValues(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    doubleVector  &vec = obj->data->GetMixValues();
    PyObject     *tuple;
    if(!PyArg_ParseTuple(args, "O", &tuple))
        return NULL;

    if(PyTuple_Check(tuple))
    {
        vec.resize(PyTuple_Size(tuple));
        for(int i = 0; i < PyTuple_Size(tuple); ++i)
        {
            PyObject *item = PyTuple_GET_ITEM(tuple, i);
            if(PyFloat_Check(item))
                vec[i] = PyFloat_AS_DOUBLE(item);
            else if(PyInt_Check(item))
                vec[i] = double(PyInt_AS_LONG(item));
            else if(PyLong_Check(item))
                vec[i] = PyLong_AsDouble(item);
            else
                vec[i] = 0.;
        }
    }
    else if(PyFloat_Check(tuple))
    {
        vec.resize(1);
        vec[0] = PyFloat_AS_DOUBLE(tuple);
    }
    else if(PyInt_Check(tuple))
    {
        vec.resize(1);
        vec[0] = double(PyInt_AS_LONG(tuple));
    }
    else if(PyLong_Check(tuple))
    {
        vec.resize(1);
        vec[0] = PyLong_AsDouble(tuple);
    }
    else
        return NULL;

    // Mark the mixValues in the object as modified.
    obj->data->SelectMixValues();

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:50,代码来源:PyPickVarInfo.C


示例3: ConstructDataBinningAttributes_SetBinBoundaries

/*static*/ PyObject *
ConstructDataBinningAttributes_SetBinBoundaries(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    doubleVector  &vec = obj->data->GetBinBoundaries();
    PyObject     *tuple;
    if(!PyArg_ParseTuple(args, "O", &tuple))
        return NULL;

    if(PyTuple_Check(tuple))
    {
        vec.resize(PyTuple_Size(tuple));
        for(int i = 0; i < PyTuple_Size(tuple); ++i)
        {
            PyObject *item = PyTuple_GET_ITEM(tuple, i);
            if(PyFloat_Check(item))
                vec[i] = PyFloat_AS_DOUBLE(item);
            else if(PyInt_Check(item))
                vec[i] = double(PyInt_AS_LONG(item));
            else if(PyLong_Check(item))
                vec[i] = PyLong_AsDouble(item);
            else
                vec[i] = 0.;
        }
    }
    else if(PyFloat_Check(tuple))
    {
        vec.resize(1);
        vec[0] = PyFloat_AS_DOUBLE(tuple);
    }
    else if(PyInt_Check(tuple))
    {
        vec.resize(1);
        vec[0] = double(PyInt_AS_LONG(tuple));
    }
    else if(PyLong_Check(tuple))
    {
        vec.resize(1);
        vec[0] = PyLong_AsDouble(tuple);
    }
    else
        return NULL;

    // Mark the binBoundaries in the object as modified.
    obj->data->SelectBinBoundaries();

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:ahota,项目名称:visit_intel,代码行数:50,代码来源:PyConstructDataBinningAttributes.C


示例4: nb_multiply

static PyObject*
nb_multiply (PyObject* o1, PyObject* o2) {
    double o1x, o1y, o1z = 0;
    double o2x, o2y, o2z = 0;
    PyObject *args, *result;
	PySoy_atoms_Rotation_Object *so1, *so2;

    // parse object 1
    if (PyLong_Check(o1)) {
	  o1x = o1y = o1z = PyLong_AsDouble(o1);	  
	} else if (PyFloat_Check(o1)) {
	  o1x = o1y = o1z = PyFloat_AsDouble(o1);	  
	} else if (PySoy_atoms_Rotation_Check(o1)) {
	  so1 = (PySoy_atoms_Rotation_Object*)o1;
	  o1x = soy_atoms_rotation_get_alpha(so1->g);
	  o1y = soy_atoms_rotation_get_beta(so1->g);
	  o1z = soy_atoms_rotation_get_gamma(so1->g);
	} else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // parse object 2
    if (PyLong_Check(o2)) {
	  o2x = o2y = o2z = PyLong_AsDouble(o2);	  
	} else if (PyFloat_Check(o2)) {
	  o2x = o2y = o2z = PyFloat_AsDouble(o2);	  
	} else if (PySoy_atoms_Rotation_Check(o2)) {
	  so2 = (PySoy_atoms_Rotation_Object*)o2;
	  o2x = soy_atoms_rotation_get_alpha(so2->g);
	  o2y = soy_atoms_rotation_get_beta(so2->g);
	  o2z = soy_atoms_rotation_get_gamma(so2->g);
	} else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // build args with calculated values
    args = Py_BuildValue("((fff))", o1x * o2x, o1y * o2y, o1z * o2z);

    // create result object
    result = tp_new(&PySoy_atoms_Rotation_Type, args, NULL);

    // decref args tuple
    Py_DECREF(args);

    // return calculated result
    return result;
}
开发者ID:RONNCC,项目名称:pysoy,代码行数:49,代码来源:Rotation.c


示例5: nb_add

static PyObject*
nb_add (PyObject* o1, PyObject* o2) {
    float o1x = 0, o1y = 0, o1z = 0;
    float o2x = 0, o2y = 0, o2z = 0;
    PyObject *args, *result;
    PySoy_atoms_Position_Object *so1, *so2;

    // parse object 1
    if (PyLong_Check(o1)) {
        o1x = o1y = o1z = PyLong_AsDouble(o1);
    } else if (PyFloat_Check(o1)) {
        o1x = o1y = o1z = PyFloat_AsDouble(o1);
    } else if (PySoy_atoms_Position_Check(o1)) {
        so1 = (PySoy_atoms_Position_Object*)o1;
        o1x = soy_atoms_position_get_x(so1->g);
        o1y = soy_atoms_position_get_y(so1->g);
        o1z = soy_atoms_position_get_z(so1->g);
    } else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // parse object 2
    if (PyLong_Check(o2)) {
        o2x = o2y = o2z = PyLong_AsDouble(o2);
    } else if (PyFloat_Check(o2)) {
        o2x = o2y = o2z = PyFloat_AsDouble(o2);
    } else if (PySoy_atoms_Position_Check(o2)) {
        so2 = (PySoy_atoms_Position_Object*)o2;
        o2x = soy_atoms_position_get_x(so2->g);
        o2y = soy_atoms_position_get_y(so2->g);
        o2z = soy_atoms_position_get_z(so2->g);
    } else {
        PyErr_SetString(PyExc_TypeError, "unsupported operand type(s)");
        return NULL;
    }

    // build args with calculated values
    args = Py_BuildValue("((fff))", o1x + o2x, o1y + o2y, o1z + o2z);

    // create result object
    result = tp_new(&PySoy_atoms_Position_Type, args, NULL);

    // decref args tuple and tmp
    Py_DECREF(args);

    // return calculated result
    return result;
}
开发者ID:RONNCC,项目名称:pysoy,代码行数:49,代码来源:Position.c


示例6: complex_coerce

static int
complex_coerce(PyObject **pv, PyObject **pw)
{
	Py_complex cval;
	cval.imag = 0.;
	if (PyInt_Check(*pw)) {
		cval.real = (double)PyInt_AsLong(*pw);
		*pw = PyComplex_FromCComplex(cval);
		Py_INCREF(*pv);
		return 0;
	}
	else if (PyLong_Check(*pw)) {
		cval.real = PyLong_AsDouble(*pw);
		if (cval.real == -1.0 && PyErr_Occurred())
			return -1;
		*pw = PyComplex_FromCComplex(cval);
		Py_INCREF(*pv);
		return 0;
	}
	else if (PyFloat_Check(*pw)) {
		cval.real = PyFloat_AsDouble(*pw);
		*pw = PyComplex_FromCComplex(cval);
		Py_INCREF(*pv);
		return 0;
	}
	else if (PyComplex_Check(*pw)) {
		Py_INCREF(*pv);
		Py_INCREF(*pw);
		return 0;
	}
	return 1; /* Can't do it */
}
开发者ID:santagada,项目名称:wpython,代码行数:32,代码来源:complexobject.c


示例7: to_complex

static int
to_complex(PyObject **pobj, Py_complex *pc)
{
    PyObject *obj = *pobj;

    pc->real = pc->imag = 0.0;
    if (PyInt_Check(obj)) {
        pc->real = PyInt_AS_LONG(obj);
        return 0;
    }
    if (PyLong_Check(obj)) {
        pc->real = PyLong_AsDouble(obj);
        if (pc->real == -1.0 && PyErr_Occurred()) {
            *pobj = NULL;
            return -1;
        }
        return 0;
    }
    if (PyFloat_Check(obj)) {
        pc->real = PyFloat_AsDouble(obj);
        return 0;
    }
    Py_INCREF(Py_NotImplemented);
    *pobj = Py_NotImplemented;
    return -1;
}
开发者ID:santagada,项目名称:wpython,代码行数:26,代码来源:complexobject.c


示例8: EnumValue_coerce

int EnumValue_coerce(PyObject **pv, PyObject **pw)
{
    if (PyInt_Check(*pw))
    {
        long x = PyInt_AsLong(*pw);
        *pw = NewEnumValue(NULL, x);
        Py_INCREF(*pv);
        return 0;
    }
    else if (PyLong_Check(*pw))
    {
        double x = PyLong_AsDouble(*pw);
        if (x == -1.0 && PyErr_Occurred())
            return -1;
        *pw = NewEnumValue(NULL, (long)x);
        Py_INCREF(*pv);
        return 0;
    }
    else if (PyFloat_Check(*pw))
    {
        double x = PyFloat_AsDouble(*pw);
        *pw = NewEnumValue(NULL, (long)x);
        Py_INCREF(*pv);
        return 0;
    }
    else if (IsEnumValue(*pw))
    {
        Py_INCREF(*pv);
        Py_INCREF(*pw);
        return 0;
    }
    return 1; // Can't do it
}
开发者ID:branan,项目名称:Plasma-nobink,代码行数:33,代码来源:pyEnum.cpp


示例9: SWIG_AsVal_double

SWIGINTERN int
  SWIG_AsVal_double(PyObject *obj, double *val)
{
  if (PyFloat_Check(obj)) {
    if (val) *val = PyFloat_AS_DOUBLE(obj);
    return 1;
  }  
  if (PyInt_Check(obj)) {
    if (val) *val = PyInt_AS_LONG(obj);
    return 1;
  }
  if (PyLong_Check(obj)) {
    double v = PyLong_AsDouble(obj);
    if (!PyErr_Occurred()) {
      if (val) *val = v;
      return 1;
    } else {
      if (!val) PyErr_Clear();
      return 0;
    }
  }
  if (val) {
    SWIG_type_error("double", obj);
  }
  return 0;
}
开发者ID:gitter-badger,项目名称:quinoa,代码行数:26,代码来源:wrap_LOCA_TimeDependent.C


示例10: errMsg

template<> double fromPy<double>(PyObject* obj) {
#if PY_MAJOR_VERSION <= 2
    if (PyInt_Check(obj)) return PyInt_AsLong(obj);
#endif
    if (PyFloat_Check(obj)) return PyFloat_AsDouble(obj);
    if (PyLong_Check(obj)) return PyLong_AsDouble(obj);
    errMsg("argument is not a double");    
}
开发者ID:SheldonZHANG,项目名称:Smoke,代码行数:8,代码来源:pconvert.cpp


示例11: convert_2d_pylist

int convert_2d_pylist( PyObject *list, double ***array, int *rows, int *cols ) {
    int i, j;
    PyObject *item;
    PyObject *num;
    // Is the object a list?
    if (!PyList_Check(list))
        return -1;
    *rows = PySequence_Length(list);
    
    // Does the list contain elements?
    if (*rows < 0) {
        return -1;
    }

    item = PySequence_GetItem(list,0);
    if(!PySequence_Check(item)) {
        return -1;
    }
    *cols = PySequence_Length(item);
    if(*cols < 0) {
        return -1;
    }
    Py_DECREF(item);

    *array = (double **)malloc(*rows * sizeof(double*) );
    for( i = 0; i < *rows; i++ ) {
        (*array)[i] = (double*)malloc(*cols*sizeof(double));
    }
        
    
    for( i = 0; i < *rows; i++ ) {
        item = PySequence_GetItem(list,i);
        if(!PySequence_Check(item)) {
            return -1;
        }
        if( PySequence_Length(item) != *cols) {
            return -1;
        }
        for( j = 0; j < *cols; j++ ) {
            num = PySequence_GetItem( item, j );
            if (PyInt_Check(num)) {
                (*array)[i][j] = (double)PyInt_AsLong( num );
            }
            else if (PyLong_Check(num)) {
                (*array)[i][j] = PyLong_AsDouble( num );
            }
            else if (PyFloat_Check(num)) {
                (*array)[i][j] = PyFloat_AsDouble( num );
            }
            else {
                return -1;
            }
        }
        Py_DECREF(item);        
    }
    return 0;
}
开发者ID:josephcourtney,项目名称:compass,代码行数:57,代码来源:util.c


示例12: _extract

 void PW_EXPORT _extract(PyObject *obj, float &val)
 {
     if (PyInt_Check(obj))
         val = (float)PyInt_AS_LONG(obj);
     else if (PyLong_Check(obj))
         val = (float)PyLong_AsDouble(obj);
     else
         val = (float)PyFloat_AsDouble(obj);
 }
开发者ID:BackupTheBerlios,项目名称:pythonwrapper-svn,代码行数:9,代码来源:PWExtract.cpp


示例13: complex_from_python

  std::complex<T> complex_from_python(PyObject* p, boost::python::type<T>)
  {
      if (PyInt_Check(p)) return std::complex<T>(PyInt_AS_LONG(p));
      if (PyLong_Check(p)) return std::complex<T>(PyLong_AsDouble(p));
      if (PyFloat_Check(p)) return std::complex<T>(PyFloat_AS_DOUBLE(p));

      expect_complex(p);

      return std::complex<T>(
        static_cast<T>(PyComplex_RealAsDouble(p)),
        static_cast<T>(PyComplex_ImagAsDouble(p)));
  }
开发者ID:metashell,项目名称:headers,代码行数:12,代码来源:conversions.hpp


示例14: validate_float_promote

static PyObject*
validate_float_promote( Member* member, PyObject* owner, PyObject* oldvalue, PyObject* newvalue )
{
    if( PyFloat_Check( newvalue ) )
        return newref( newvalue );
    if( PyInt_Check( newvalue ) )
        return PyFloat_FromDouble( static_cast<double>( PyInt_AS_LONG( newvalue ) ) );
    if( PyLong_Check( newvalue ) )
    {
        double val = PyLong_AsDouble( newvalue );
        if( val < 0.0 && PyErr_Occurred() )
            return 0;
        return PyFloat_FromDouble( val );
    }
    return validate_type_fail( member, owner, newvalue, "float" );
}
开发者ID:enthought,项目名称:atom,代码行数:16,代码来源:memberfunctions.cpp


示例15: Text3DObject_SetRotations

static PyObject *
Text3DObject_SetRotations(PyObject *self, PyObject *args)
{
    Text3DObjectObject *obj = (Text3DObjectObject *)self;

    double dvals[3];
    dvals[0] = obj->data->GetRotations()[0];
    dvals[1] = obj->data->GetRotations()[1];
    dvals[2] = obj->data->GetRotations()[2];
    if(!PyArg_ParseTuple(args, "ddd", &dvals[0], &dvals[1], &dvals[2]))
    {
        PyObject     *tuple;
        if(!PyArg_ParseTuple(args, "O", &tuple))
            return NULL;

        if(PyTuple_Check(tuple))
        {
            if(PyTuple_Size(tuple) != 3)
                return NULL;

            PyErr_Clear();
            for(int i = 0; i < PyTuple_Size(tuple); ++i)
            {
                PyObject *item = PyTuple_GET_ITEM(tuple, i);
                if(PyFloat_Check(item))
                    dvals[i] = PyFloat_AS_DOUBLE(item);
                else if(PyInt_Check(item))
                    dvals[i] = double(PyInt_AS_LONG(item));
                else if(PyLong_Check(item))
                    dvals[i] = PyLong_AsDouble(item);
                else
                    dvals[i] = 0.;
            }
        }
        else
            return NULL;
    }

    // Mark the rotations in the object as modified.
    obj->data->SetRotations(dvals);

/*CUSTOM*/
    UpdateAnnotationHelper(obj->data);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:47,代码来源:PyText3DObject.C


示例16: ColorAttribute_SetColor

/*static*/ PyObject *
ColorAttribute_SetColor(PyObject *self, PyObject *args)
{
    ColorAttributeObject *obj = (ColorAttributeObject *)self;

    unsigned char *cvals = obj->data->GetColor();
    if(!PyArg_ParseTuple(args, "cccc", &cvals[0], &cvals[1], &cvals[2], &cvals[3]))
    {
        PyObject     *tuple;
        if(!PyArg_ParseTuple(args, "O", &tuple))
            return NULL;

        if(PyTuple_Check(tuple))
        {
            if(PyTuple_Size(tuple) != 4)
                return NULL;

            PyErr_Clear();
            for(int i = 0; i < PyTuple_Size(tuple); ++i)
            {
                int c;
                PyObject *item = PyTuple_GET_ITEM(tuple, i);
                if(PyFloat_Check(item))
                    c = int(PyFloat_AS_DOUBLE(item));
                else if(PyInt_Check(item))
                    c = int(PyInt_AS_LONG(item));
                else if(PyLong_Check(item))
                    c = int(PyLong_AsDouble(item));
                else
                    c = 0;

                if(c < 0) c = 0;
                if(c > 255) c = 255;
                cvals[i] = (unsigned char)(c);
            }
        }
        else
            return NULL;
    }

    // Mark the color in the object as modified.
    obj->data->SelectColor();

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:ahota,项目名称:visit_intel,代码行数:46,代码来源:PyColorAttribute.C


示例17: TimeSliderObject_SetPosition

static PyObject *
TimeSliderObject_SetPosition(PyObject *self, PyObject *args)
{
    TimeSliderObjectObject *obj = (TimeSliderObjectObject *)self;

    double *dvals = obj->data->GetPosition();
    if(!PyArg_ParseTuple(args, "dd", &dvals[0], &dvals[1]))
    {
        PyObject     *tuple;
        if(!PyArg_ParseTuple(args, "O", &tuple))
            return NULL;

        if(PyTuple_Check(tuple))
        {
            if(PyTuple_Size(tuple) != 2)
                return NULL;

            PyErr_Clear();
            for(int i = 0; i < PyTuple_Size(tuple); ++i)
            {
                PyObject *item = PyTuple_GET_ITEM(tuple, i);
                if(PyFloat_Check(item))
                    dvals[i] = (PyFloat_AS_DOUBLE(item));
                else if(PyInt_Check(item))
                    dvals[i] = double(PyInt_AS_LONG(item));
                else if(PyLong_Check(item))
                    dvals[i] = (PyLong_AsDouble(item));
                else
                    dvals[i] = 0.;
            }
        }
        else
            return NULL;
    }

    // Mark the position in the object as modified.
    obj->data->SelectPosition();
/* CUSTOM */
    UpdateAnnotationHelper(obj->data);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:43,代码来源:PyTimeSliderObject.C


示例18: PYTHON_METHOD_DEFINITION

PYTHON_METHOD_DEFINITION(ptNotify, addVarNumber, args)
{
    char* name;
    PyObject* number = NULL;
    if (!PyArg_ParseTuple(args, "s|O", &name, &number))
    {
        PyErr_SetString(PyExc_TypeError, "addVarNumber expects a string and optional number");
        PYTHON_RETURN_ERROR;
    }

    if (number == NULL || number == Py_None)
        self->fThis->AddVarNull(name);
    else if (PyInt_Check(number))
        self->fThis->AddVarNumber(name, static_cast<int32_t>(PyInt_AsLong(number)));
    else if (PyLong_Check(number))
    {
        // try as int first
        long i = PyLong_AsLong(number);
        if (!PyErr_Occurred())
        {
            self->fThis->AddVarNumber(name, static_cast<int32_t>(i));
        }
        else
        {
            // OverflowError, try float
            PyErr_Clear();
            self->fThis->AddVarNumber(name, (float)PyLong_AsDouble(number));
        }
    }
    else if (PyNumber_Check(number))
    {
        PyObject* f = PyNumber_Float(number);
        self->fThis->AddVarNumber(name, (float)PyFloat_AsDouble(f));
        Py_DECREF(f);
    } 
    else
    {
        PyErr_SetString(PyExc_TypeError, "addVarNumber expects a string and optional number");
        PYTHON_RETURN_ERROR;
    }
    PYTHON_RETURN_NONE;
}
开发者ID:Asteral,项目名称:Plasma,代码行数:42,代码来源:pyNotifyGlue.cpp


示例19: convert_to_double

/* adapted from Python source, floatobject.c:convert_to_double */
int
convert_to_double(PyObject *obj, double *dbl)
{
    if (PyFloat_Check(obj)) {
        *dbl = PyFloat_AS_DOUBLE(obj);
#ifndef IS_PY3K
    } else if (PyInt_Check(obj)) {
        *dbl = (double)PyInt_AS_LONG(obj);
#endif
    } else if (PyLong_Check(obj)) {
        *dbl = PyLong_AsDouble(obj);
        if (*dbl == -1.0 && PyErr_Occurred()) {
            return 0;
        }
    } else {
        PyErr_SetString(PyExc_ValueError, "Expected a number");
        return 0;
    }
    return 1;
}
开发者ID:shengtu,项目名称:pypybox2d,代码行数:21,代码来源:commonmodule.c


示例20: ReplicateAttributes_SetNewPeriodicOrigin

/*static*/ PyObject *
ReplicateAttributes_SetNewPeriodicOrigin(PyObject *self, PyObject *args)
{
    ReplicateAttributesObject *obj = (ReplicateAttributesObject *)self;

    double *dvals = obj->data->GetNewPeriodicOrigin();
    if(!PyArg_ParseTuple(args, "ddd", &dvals[0], &dvals[1], &dvals[2]))
    {
        PyObject     *tuple;
        if(!PyArg_ParseTuple(args, "O", &tuple))
            return NULL;

        if(PyTuple_Check(tuple))
        {
            if(PyTuple_Size(tuple) != 3)
                return NULL;

            PyErr_Clear();
            for(int i = 0; i < PyTuple_Size(tuple); ++i)
            {
                PyObject *item = PyTuple_GET_ITEM(tuple, i);
                if(PyFloat_Check(item))
                    dvals[i] = PyFloat_AS_DOUBLE(item);
                else if(PyInt_Check(item))
                    dvals[i] = double(PyInt_AS_LONG(item));
                else if(PyLong_Check(item))
                    dvals[i] = PyLong_AsDouble(item);
                else
                    dvals[i] = 0.;
            }
        }
        else
            return NULL;
    }

    // Mark the newPeriodicOrigin in the object as modified.
    obj->data->SelectNewPeriodicOrigin();

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:HarinarayanKrishnan,项目名称:VisIt28RC_Trunk,代码行数:41,代码来源:PyReplicateAttributes.C



注:本文中的PyLong_AsDouble函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyLong_AsLong函数代码示例发布时间:2022-05-30
下一篇:
C++ PyList_Size函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap