Hello,

I was hoping to write a fast function to give a floating
point approximation of a quadratic number. With the code given as in the
attached file I got the following compilation error

sage: %runfile quadratic_numerical_approx.pyx
RuntimeError: Error compiling ./quadratic_numerical_approx.pyx:
running build
running build_ext
building
'_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9' extension
gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC
-I/opt/sage_flatsurf/local/include
-I/opt/sage_flatsurf/local/include/python2.7
-I/opt/sage_flatsurf/local/lib/python2.7/site-packages/numpy/core/include -I/opt/sage_flatsurf/local/lib/python2.7/site-packages
-I/opt/sage_flatsurf/local/lib/python2.7/site-packages/sage/ext -I.
-I/opt/sage_flatsurf/local/include/python2.7 -c
_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.c -o
build/temp.linux-x86_64-2.7/_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.o
-w -O2

_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.c:1383:14:
error: field ‘x’ has incomplete type
    struct ZZX x;
               ^
_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.c:1389:13:
error: field ‘x’ has incomplete type
    struct ZZ x;
              ^
_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.c:1613:14:
error: field ‘__pyx___numerator’ has incomplete type
    struct ZZX __pyx___numerator;
               ^
_home_vincent_programming_grace_quadratic_numerical_approx_pyx_9.c:1614:13:
error: field ‘__pyx___denominator’ has incomplete type
    struct ZZ __pyx___denominator;
              ^
error: command 'gcc' failed with exit status 1


Please help!

Best,
Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.
from sage.libs.gmp.mpz cimport *
from sage.libs.mpfr cimport *

from sage.rings.number_field.number_field_element_quadratic cimport NumberFieldElement_quadratic

from sage.rings.real_mpfr cimport RealNumber, RealField_class

def quad_nf_element_numerical_approx(NumberFieldElement_quadratic x,
        RealField_class R):
    r"""
    Return an approximation of the quadratic element ``x`` in the given real
    field ``R``.
    """
    cdef RealNumber y = R._new()
    mpfr_set_z(y.value, x.D.value, R.rnd)
    mpfr_sqrt(y.value, y.value, R.rnd)
    mpfr_mul_z(y.value, y.value, x.b, R.rnd)
    mpfr_add_z(y.value, y.value, x.a, R.rnd)
    return y

Reply via email to