本文整理汇总了C++中PyFloat_FromDouble函数的典型用法代码示例。如果您正苦于以下问题:C++ PyFloat_FromDouble函数的具体用法?C++ PyFloat_FromDouble怎么用?C++ PyFloat_FromDouble使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyFloat_FromDouble函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: describe_plugin
static PyObject *
describe_plugin(PyObject * mod, PyObject * args)
{
char * libname = NULL;
int plug_id;
int port_num;
void * dlfile;
LADSPA_Descriptor * (* descrip_func)(unsigned long);
LADSPA_Descriptor * descrip;
PyObject * dict = NULL;
PyObject * ports = NULL;
PyObject * portinfo = NULL;
PyArg_ParseTuple(args, "si", &libname, &plug_id);
if (libname == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
dlfile = dlopen(libname, RTLD_NOW);
if (dlfile == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
descrip_func = dlsym(dlfile, "ladspa_descriptor");
descrip = descrip_func(plug_id);
if (descrip == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
dict = PyDict_New();
PyDict_SetItemString(dict, "lib_name", PyString_FromString(libname));
PyDict_SetItemString(dict, "lib_type", PyString_FromString("ladspa"));
PyDict_SetItemString(dict, "lib_index", PyInt_FromLong(plug_id));
PyDict_SetItemString(dict, "unique_id", PyInt_FromLong(descrip->UniqueID));
PyDict_SetItemString(dict, "properties", PyInt_FromLong(descrip->Properties));
PyDict_SetItemString(dict, "label", PyString_FromString(descrip->Label));
PyDict_SetItemString(dict, "name", PyString_FromString(descrip->Name));
PyDict_SetItemString(dict, "maker", PyString_FromString(descrip->Maker));
PyDict_SetItemString(dict, "copyright", PyString_FromString(descrip->Copyright));
ports = PyList_New(descrip->PortCount);
for(port_num=0; port_num < descrip->PortCount; port_num++) {
portinfo = PyDict_New();
PyDict_SetItemString(portinfo, "descriptor",
PyInt_FromLong(descrip->PortDescriptors[port_num]));
PyDict_SetItemString(portinfo, "name",
PyString_FromString(descrip->PortNames[port_num]));
PyDict_SetItemString(portinfo, "hint_type",
PyInt_FromLong(descrip->PortRangeHints[port_num].HintDescriptor));
PyDict_SetItemString(portinfo, "hint_lower",
PyFloat_FromDouble(descrip->PortRangeHints[port_num].LowerBound));
PyDict_SetItemString(portinfo, "hint_upper",
PyFloat_FromDouble(descrip->PortRangeHints[port_num].UpperBound));
PyList_SetItem(ports, port_num, portinfo);
}
PyDict_SetItemString(dict, "ports", ports);
dlclose(dlfile);
Py_INCREF(dict);
return dict;
}
示例2: Object_newDouble
JSOBJ Object_newDouble(double value)
{
return PyFloat_FromDouble(value);
}
示例3: Py_INCREF
//-------------------------------------------------------------------------------------
PyObject* ScriptVector3::seq_slice(PyObject* self, Py_ssize_t startIndex, Py_ssize_t endIndex)
{
if(startIndex < 0)
startIndex = 0;
if(endIndex > VECTOR_SIZE)
endIndex = VECTOR_SIZE;
if(endIndex < startIndex)
endIndex = startIndex;
ScriptVector3* sv = static_cast<ScriptVector3*>(self);
Vector3& my_v = sv->getVector();
PyObject* pyResult = NULL;
int length = (int)(endIndex - startIndex);
if (length == VECTOR_SIZE)
{
pyResult = sv;
Py_INCREF(pyResult);
}
else
switch(length)
{
case 0:
pyResult = PyTuple_New(0);
break;
case 1:
pyResult = PyTuple_New(1);
PyTuple_SET_ITEM(pyResult, 0, PyFloat_FromDouble(sv->getVector()[static_cast<int>(startIndex)]));
break;
case 2:
{
Vector2 v;
for (int i = (int)startIndex; i < (int)endIndex; ++i){
v[i - static_cast<int>(startIndex)] = my_v[i];
}
pyResult = new ScriptVector2(v);
break;
}
case 3:
{
Vector3 v;
for (int i = (int)startIndex; i < (int)endIndex; ++i){
v[i - static_cast<int>(startIndex)] = my_v[i];
}
pyResult = new ScriptVector3(v);
break;
}
default:
PyErr_Format(PyExc_IndexError, "Bad slice indexes [%d, %d] for Vector%d", startIndex, endIndex, VECTOR_SIZE);
PyErr_PrintEx(0);
break;
}
return pyResult;
}
示例4: CameraInfo_GetFocalLength
static PyObject* CameraInfo_GetFocalLength(CameraInfoObj* self, void* closure)
{
return PyFloat_FromDouble(self->instance.flen);
}
示例5: srd_inst_option_set
/**
* Set one or more options in a decoder instance.
*
* Handled options are removed from the hash.
*
* @param di Decoder instance.
* @param options A GHashTable of options to set.
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*
* @since 0.1.0
*/
SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
GHashTable *options)
{
struct srd_decoder_option *sdo;
PyObject *py_di_options, *py_optval;
GVariant *value;
GSList *l;
double val_double;
gint64 val_int;
int ret;
const char *val_str;
if (!di) {
srd_err("Invalid decoder instance.");
return SRD_ERR_ARG;
}
if (!options) {
srd_err("Invalid options GHashTable.");
return SRD_ERR_ARG;
}
if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
/* Decoder has no options. */
if (g_hash_table_size(options) == 0) {
/* No options provided. */
return SRD_OK;
} else {
srd_err("Protocol decoder has no options.");
return SRD_ERR_ARG;
}
return SRD_OK;
}
ret = SRD_ERR_PYTHON;
py_optval = NULL;
/*
* The 'options' tuple is a class variable, but we need to
* change it. Changing it directly will affect the entire class,
* so we need to create a new object for it, and populate that
* instead.
*/
if (!(py_di_options = PyObject_GetAttrString(di->py_inst, "options")))
goto err_out;
Py_DECREF(py_di_options);
py_di_options = PyDict_New();
PyObject_SetAttrString(di->py_inst, "options", py_di_options);
for (l = di->decoder->options; l; l = l->next) {
sdo = l->data;
if ((value = g_hash_table_lookup(options, sdo->id))) {
/* A value was supplied for this option. */
if (!g_variant_type_equal(g_variant_get_type(value),
g_variant_get_type(sdo->def))) {
srd_err("Option '%s' should have the same type "
"as the default value.", sdo->id);
goto err_out;
}
} else {
/* Use default for this option. */
value = sdo->def;
}
if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
val_str = g_variant_get_string(value, NULL);
if (!(py_optval = PyUnicode_FromString(val_str))) {
/* Some UTF-8 encoding error. */
PyErr_Clear();
srd_err("Option '%s' requires a UTF-8 string value.", sdo->id);
goto err_out;
}
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT64)) {
val_int = g_variant_get_int64(value);
if (!(py_optval = PyLong_FromLong(val_int))) {
/* ValueError Exception */
PyErr_Clear();
srd_err("Option '%s' has invalid integer value.", sdo->id);
goto err_out;
}
} else if (g_variant_is_of_type(value, G_VARIANT_TYPE_DOUBLE)) {
val_double = g_variant_get_double(value);
if (!(py_optval = PyFloat_FromDouble(val_double))) {
/* ValueError Exception */
PyErr_Clear();
srd_err("Option '%s' has invalid float value.",
sdo->id);
goto err_out;
}
//.........这里部分代码省略.........
示例6: pyAffineParts_getF
static PyObject* pyAffineParts_getF(pyAffineParts* self, void*) {
return PyFloat_FromDouble(self->fThis->fF);
}
示例7: switch
PyObject *PyMAPIObject_FromSPropValue(SPropValue *pv)
{
PyObject *val;
ULONG i;
switch (PROP_TYPE(pv->ulPropTag)) {
case PT_I2: // case PT_SHORT:
val = PyInt_FromLong(pv->Value.i);
break;
case PT_I4: // case PT_LONG:
val = PyInt_FromLong(pv->Value.l);
break;
case PT_R4: // case PT_FLOAT:
val = PyFloat_FromDouble(pv->Value.flt);
break;
case PT_R8: // case PT_DOUBLE:
val = PyFloat_FromDouble(pv->Value.dbl);
break;
case PT_BOOLEAN:
val = pv->Value.b ? Py_True : Py_False;
Py_INCREF(val);
break;
/*
case PT_CURRENCY:
pv->Value.cur??
break;
*/
case PT_APPTIME :
val = PyWinObject_FromDATE(pv->Value.at);
break;
case PT_SYSTIME:
val = PyWinObject_FromFILETIME(pv->Value.ft);
break;
case PT_STRING8:
val = PyString_FromString(pv->Value.lpszA);
break;
case PT_UNICODE:
val = PyWinObject_FromWCHAR(pv->Value.lpszW);
break;
case PT_BINARY:
val = PyString_FromStringAndSize((char *)pv->Value.bin.lpb, pv->Value.bin.cb);
break;
case PT_CLSID:
val = PyWinObject_FromIID(*pv->Value.lpguid);
break;
case PT_I8:
// case PT_LONGLONG:
val = PyWinObject_FromLARGE_INTEGER(pv->Value.li);
break;
case PT_ERROR:
val = PyInt_FromLong(pv->Value.err);
break;
case PT_NULL:
val = Py_None;
Py_INCREF(Py_None);
break;
case PT_MV_I2:
val = PyTuple_New(pv->Value.MVi.cValues);
if (val) {
for (i=0;i<pv->Value.MVi.cValues;i++)
PyTuple_SET_ITEM(val, i, PyInt_FromLong(pv->Value.MVi.lpi[i]));
}
break;
case PT_MV_LONG:
val = PyTuple_New(pv->Value.MVi.cValues);
if (val) {
for (i=0;i<pv->Value.MVl.cValues;i++)
PyTuple_SET_ITEM(val, i, PyInt_FromLong(pv->Value.MVl.lpl[i]));
}
break;
case PT_MV_R4:
val = PyTuple_New(pv->Value.MVflt.cValues);
if (val) {
for (i=0;i<pv->Value.MVflt.cValues;i++)
PyTuple_SET_ITEM(val, i, PyFloat_FromDouble(pv->Value.MVflt.lpflt[i]));
}
break;
case PT_MV_DOUBLE :
val = PyTuple_New(pv->Value.MVdbl.cValues);
if (val) {
for (i=0;i<pv->Value.MVdbl.cValues;i++)
PyTuple_SET_ITEM(val, i, PyFloat_FromDouble(pv->Value.MVdbl.lpdbl[i]));
}
break;
/*
case PT_MV_CURRENCY:
MVcur
SCurrencyArray
*/
case PT_MV_APPTIME :
val = PyTuple_New(pv->Value.MVat.cValues);
if (val) {
for (i=0;i<pv->Value.MVat.cValues;i++)
PyTuple_SET_ITEM(val, i, PyWinObject_FromDATE(pv->Value.MVat.lpat[i]));
}
break;
case PT_MV_SYSTIME:
//.........这里部分代码省略.........
示例8: switch
PyObject* PythonQtConv::ConvertQtValueToPythonInternal(int type, const void* data) {
switch (type) {
case QMetaType::Void:
Py_INCREF(Py_None);
return Py_None;
case QMetaType::Char:
return PyInt_FromLong(*((char*)data));
case QMetaType::UChar:
return PyInt_FromLong(*((unsigned char*)data));
case QMetaType::Short:
return PyInt_FromLong(*((short*)data));
case QMetaType::UShort:
return PyInt_FromLong(*((unsigned short*)data));
case QMetaType::Long:
return PyInt_FromLong(*((long*)data));
case QMetaType::ULong:
// does not fit into simple int of python
return PyLong_FromUnsignedLong(*((unsigned long*)data));
case QMetaType::Bool:
return PythonQtConv::GetPyBool(*((bool*)data));
case QMetaType::Int:
return PyInt_FromLong(*((int*)data));
case QMetaType::UInt:
// does not fit into simple int of python
return PyLong_FromUnsignedLong(*((unsigned int*)data));
case QMetaType::QChar:
return PyInt_FromLong(*((short*)data));
case QMetaType::Float:
return PyFloat_FromDouble(*((float*)data));
case QMetaType::Double:
return PyFloat_FromDouble(*((double*)data));
case QMetaType::LongLong:
return PyLong_FromLongLong(*((qint64*)data));
case QMetaType::ULongLong:
return PyLong_FromUnsignedLongLong(*((quint64*)data));
// implicit conversion from QByteArray to str has been removed:
//case QMetaType::QByteArray: {
// QByteArray* v = (QByteArray*) data;
// return PyString_FromStringAndSize(*v, v->size());
// }
case QMetaType::QVariantMap:
return PythonQtConv::QVariantMapToPyObject(*((QVariantMap*)data));
case QMetaType::QVariantList:
return PythonQtConv::QVariantListToPyObject(*((QVariantList*)data));
case QMetaType::QString:
return PythonQtConv::QStringToPyObject(*((QString*)data));
case QMetaType::QStringList:
return PythonQtConv::QStringListToPyObject(*((QStringList*)data));
case PythonQtMethodInfo::Variant:
return PythonQtConv::QVariantToPyObject(*((QVariant*)data));
case QMetaType::QObjectStar:
case QMetaType::QWidgetStar:
return PythonQt::priv()->wrapQObject(*((QObject**)data));
default:
if (PythonQt::priv()->isPythonQtObjectPtrMetaId(type)) {
// special case, it is a PythonQtObjectPtr which contains a PyObject, take it directly:
PyObject* o = ((PythonQtObjectPtr*)data)->object();
Py_INCREF(o);
return o;
} else {
if (type > 0) {
// if the type is known, we can construct it via QMetaType::construct
void* newCPPObject = QMetaType::construct(type, data);
// XXX this could be optimized by using metatypeid directly
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv()->wrapPtr(newCPPObject, QMetaType::typeName(type));
wrap->_ownedByPythonQt = true;
wrap->_useQMetaTypeDestroy = true;
return (PyObject*)wrap;
}
std::cerr << "Unknown type that can not be converted to Python: " << type << ", in " << __FILE__ << ":" << __LINE__ << std::endl;
}
}
Py_INCREF(Py_None);
return Py_None;
}
示例9: PyFloat_FromDouble
static PyObject *PyAsap_ParamProvMaxCutoff(PyAsap_EMTParamProvObject *self,
PyObject *noargs)
{
double cutoff = self->cobj->GetMaxListCutoffDistance();
return PyFloat_FromDouble(cutoff);
}
示例10: to_python
inline PyObject* to_python(double d)
{
return PyFloat_FromDouble(d);
}
示例11: math_pow
static PyObject *
math_pow(PyObject *self, PyObject *args)
{
PyObject *ox, *oy;
double r, x, y;
int odd_y;
if (! PyArg_UnpackTuple(args, "pow", 2, 2, &ox, &oy))
return NULL;
x = PyFloat_AsDouble(ox);
y = PyFloat_AsDouble(oy);
if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
return NULL;
/* deal directly with IEEE specials, to cope with problems on various
platforms whose semantics don't exactly match C99 */
r = 0.; /* silence compiler warning */
if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) {
errno = 0;
if (Py_IS_NAN(x))
r = y == 0. ? 1. : x; /* NaN**0 = 1 */
else if (Py_IS_NAN(y))
r = x == 1. ? 1. : y; /* 1**NaN = 1 */
else if (Py_IS_INFINITY(x)) {
odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
if (y > 0.)
r = odd_y ? x : fabs(x);
else if (y == 0.)
r = 1.;
else /* y < 0. */
r = odd_y ? copysign(0., x) : 0.;
}
else if (Py_IS_INFINITY(y)) {
if (fabs(x) == 1.0)
r = 1.;
else if (y > 0. && fabs(x) > 1.0)
r = y;
else if (y < 0. && fabs(x) < 1.0) {
r = -y; /* result is +inf */
if (x == 0.) /* 0**-inf: divide-by-zero */
errno = EDOM;
}
else
r = 0.;
}
}
else {
/* let libm handle finite**finite */
errno = 0;
PyFPE_START_PROTECT("in math_pow", return 0);
r = pow(x, y);
PyFPE_END_PROTECT(r);
/* a NaN result should arise only from (-ve)**(finite
non-integer); in this case we want to raise ValueError. */
if (!Py_IS_FINITE(r)) {
if (Py_IS_NAN(r)) {
errno = EDOM;
}
/*
an infinite result here arises either from:
(A) (+/-0.)**negative (-> divide-by-zero)
(B) overflow of x**y with x and y finite
*/
else if (Py_IS_INFINITY(r)) {
if (x == 0.)
errno = EDOM;
else
errno = ERANGE;
}
}
}
if (errno && is_error(r))
return NULL;
else
return PyFloat_FromDouble(r);
}
示例12: math_ldexp
static PyObject *
math_ldexp(PyObject *self, PyObject *args)
{
double x, r;
PyObject *oexp;
long exp;
if (! PyArg_ParseTuple(args, "dO:ldexp", &x, &oexp))
return NULL;
if (PyLong_Check(oexp)) {
/* on overflow, replace exponent with either LONG_MAX
or LONG_MIN, depending on the sign. */
exp = PyLong_AsLong(oexp);
if (exp == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
if (Py_SIZE(oexp) < 0) {
exp = LONG_MIN;
}
else {
exp = LONG_MAX;
}
PyErr_Clear();
}
else {
/* propagate any unexpected exception */
return NULL;
}
}
}
else {
PyErr_SetString(PyExc_TypeError,
"Expected an int or long as second argument "
"to ldexp.");
return NULL;
}
if (x == 0. || !Py_IS_FINITE(x)) {
/* NaNs, zeros and infinities are returned unchanged */
r = x;
errno = 0;
} else if (exp > INT_MAX) {
/* overflow */
r = copysign(Py_HUGE_VAL, x);
errno = ERANGE;
} else if (exp < INT_MIN) {
/* underflow to +-0 */
r = copysign(0., x);
errno = 0;
} else {
errno = 0;
PyFPE_START_PROTECT("in math_ldexp", return 0);
r = ldexp(x, (int)exp);
PyFPE_END_PROTECT(r);
if (Py_IS_INFINITY(r))
errno = ERANGE;
}
if (errno && is_error(r))
return NULL;
return PyFloat_FromDouble(r);
}
示例13: math_fsum
static PyObject*
math_fsum(PyObject *self, PyObject *seq)
{
PyObject *item, *iter, *sum = NULL;
Py_ssize_t i, j, n = 0, m = NUM_PARTIALS;
double x, y, t, ps[NUM_PARTIALS], *p = ps;
double xsave, special_sum = 0.0, inf_sum = 0.0;
volatile double hi, yr, lo;
iter = PyObject_GetIter(seq);
if (iter == NULL)
return NULL;
PyFPE_START_PROTECT("fsum", Py_DECREF(iter); return NULL)
for(;;) { /* for x in iterable */
assert(0 <= n && n <= m);
assert((m == NUM_PARTIALS && p == ps) ||
(m > NUM_PARTIALS && p != NULL));
item = PyIter_Next(iter);
if (item == NULL) {
if (PyErr_Occurred())
goto _fsum_error;
break;
}
x = PyFloat_AsDouble(item);
Py_DECREF(item);
if (PyErr_Occurred())
goto _fsum_error;
xsave = x;
for (i = j = 0; j < n; j++) { /* for y in partials */
y = p[j];
if (fabs(x) < fabs(y)) {
t = x; x = y; y = t;
}
hi = x + y;
yr = hi - x;
lo = y - yr;
if (lo != 0.0)
p[i++] = lo;
x = hi;
}
n = i; /* ps[i:] = [x] */
if (x != 0.0) {
if (! Py_IS_FINITE(x)) {
/* a nonfinite x could arise either as
a result of intermediate overflow, or
as a result of a nan or inf in the
summands */
if (Py_IS_FINITE(xsave)) {
PyErr_SetString(PyExc_OverflowError,
"intermediate overflow in fsum");
goto _fsum_error;
}
if (Py_IS_INFINITY(xsave))
inf_sum += xsave;
special_sum += xsave;
/* reset partials */
n = 0;
}
else if (n >= m && _fsum_realloc(&p, n, ps, &m))
goto _fsum_error;
else
p[n++] = x;
}
}
if (special_sum != 0.0) {
if (Py_IS_NAN(inf_sum))
PyErr_SetString(PyExc_ValueError,
"-inf + inf in fsum");
else
sum = PyFloat_FromDouble(special_sum);
goto _fsum_error;
}
hi = 0.0;
if (n > 0) {
hi = p[--n];
/* sum_exact(ps, hi) from the top, stop when the sum becomes
inexact. */
while (n > 0) {
x = hi;
y = p[--n];
assert(fabs(y) < fabs(x));
hi = x + y;
yr = hi - x;
lo = y - yr;
if (lo != 0.0)
break;
}
/* Make half-even rounding work across multiple partials.
Needed so that sum([1e-16, 1, 1e16]) will round-up the last
digit to two instead of down to zero (the 1e-16 makes the 1
slightly closer to two). With a potential 1 ULP rounding
error fixed-up, math.fsum() can guarantee commutativity. */
if (n > 0 && ((lo < 0.0 && p[n-1] < 0.0) ||
//.........这里部分代码省略.........
示例14: PyNeighbor_getradius
static PyObject*
PyNeighbor_getradius(PyNeighbor* self, void* closure)
{
float value = self->neighbor.radius;
return PyFloat_FromDouble((double)value);
}
示例15: next_token
static PyObject *next(PyObject *self)
{
ligolw_Tokenizer *tokenizer = (ligolw_Tokenizer *) self;
PyObject *type;
PyObject *token;
Py_UNICODE *start, *end;
/*
* Identify the start and end of the next token.
*/
do {
type = next_token(tokenizer, &start, &end);
if(!type)
return NULL;
} while(type == Py_None);
/*
* Extract token as desired type.
*/
if(start == NULL) {
/*
* unquoted zero-length string == None
*/
Py_INCREF(Py_None);
token = Py_None;
} else if(type == (PyObject *) &PyFloat_Type) {
char ascii_buffer[end - start + 1];
char *ascii_end;
if(PyUnicode_EncodeDecimal(start, end - start, ascii_buffer, NULL))
return NULL;
token = PyFloat_FromDouble(strtod(ascii_buffer, &ascii_end));
if(ascii_end == ascii_buffer || *ascii_end != 0) {
/*
* strtod() couldn't convert the token, emulate
* float()'s error message
*/
Py_XDECREF(token);
PyErr_Format(PyExc_ValueError, "invalid literal for float(): '%s'", ascii_buffer);
token = NULL;
}
} else if(type == (PyObject *) &PyUnicode_Type) {
token = PyUnicode_FromUnicode(start, end - start);
} else if(type == (PyObject *) &PyString_Type) {
token = PyUnicode_Encode(start, end - start, NULL, NULL);
} else if(type == (PyObject *) &PyInt_Type) {
token = PyInt_FromUnicode(start, end - start, 0);
} else if(type == (PyObject *) &PyLong_Type) {
token = PyLong_FromUnicode(start, end - start, 0);
} else {
token = PyObject_CallFunction(type, "u#", start, end - start);
}
/*
* Done.
*/
return token;
}