Ticket #8847: trac_8847-take4.patch

File trac_8847-take4.patch, 2.9 KB (added by mhansen, 9 years ago)
  • sage/symbolic/pynac.pyx

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1274840359 25200
    # Node ID 959d63b9f1e9aec57ccb9ecfc8782aa0717a22cc
    # Parent  2898b0963ffe53de723c352c1fdf4e18f28b60b0
    trac 8847 -- pynac.pyx use double precision special functions instead of long double
    
    diff -r 2898b0963ffe -r 959d63b9f1e9 sage/symbolic/pynac.pyx
    a b  
    77#                  http://www.gnu.org/licenses/
    88###############################################################################
    99
    10 cdef extern from "math.h":
    11     long double logl(long double)
    12     long double sqrtl(long double)
    13     long double tgammal(long double)
    14     long double lgammal(long double)
     10cdef extern from "pynac_cc.h":
     11    long double sage_logl(long double)
     12    long double sage_sqrtl(long double)
     13    long double sage_tgammal(long double)
     14    long double sage_lgammal(long double)
    1515
    1616include "../ext/cdefs.pxi"
    1717include "../ext/stdsage.pxi"
     
    10271027#################################################################
    10281028cdef public object py_tgamma(object x) except +:
    10291029    if PY_TYPE_CHECK_EXACT(x, float):
    1030         return tgammal(x)
     1030        return sage_tgammal(x)
    10311031    #FIXME: complex
    10321032    try:
    10331033        return x.gamma()
     
    12551255        x = float(x)
    12561256    if PY_TYPE_CHECK_EXACT(x, float):
    12571257        if (<float>x) > 0:
    1258             return logl(x)
     1258            return sage_logl(x)
    12591259        elif x < 0:
    12601260            res = gsl_complex_log(gsl_complex_rect(PyFloat_AsDouble(x), 0))
    12611261            return PyComplex_FromDoubles(res.dat[0], res.dat[1])
     
    13821382
    13831383cdef public object py_lgamma(object x) except +:
    13841384    if PY_TYPE_CHECK_EXACT(x, float):
    1385         return lgammal(x)
     1385        return sage_lgammal(x)
    13861386    #FIXME: complex
    13871387    try:
    13881388        return x.log_gamma()
     
    13971397        # WORRY: What if Integer's sqrt calls symbolic one and we go in circle?
    13981398        return x.sqrt() 
    13991399    except AttributeError, msg:
    1400         return sqrtl(float(x))
     1400        return sage_sqrtl(float(x))
    14011401
    14021402cdef public object py_abs(object x) except +:
    14031403    return abs(x)
  • new file sage/symbolic/pynac_cc.h

    diff -r 2898b0963ffe -r 959d63b9f1e9 sage/symbolic/pynac_cc.h
    - +  
     1#include <math.h>
     2
     3inline long double sage_logl(long double x)
     4{
     5#if defined(__CYGWIN__)
     6  return log(x);
     7#else
     8  return logl(x);
     9#endif
     10}
     11
     12inline long double sage_sqrtl(long double x)
     13{
     14#if defined(__CYGWIN__)
     15  return sqrt(x);
     16#else
     17  return sqrtl(x);
     18#endif
     19}
     20
     21inline long double sage_tgammal(long double x)
     22{
     23#if defined(__CYGWIN__)
     24  return tgamma(x);
     25#else
     26  return tgammal(x);
     27#endif
     28}
     29
     30inline long double sage_lgammal(long double x)
     31{
     32#if defined(__CYGWIN__)
     33  return lgamma(x);
     34#else
     35  return lgammal(x);
     36#endif
     37}