fix cast from double to long long
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8458 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
01597d58c1
commit
5601aff69c
3 changed files with 11 additions and 5 deletions
|
|
@ -192,9 +192,11 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val)
|
|||
}
|
||||
}
|
||||
if (!dispatch) {
|
||||
const double mant_max = 1LL << DBL_MANT_DIG;
|
||||
const double mant_min = -mant_max;
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LLONG_MIN, LLONG_MAX)) {
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) {
|
||||
if (val) *val = (long long)(d);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -250,9 +252,10 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
|||
}
|
||||
}
|
||||
if (!dispatch) {
|
||||
const double mant_max = 1LL << DBL_MANT_DIG;
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULLONG_MAX)) {
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
|
||||
if (val) *val = (unsigned long long)(d);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,9 +185,11 @@ SWIG_AsVal_dec(long long)(PyObject *obj, long long *val)
|
|||
PyErr_Clear();
|
||||
}
|
||||
if (!dispatch) {
|
||||
const double mant_max = 1LL << DBL_MANT_DIG;
|
||||
const double mant_min = -mant_max;
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LLONG_MIN, LLONG_MAX)) {
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) {
|
||||
if (val) *val = (long long)(d);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -247,9 +249,10 @@ SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val)
|
|||
PyErr_Clear();
|
||||
}
|
||||
if (!dispatch) {
|
||||
const double mant_max = 1LL << DBL_MANT_DIG;
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULLONG_MAX)) {
|
||||
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
|
||||
if (val) *val = (unsigned long long)(d);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ SWIG_AsVal_dec(ptrdiff_t)(SWIG_Object obj, ptrdiff_t *val)
|
|||
SWIGINTERNINLINE int
|
||||
SWIG_CanCastAsInteger(double *d, double min, double max) {
|
||||
double x = *d;
|
||||
if (min <= x && x <= max) {
|
||||
if ((min <= x && x <= max)) {
|
||||
double fx = floor(x);
|
||||
double rd = ((x - fx) < 0.5) ? fx : ceil(x); /* simple rint */
|
||||
if ((errno == EDOM) || (errno == ERANGE)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue