Commit 8e5064da authored by Cerlane Leong's avatar Cerlane Leong 💬

python bug fixes

parent fb3488e9
V0.4RC
1) Added support for P32
V0.3.2
1) Fixed lt, le and eq. int_fast16_t types cannot represent negative numbers
......
......@@ -296,6 +296,9 @@ class posit32_t(_object):
def toI64(self):
return _softposit.posit32_t_toI64(self)
def castInt(self):
return _softposit.posit32_t_castInt(self)
def i32ToP32(self, a):
return _softposit.posit32_t_i32ToP32(self, a)
......@@ -1067,6 +1070,10 @@ def p32_lt(arg1, arg2):
return _softposit.p32_lt(arg1, arg2)
p32_lt = _softposit.p32_lt
def p32_toInteger(arg1):
return _softposit.p32_toInteger(arg1)
p32_toInteger = _softposit.p32_toInteger
def q32_fdp_add(arg1, arg2, arg3):
return _softposit.q32_fdp_add(arg1, arg2, arg3)
q32_fdp_add = _softposit.q32_fdp_add
......@@ -1129,7 +1136,14 @@ class posit8:
a.v = _softposit.p8_sub(self.v, other.v)
return a
def __rsub__(self, other):
return self.__sub__(other)
a = posit8(0)
if isinstance(other, (int)):
a.v = _softposit.p8_sub(self.v.i64ToP8(other), self.v)
elif isinstance(other, (float)):
a.v = _softposit.p8_sub(_softposit.convertDoubleToP8(other), self.v)
else:
a.v = _softposit.p8_sub(other.v, self.v)
return a
def __mul__(self, other):
a = posit8(0)
if isinstance(other, (int)):
......@@ -1355,9 +1369,10 @@ class quire8:
else:
self.v = _softposit.q8_fdp_sub(self.v, other1.v, other2.v)
return self
def toPosit(self):
self.v = _softposit.q8_to_p8(self.v);
return self
def toPosit(self):
a = posit8(0)
a.v = _softposit.q8_to_p8(self.v);
return a
def clr(self):
self.v = _softposit.q8Clr();
def isNaR(self):
......@@ -1408,7 +1423,14 @@ class posit16:
a.v = _softposit.p16_sub(self.v, other.v)
return a
def __rsub__(self, other):
return self.__sub__(other)
a = posit16(0)
if isinstance(other, (int)):
a.v = _softposit.p16_sub(self.v.i64ToP16(other), self.v)
elif isinstance(other, (float)):
a.v = _softposit.p16_sub(_softposit.convertDoubleToP16(other), self.v)
else:
a.v = _softposit.p16_sub(other.v, self.v)
return a
def __mul__(self, other):
a = posit16(0)
if isinstance(other, (int)):
......@@ -1635,9 +1657,10 @@ class quire16:
else:
self.v = _softposit.q16_fdp_sub(self.v, other1.v, other2.v)
return self
def toPosit(self):
self.v = _softposit.q16_to_p16(self.v);
return self
def toPosit(self):
a = posit16(0)
a.v = _softposit.q16_to_p16(self.v);
return a
def clr(self):
self.v = _softposit.q16Clr();
def isNaR(self):
......@@ -1688,7 +1711,14 @@ class posit32:
a.v = _softposit.p32_sub(self.v, other.v)
return a
def __rsub__(self, other):
return self.__sub__(other)
a = posit32(0)
if isinstance(other, (int)):
a.v = _softposit.p32_sub(self.v.i64ToP32(other), self.v)
elif isinstance(other, (float)):
a.v = _softposit.p32_sub(_softposit.convertDoubleToP32(other), self.v)
else:
a.v = _softposit.p32_sub(other.v, self.v)
return a
def __mul__(self, other):
a = posit32(0)
if isinstance(other, (int)):
......@@ -1914,9 +1944,10 @@ class quire32:
else:
self.v = _softposit.q32_fdp_sub(self.v, other1.v, other2.v)
return self
def toPosit(self):
self.v = _softposit.q32_to_p32(self.v);
return self
def toPosit(self):
a = posit32(0)
a.v = _softposit.q32_to_p32(self.v);
return a
def clr(self):
self.v = _softposit.q32Clr();
def isNaR(self):
......
......@@ -3357,6 +3357,9 @@ SWIGINTERN int posit32_t_toInt(posit32_t *self){
SWIGINTERN int posit32_t_toI64(posit32_t *self){
return (int) p32_to_i64(*self);
}
SWIGINTERN int posit32_t_castInt(posit32_t *self){
return (int) p32_toInteger(*self);
}
SWIGINTERN posit32_t posit32_t_i32ToP32(posit32_t *self,int a){
return i32_to_p32((int32_t)a);
}
......@@ -4860,6 +4863,28 @@ fail:
}
SWIGINTERN PyObject *_wrap_posit32_t_castInt(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
posit32_t *arg1 = (posit32_t *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
int result;
if (!PyArg_ParseTuple(args,(char *)"O:posit32_t_castInt",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_posit32_t, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "posit32_t_castInt" "', argument " "1"" of type '" "posit32_t *""'");
}
arg1 = (posit32_t *)(argp1);
result = (int)posit32_t_castInt(arg1);
resultobj = SWIG_From_int((int)(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_posit32_t_i32ToP32(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
posit32_t *arg1 = (posit32_t *) 0 ;
......@@ -9919,6 +9944,34 @@ fail:
}
SWIGINTERN PyObject *_wrap_p32_toInteger(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
posit32_t arg1 ;
void *argp1 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
int64_t result;
if (!PyArg_ParseTuple(args,(char *)"O:p32_toInteger",&obj0)) SWIG_fail;
{
res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_posit32_t, 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "p32_toInteger" "', argument " "1"" of type '" "posit32_t""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "p32_toInteger" "', argument " "1"" of type '" "posit32_t""'");
} else {
arg1 = *((posit32_t *)(argp1));
}
}
result = p32_toInteger(arg1);
resultobj = SWIG_NewPointerObj((int64_t *)memcpy((int64_t *)calloc(1,sizeof(int64_t)),&result,sizeof(int64_t)), SWIGTYPE_p_int64_t, SWIG_POINTER_OWN | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_q32_fdp_add(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
quire32_t arg1 ;
......@@ -10229,6 +10282,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"posit32_t_toHex", _wrap_posit32_t_toHex, METH_VARARGS, NULL},
{ (char *)"posit32_t_toInt", _wrap_posit32_t_toInt, METH_VARARGS, NULL},
{ (char *)"posit32_t_toI64", _wrap_posit32_t_toI64, METH_VARARGS, NULL},
{ (char *)"posit32_t_castInt", _wrap_posit32_t_castInt, METH_VARARGS, NULL},
{ (char *)"posit32_t_i32ToP32", _wrap_posit32_t_i32ToP32, METH_VARARGS, NULL},
{ (char *)"posit32_t_i64ToP32", _wrap_posit32_t_i64ToP32, METH_VARARGS, NULL},
{ (char *)"posit32_t___rshift__", _wrap_posit32_t___rshift__, METH_VARARGS, NULL},
......@@ -10415,6 +10469,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"p32_eq", _wrap_p32_eq, METH_VARARGS, NULL},
{ (char *)"p32_le", _wrap_p32_le, METH_VARARGS, NULL},
{ (char *)"p32_lt", _wrap_p32_lt, METH_VARARGS, NULL},
{ (char *)"p32_toInteger", _wrap_p32_toInteger, METH_VARARGS, NULL},
{ (char *)"q32_fdp_add", _wrap_q32_fdp_add, METH_VARARGS, NULL},
{ (char *)"q32_fdp_sub", _wrap_q32_fdp_sub, METH_VARARGS, NULL},
{ (char *)"q32_to_p32", _wrap_q32_to_p32, METH_VARARGS, NULL},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment