Ticket #8847: trac_8847-take3.patch

File trac_8847-take3.patch, 2.8 KB (added by was, 9 years ago)
  • c_lib/include/ginac_wrap.h

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1274840359 25200
    # Node ID bc6b0f6628bfcc8a8e9a272a6c4ef31af9092ccd
    # Parent  bb9e9b1ca4f0c18671752b7911566ee21f06daa4
    trac 8847 -- pynac.pyx use double precision special functions instead of long double
    
    diff --git a/c_lib/include/ginac_wrap.h b/c_lib/include/ginac_wrap.h
    a b  
    126126#define NE_WRAP(x,y)  (x)!=(y)
    127127#define GE_WRAP(x,y)  (x)>=(y)
    128128
     129inline long double sage_logl(long double x)
     130{
     131#if defined(__CYGWIN__)
     132  return log(x);
     133#else
     134  return logl(x);
     135#endif
     136}
     137
     138inline long double sage_sqrtl(long double x)
     139{
     140#if defined(__CYGWIN__)
     141  return sqrt(x);
     142#else
     143  return sqrtl(x);
     144#endif
     145}
     146
     147inline long double sage_tgammal(long double x)
     148{
     149#if defined(__CYGWIN__)
     150  return tgamma(x);
     151#else
     152  return tgammal(x);
     153#endif
     154}
     155
     156inline long double sage_lgammal(long double x)
     157{
     158#if defined(__CYGWIN__)
     159  return lgamma(x);
     160#else
     161  return lgammal(x);
     162#endif
     163}
  • sage/symbolic/pynac.pyx

    diff --git a/sage/symbolic/pynac.pyx b/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 "ginac_wrap.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"
     
    11221122#################################################################
    11231123cdef public object py_tgamma(object x) except +:
    11241124    if PY_TYPE_CHECK_EXACT(x, float):
    1125         return tgammal(x)
     1125        return sage_tgammal(x)
    11261126    #FIXME: complex
    11271127    try:
    11281128        return x.gamma()
     
    13501350        x = float(x)
    13511351    if PY_TYPE_CHECK_EXACT(x, float):
    13521352        if (<float>x) > 0:
    1353             return logl(x)
     1353            return sage_logl(x)
    13541354        elif x < 0:
    13551355            res = gsl_complex_log(gsl_complex_rect(PyFloat_AsDouble(x), 0))
    13561356            return PyComplex_FromDoubles(res.dat[0], res.dat[1])
     
    14771477
    14781478cdef public object py_lgamma(object x) except +:
    14791479    if PY_TYPE_CHECK_EXACT(x, float):
    1480         return lgammal(x)
     1480        return sage_lgammal(x)
    14811481    #FIXME: complex
    14821482    try:
    14831483        return x.log_gamma()
     
    14921492        # WORRY: What if Integer's sqrt calls symbolic one and we go in circle?
    14931493        return x.sqrt() 
    14941494    except AttributeError, msg:
    1495         return sqrtl(float(x))
     1495        return sage_sqrtl(float(x))
    14961496
    14971497cdef public object py_abs(object x) except +:
    14981498    return abs(x)