the beginnings of posit interface
authorBill Zorn <bill.zorn@gmail.com>
Tue, 24 Jul 2018 01:32:31 +0000 (18:32 -0700)
committerBill Zorn <bill.zorn@gmail.com>
Tue, 24 Jul 2018 01:32:31 +0000 (18:32 -0700)
cposit.pxd [new file with mode: 0644]
posit.pyx [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/cposit.pxd b/cposit.pxd
new file mode 100644 (file)
index 0000000..b15cc10
--- /dev/null
@@ -0,0 +1,9 @@
+from libc.stdint cimport *
+
+cdef extern from 'SoftPosit/source/include/softposit.h':
+
+    ctypedef struct posit8_t:
+        pass
+
+    posit8_t  i64_to_p8( int64_t );
+    int_fast64_t p8_to_i64( posit8_t);
diff --git a/posit.pyx b/posit.pyx
new file mode 100644 (file)
index 0000000..3bbeabf
--- /dev/null
+++ b/posit.pyx
@@ -0,0 +1,11 @@
+cimport cposit
+
+cdef class Posit8:
+    cdef cposit.posit8_t _c_posit
+
+    def __cinit__(self):
+        self._c_posit = cposit.i64_to_p8(1)
+
+    cpdef show(self):
+        print(cposit.p8_to_i64(self._c_posit))
+    
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..82b066d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,14 @@
+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Build import cythonize
+
+ext = Extension('posit', ['posit.pyx'],
+    include_dirs=['SoftPosit/source/include/'],
+    extra_objects=['./SoftPosit/build/Linux-x86_64-GCC/softposit.a'],
+    libraries=['m'],
+)
+
+setup(
+    name='sfpy',
+    ext_modules=cythonize([ext]),
+)