本文整理匯總了C++中CHECK_CONTEXT函數的典型用法代碼示例。如果您正苦於以下問題:C++ CHECK_CONTEXT函數的具體用法?C++ CHECK_CONTEXT怎麽用?C++ CHECK_CONTEXT使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CHECK_CONTEXT函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GMPy_Real_Div_2exp
static PyObject *
GMPy_Real_Div_2exp(PyObject *x, PyObject *y, CTXT_Object *context)
{
MPFR_Object *result, *tempx;
unsigned long exp = 0;
CHECK_CONTEXT(context);
exp = c_ulong_From_Integer(y);
if (exp == (unsigned long)(-1) && PyErr_Occurred()) {
return NULL;
}
result = GMPy_MPFR_New(0, context);
tempx = GMPy_MPFR_From_Real(x, 1, context);
if (!result || !tempx) {
Py_XDECREF((PyObject*)result);
Py_XDECREF((PyObject*)tempx);
return NULL;
}
mpfr_clear_flags();
result->rc = mpfr_div_2ui(result->f, tempx->f, exp, GET_MPFR_ROUND(context));
Py_DECREF((PyObject*)tempx);
GMPY_MPFR_CLEANUP(result, context, "div_2exp()");
return (PyObject*)result;
}
示例2: GMPy_Complex_Is_NAN
static PyObject *
GMPy_Complex_Is_NAN(PyObject *x, CTXT_Object *context)
{
MPC_Object *tempx;
int res;
if (MPC_Check(x)) {
res = MPC_IS_NAN_P(x);
}
else {
CHECK_CONTEXT(context);
if (!(tempx = GMPy_MPC_From_Complex(x, 1, 1, context))) {
return NULL;
}
res = MPC_IS_NAN_P(tempx);
Py_DECREF((PyObject*)tempx);
}
if (res) {
Py_RETURN_TRUE;
}
else {
Py_RETURN_FALSE;
}
}
示例3: GMPy_Complex_Mul_2exp
static PyObject *
GMPy_Complex_Mul_2exp(PyObject *x, PyObject *y, CTXT_Object *context)
{
MPC_Object *result, *tempx;
unsigned long exp = 0;
CHECK_CONTEXT(context);
exp = c_ulong_From_Integer(y);
if (exp == (unsigned long)(-1) && PyErr_Occurred()) {
return NULL;
}
result = GMPy_MPC_New(0, 0, context);
tempx = GMPy_MPC_From_Complex(x, 1, 1, context);
if (!result || !tempx) {
Py_XDECREF((PyObject*)result);
Py_XDECREF((PyObject*)tempx);
return NULL;
}
result->rc = mpc_mul_2ui(result->c, tempx->c, exp, GET_MPC_ROUND(context));
Py_DECREF((PyObject*)tempx);
GMPY_MPC_CLEANUP(result, context, "mul_2exp()");
return (PyObject*)result;
}
示例4: GMPy_Real_Is_Integer
static PyObject *
GMPy_Real_Is_Integer(PyObject *x, CTXT_Object *context)
{
MPFR_Object *tempx;
int res;
if (MPFR_Check(x)) {
res = mpfr_integer_p(MPFR(x));
}
else {
CHECK_CONTEXT(context);
if (!(tempx = GMPy_MPFR_From_Real(x, 1, context))) {
return NULL;
}
res = mpfr_integer_p(tempx->f);
Py_DECREF((PyObject*)tempx);
}
if (res) {
Py_RETURN_TRUE;
}
else {
Py_RETURN_FALSE;
}
}
示例5: GMPy_XMPZ_Function_XbitMask
static PyObject *
GMPy_XMPZ_Function_XbitMask(PyObject *self, PyObject *other)
{
Py_ssize_t i = 0;
XMPZ_Object* result;
CTXT_Object *context = NULL;
CHECK_CONTEXT(context);
i = ssize_t_From_Integer(other);
if (i == -1 && PyErr_Occurred()) {
TYPE_ERROR("xbit_mask() requires 'int' argument");
return NULL;
}
if (i < 0) {
VALUE_ERROR("mask length must be >= 0");
return NULL;
}
if (!(result = GMPy_XMPZ_New(context))) {
return NULL;
}
mpz_set_ui(result->z, 1);
mpz_mul_2exp(result->z, result->z, i);
mpz_sub_ui(result->z, result->z, 1);
return (PyObject*)result;
}
示例6: GMPy_Context_Radians
static PyObject *
GMPy_Context_Radians(PyObject *self, PyObject *other)
{
MPFR_Object *result, *tempx, *temp;
CTXT_Object *context = NULL;
if (self && CTXT_Check(self)) {
context = (CTXT_Object*)self;
}
else {
CHECK_CONTEXT(context);
}
result = GMPy_MPFR_New(0, context);
temp = GMPy_MPFR_New(context->ctx.mpfr_prec + 100, context);
tempx = GMPy_MPFR_From_Real(other, 1, context);
if (!result || !temp || !tempx) {
Py_XDECREF((PyObject*)temp);
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)result);
return NULL;
}
mpfr_const_pi(temp->f, MPFR_RNDN);
mpfr_div_ui(temp->f, temp->f, 180, MPFR_RNDN);
mpfr_mul(result->f, MPFR(self), temp->f, MPFR_RNDN);
Py_DECREF((PyObject*)temp);
Py_DECREF((PyObject*)tempx);
_GMPy_MPFR_Cleanup(&result, context);
return (PyObject*)result;
}
示例7: GMPy_Rational_FloorDiv
static PyObject *
GMPy_Rational_FloorDiv(PyObject *x, PyObject *y, CTXT_Object *context)
{
MPZ_Object *result;
MPQ_Object *tempq;
CHECK_CONTEXT(context);
result = GMPy_MPZ_New(context);
tempq = GMPy_MPQ_New(context);
if (!result || !tempq) {
Py_XDECREF((PyObject*)result);
Py_XDECREF((PyObject*)tempq);
return NULL;
}
if (MPQ_Check(x) && MPQ_Check(y)) {
if (mpq_sgn(MPQ(y)) == 0) {
ZERO_ERROR("division or modulo by zero");
goto error;
}
mpq_div(tempq->q, MPQ(x), MPQ(y));
mpz_fdiv_q(result->z, mpq_numref(tempq->q), mpq_denref(tempq->q));
Py_DECREF((PyObject*)tempq);
return (PyObject*)result;
}
if (IS_RATIONAL(x) && IS_RATIONAL(y)) {
MPQ_Object *tempx, *tempy;
tempx = GMPy_MPQ_From_Number(x, context);
tempy = GMPy_MPQ_From_Number(y, context);
if (!tempx || !tempy) {
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)tempy);
goto error;
}
if (mpq_sgn(tempy->q) == 0) {
ZERO_ERROR("division or modulo by zero");
Py_DECREF((PyObject*)tempx);
Py_DECREF((PyObject*)tempy);
goto error;
}
mpq_div(tempq->q, tempx->q, tempy->q);
mpz_fdiv_q(result->z, mpq_numref(tempq->q), mpq_denref(tempq->q));
Py_DECREF((PyObject*)tempx);
Py_DECREF((PyObject*)tempy);
Py_DECREF((PyObject*)tempq);
return (PyObject*)result;
}
Py_DECREF((PyObject*)result);
Py_RETURN_NOTIMPLEMENTED;
error:
Py_DECREF((PyObject*)result);
Py_DECREF((PyObject*)tempq);
return NULL;
}
示例8: GMPy_Real_RemQuo
static PyObject *
GMPy_Real_RemQuo(PyObject *x, PyObject *y, CTXT_Object *context)
{
PyObject *result;
MPFR_Object *value, *tempx, *tempy;
long quobits = 0;
CHECK_CONTEXT(context);
value = GMPy_MPFR_New(0, context);
tempx = GMPy_MPFR_From_Real(x, 1, context);
tempy = GMPy_MPFR_From_Real(y, 1, context);
result = PyTuple_New(2);
if (!value || !tempx || !tempx || !result) {
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)tempy);
Py_XDECREF((PyObject*)value);
Py_XDECREF(result);
return NULL;
}
mpfr_clear_flags();
value->rc = mpfr_remquo(value->f, &quobits, tempx->f, tempy->f, GET_MPFR_ROUND(context));
Py_DECREF((PyObject*)tempx);
Py_DECREF((PyObject*)tempy);
_GMPy_MPFR_Cleanup(&value, context);
PyTuple_SET_ITEM(result, 0, (PyObject*)value);
PyTuple_SET_ITEM(result, 1, PyIntOrLong_FromLong(quobits));
return result;
}
示例9: PointerList_PushLast
rc_ReturnCode_t PointerList_PushLast(PointerList* list, void* pointer)
{
CHECK_CONTEXT(list);
// Check if we need to grow the buffer
if (list->nbOfElements == list->allocatedSize-1)
{
// Allocate the new buffer
void** buffer = malloc(list->allocatedSize*2*sizeof(*list->buffer));
if (!buffer)
return RC_NO_MEMORY;
// Copy the data from the previous buffer
if (list->readIdx < list->writeIdx)
memcpy(buffer, list->buffer + list->readIdx, (list->writeIdx - list->readIdx)*sizeof(*list->buffer));
else
{
memcpy(buffer, list->buffer + list->readIdx, (list->allocatedSize - list->readIdx)*sizeof(*list->buffer));
memcpy(buffer+(list->allocatedSize - list->readIdx), list->buffer, list->writeIdx*sizeof(*list->buffer));
}
free(list->buffer);
list->readIdx = 0;
list->writeIdx = list->nbOfElements;
list->buffer = buffer;
list->allocatedSize *= 2;
}
list->buffer[list->writeIdx] = pointer;
list->writeIdx = (list->writeIdx+1) % list->allocatedSize;
list->nbOfElements++;
return RC_OK;
}
示例10: PointerList_Remove
rc_ReturnCode_t PointerList_Remove(PointerList* list, unsigned int index, void** pointer)
{
CHECK_CONTEXT(list);
if (index >= list->nbOfElements)
{
*pointer = NULL;
return RC_OUT_OF_RANGE;
}
unsigned int i = (index+list->readIdx) % list->allocatedSize;
*pointer = list->buffer[i];
list->nbOfElements--;
unsigned int n;
for (n = list->nbOfElements - index; n>0; n--, i++)
{
if (i == list->allocatedSize-1)
{
list->buffer[i] = list->buffer[0];
i = 0;
}
else
list->buffer[i] = list->buffer[i+1];
}
list->writeIdx = (list->writeIdx - 1 + list->allocatedSize) % list->allocatedSize;
return RC_OK;
}
示例11: GMPy_Real_Frexp
static PyObject *
GMPy_Real_Frexp(PyObject *x, CTXT_Object *context)
{
PyObject *result;
MPFR_Object *value, *tempx;
mpfr_exp_t exp = 0;
CHECK_CONTEXT(context);
value = GMPy_MPFR_New(0, context);
tempx = GMPy_MPFR_From_Real(x, 1, context);
result = PyTuple_New(2);
if (!value || !result || !tempx) {
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)value);
Py_XDECREF(result);
return NULL;
}
mpfr_clear_flags();
value->rc = mpfr_frexp(&exp, value->f, tempx->f, GET_MPFR_ROUND(context));
Py_DECREF((PyObject*)tempx);
_GMPy_MPFR_Cleanup(&value, context);
PyTuple_SET_ITEM(result, 0, PyIntOrLong_FromSsize_t((Py_ssize_t)exp));
PyTuple_SET_ITEM(result, 1, (PyObject*)value);
return result;
}
示例12: GMPy_Real_Lgamma
static PyObject *
GMPy_Real_Lgamma(PyObject *x, CTXT_Object *context)
{
PyObject *result;
MPFR_Object *value, *tempx;
int signp = 0;
CHECK_CONTEXT(context)
tempx = GMPy_MPFR_From_Real(x, 1, context);
value = GMPy_MPFR_New(0, context);
result = PyTuple_New(2);
if (!tempx || !value || !result) {
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)value);
Py_XDECREF(result);
return NULL;
}
mpfr_clear_flags();
value->rc = mpfr_lgamma(value->f, &signp, tempx->f, GET_MPFR_ROUND(context));
Py_DECREF((PyObject*)tempx);
_GMPy_MPFR_Cleanup(&value, context);
if (!value) {
Py_DECREF(result);
return NULL;
}
PyTuple_SET_ITEM(result, 0, (PyObject*)value);
PyTuple_SET_ITEM(result, 1, PyIntOrLong_FromLong((long)signp));
return result;
}
示例13: GMPy_Context_NextBelow
static PyObject *
GMPy_Context_NextBelow(PyObject *self, PyObject *other)
{
MPFR_Object *result, *tempx;
CTXT_Object *context = NULL;
mpfr_rnd_t temp_round;
if (self && CTXT_Check(self)) {
context = (CTXT_Object*)self;
}
else {
CHECK_CONTEXT(context);
}
if (!(tempx = GMPy_MPFR_From_Real(other, 1, context))) {
TYPE_ERROR("next_below() argument type not supported");
return NULL;
}
if (!(result = GMPy_MPFR_New(mpfr_get_prec(tempx->f), context))) {
Py_DECREF((PyObject*)tempx);
return NULL;
}
mpfr_clear_flags();
mpfr_set(result->f, tempx->f, GET_MPFR_ROUND(context));
Py_DECREF((PyObject*)tempx);
mpfr_nextbelow(result->f);
result->rc = 0;
temp_round = GET_MPFR_ROUND(context);
context->ctx.mpfr_round = MPFR_RNDD;
_GMPy_MPFR_Cleanup(&result, context);
context->ctx.mpfr_round = temp_round;
return (PyObject*)result;
}
示例14: GMPy_Complex_Rect
static PyObject *
GMPy_Complex_Rect(PyObject *x, PyObject *y, CTXT_Object *context)
{
MPFR_Object *tempx, *tempy;
MPC_Object *result;
CHECK_CONTEXT(context);
tempx = GMPy_MPFR_From_Real(x, 1, context);
tempy = GMPy_MPFR_From_Real(y, 1, context);
result = GMPy_MPC_New(0, 0, context);
if (!tempx || !tempy || !result) {
Py_XDECREF((PyObject*)tempx);
Py_XDECREF((PyObject*)tempy);
Py_XDECREF((PyObject*)result);
return NULL;
}
mpfr_cos(mpc_realref(result->c), tempy->f, GET_REAL_ROUND(context));
mpfr_mul(mpc_realref(result->c), mpc_realref(result->c), tempx->f, GET_REAL_ROUND(context));
mpfr_sin(mpc_imagref(result->c), tempy->f, GET_IMAG_ROUND(context));
mpfr_mul(mpc_imagref(result->c), mpc_imagref(result->c), tempx->f, GET_IMAG_ROUND(context));
Py_DECREF((PyObject*)tempx);
Py_DECREF((PyObject*)tempy);
GMPY_MPC_CLEANUP(result, context, "rect()");
return (PyObject*)result;
}
示例15: GMPy_Context_Factorial
static PyObject *
GMPy_Context_Factorial(PyObject *self, PyObject *other)
{
MPFR_Object *result;
long n;
CTXT_Object *context = NULL;
if (self && CTXT_Check(self)) {
context = (CTXT_Object*)self;
}
else {
CHECK_CONTEXT(context);
}
n = PyLong_AsLong(other);
if ((n == -1) && PyErr_Occurred()) {
TYPE_ERROR("factorial() requires 'int' argument");
return NULL;
}
if (n < 0) {
VALUE_ERROR("factorial() of negative number");
return NULL;
}
if (!(result = GMPy_MPFR_New(0, context))) {
return NULL;
}
mpfr_clear_flags();
mpfr_fac_ui(result->f, n, GET_MPFR_ROUND(context));
_GMPy_MPFR_Cleanup(&result, context);
return (PyObject*)result;
}