Skip to content

Commit

Permalink
Get rid of DEF REAL_TYPE and its associated IF declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Dec 14, 2023
1 parent cb0f747 commit 71a1bdf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
45 changes: 0 additions & 45 deletions cython/SnapPy.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,6 @@ cdef extern from "stdlib.h":
cdef extern from "string.h":
char* strncpy(char* dst, char* src, size_t len)

IF REAL_TYPE == 'qd_real':
from libcpp cimport bool as cpp_bool
cdef extern from "qd_real_SnapPy.h":
qd_real PI_SQUARED_BY_2
double default_vertex_epsilon
qd_real det_error_epsilon
cdef cppclass qd_real:
double x[4]
qd_real() except +
qd_real(double) except +
qd_real(char *) except +
qd_real(qd_real) except +
qd_real operator+(qd_real)
qd_real operator-(qd_real)
qd_real operator*(qd_real)
qd_real operator/(qd_real)
cpp_bool operator<(qd_real)
cpp_bool operator<(double)
cpp_bool operator>(qd_real)
cpp_bool operator>(double)
cpp_bool operator<=(qd_real)
cpp_bool operator<=(double)
cpp_bool operator>=(qd_real)
cpp_bool operator>=(double)
cpp_bool operator==(qd_real)
cpp_bool operator==(double)
cpp_bool operator!=(qd_real)
cpp_bool operator!=(double)
void write(char *s, int len, int precision)

ctypedef qd_real Real

cdef real_to_string(Real x):
cdef char buffer[128]
x.write(buffer, 128, 64)
return buffer # this should return a python string
ELIF REAL_TYPE == 'double':
ctypedef double Real
cdef extern from "double_SnapPy.h":
double PI_SQUARED_BY_2
double default_vertex_epsilon
double det_error_epsilon
cdef real_to_string(Real x):
return '%.18f' % x

# SnapPea declarations

# Cython can't handle arrays of C++ objects because of a bug which
Expand Down
3 changes: 2 additions & 1 deletion cython/SnapPy.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# cython: language_level=3str

DEF REAL_TYPE = 'double'
ctypedef double Real

include "SnapPy.pxi"
include "numbers/double.pyx"
include "core/basic.pyx"
Expand Down
4 changes: 3 additions & 1 deletion cython/SnapPyHP.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# distutils: language = c++
# distutils: sources = SnapPyHP.cpp
# cython: language_level=3str
DEF REAL_TYPE = "qd_real"

ctypedef qd_real Real

include "SnapPy.pxi"
include "numbers/qd.pyx"
include "core/basic.pyx"
Expand Down
9 changes: 8 additions & 1 deletion cython/numbers/double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ from .number import Number as RawNumber
class Number(RawNumber):
_default_precision=53

cdef extern from "double_SnapPy.h":
double PI_SQUARED_BY_2
double default_vertex_epsilon
double det_error_epsilon

cdef real_to_string(Real x):
return '%.18f' % x

cdef Real2gen_direct(Real R):
"""
Convert a Real to a pari gen of type t_REAL.
Expand All @@ -26,4 +34,3 @@ cdef Real2Number(Real R):
return Number(Real2gen(R))
cdef Complex2Number(Complex C):
return Number(Complex2gen(C))

34 changes: 34 additions & 0 deletions cython/numbers/qd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@ from .number import Number as RawNumber
class Number(RawNumber):
_default_precision=212

from libcpp cimport bool as cpp_bool
cdef extern from "qd_real_SnapPy.h":
qd_real PI_SQUARED_BY_2
double default_vertex_epsilon
qd_real det_error_epsilon
cdef cppclass qd_real:
double x[4]
qd_real() except +
qd_real(double) except +
qd_real(char *) except +
qd_real(qd_real) except +
qd_real operator+(qd_real)
qd_real operator-(qd_real)
qd_real operator*(qd_real)
qd_real operator/(qd_real)
cpp_bool operator<(qd_real)
cpp_bool operator<(double)
cpp_bool operator>(qd_real)
cpp_bool operator>(double)
cpp_bool operator<=(qd_real)
cpp_bool operator<=(double)
cpp_bool operator>=(qd_real)
cpp_bool operator>=(double)
cpp_bool operator==(qd_real)
cpp_bool operator==(double)
cpp_bool operator!=(qd_real)
cpp_bool operator!=(double)
void write(char *s, int len, int precision)

cdef real_to_string(Real x):
cdef char buffer[128]
x.write(buffer, 128, 64)
return buffer # this should return a python string

cdef Real2gen_direct(Real R):
"""
Convert a Real to a pari gen of type t_REAL. This constructs the gen
Expand Down

0 comments on commit 71a1bdf

Please sign in to comment.