Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/cmathmodule.c

    r2 r388  
    44
    55#include "Python.h"
     6#include "_math.h"
    67/* we need DBL_MAX, DBL_MIN, DBL_EPSILON, DBL_MANT_DIG and FLT_RADIX from
    78   float.h.  We assume that FLT_RADIX is either 2 or 16. */
     
    2324   CM_LARGE_DOUBLE is used to avoid spurious overflow in the sqrt, log,
    2425   inverse trig and inverse hyperbolic trig functions.  Its log is used in the
    25    evaluation of exp, cos, cosh, sin, sinh, tan, and tanh to avoid unecessary
     26   evaluation of exp, cos, cosh, sin, sinh, tan, and tanh to avoid unnecessary
    2627   overflow.
    2728 */
     
    3233#define CM_SQRT_DBL_MIN (sqrt(DBL_MIN))
    3334
    34 /* 
     35/*
    3536   CM_SCALE_UP is an odd integer chosen such that multiplication by
    3637   2**CM_SCALE_UP is sufficient to turn a subnormal into a normal.
     
    6364
    6465enum special_types {
    65         ST_NINF,        /* 0, negative infinity */
    66         ST_NEG,         /* 1, negative finite number (nonzero) */
    67         ST_NZERO,       /* 2, -0. */
    68         ST_PZERO,       /* 3, +0. */
    69         ST_POS,         /* 4, positive finite number (nonzero) */
    70         ST_PINF,        /* 5, positive infinity */
    71         ST_NAN          /* 6, Not a Number */
     66    ST_NINF,            /* 0, negative infinity */
     67    ST_NEG,             /* 1, negative finite number (nonzero) */
     68    ST_NZERO,           /* 2, -0. */
     69    ST_PZERO,           /* 3, +0. */
     70    ST_POS,             /* 4, positive finite number (nonzero) */
     71    ST_PINF,            /* 5, positive infinity */
     72    ST_NAN              /* 6, Not a Number */
    7273};
    7374
     
    7576special_type(double d)
    7677{
    77         if (Py_IS_FINITE(d)) {
    78                 if (d != 0) {
    79                         if (copysign(1., d) == 1.)
    80                                 return ST_POS;
    81                         else
    82                                 return ST_NEG;
    83                 }
    84                 else {
    85                         if (copysign(1., d) == 1.)
    86                                 return ST_PZERO;
    87                         else
    88                                 return ST_NZERO;
    89                 }
    90         }
    91         if (Py_IS_NAN(d))
    92                 return ST_NAN;
    93         if (copysign(1., d) == 1.)
    94                 return ST_PINF;
    95         else
    96                 return ST_NINF;
    97 }
    98 
    99 #define SPECIAL_VALUE(z, table)                                         \
    100         if (!Py_IS_FINITE((z).real) || !Py_IS_FINITE((z).imag)) {       \
    101                 errno = 0;                                              \
    102                 return table[special_type((z).real)]                    \
    103                             [special_type((z).imag)];                   \
    104         }
     78    if (Py_IS_FINITE(d)) {
     79        if (d != 0) {
     80            if (copysign(1., d) == 1.)
     81                return ST_POS;
     82            else
     83                return ST_NEG;
     84        }
     85        else {
     86            if (copysign(1., d) == 1.)
     87                return ST_PZERO;
     88            else
     89                return ST_NZERO;
     90        }
     91    }
     92    if (Py_IS_NAN(d))
     93        return ST_NAN;
     94    if (copysign(1., d) == 1.)
     95        return ST_PINF;
     96    else
     97        return ST_NINF;
     98}
     99
     100#define SPECIAL_VALUE(z, table)                                         \
     101    if (!Py_IS_FINITE((z).real) || !Py_IS_FINITE((z).imag)) {           \
     102        errno = 0;                                              \
     103        return table[special_type((z).real)]                            \
     104                    [special_type((z).imag)];                           \
     105    }
    105106
    106107#define P Py_MATH_PI
     
    126127c_acos(Py_complex z)
    127128{
    128         Py_complex s1, s2, r;
    129 
    130         SPECIAL_VALUE(z, acos_special_values);
    131 
    132         if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
    133                 /* avoid unnecessary overflow for large arguments */
    134                 r.real = atan2(fabs(z.imag), z.real);
    135                 /* split into cases to make sure that the branch cut has the
    136                    correct continuity on systems with unsigned zeros */
    137                 if (z.real < 0.) {
    138                         r.imag = -copysign(log(hypot(z.real/2., z.imag/2.)) +
    139                                            M_LN2*2., z.imag);
    140                 } else {
    141                         r.imag = copysign(log(hypot(z.real/2., z.imag/2.)) +
    142                                           M_LN2*2., -z.imag);
    143                 }
    144         } else {
    145                 s1.real = 1.-z.real;
    146                 s1.imag = -z.imag;
    147                 s1 = c_sqrt(s1);
    148                 s2.real = 1.+z.real;
    149                 s2.imag = z.imag;
    150                 s2 = c_sqrt(s2);
    151                 r.real = 2.*atan2(s1.real, s2.real);
    152                 r.imag = asinh(s2.real*s1.imag - s2.imag*s1.real);
    153         }
    154         errno = 0;
    155         return r;
     129    Py_complex s1, s2, r;
     130
     131    SPECIAL_VALUE(z, acos_special_values);
     132
     133    if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
     134        /* avoid unnecessary overflow for large arguments */
     135        r.real = atan2(fabs(z.imag), z.real);
     136        /* split into cases to make sure that the branch cut has the
     137           correct continuity on systems with unsigned zeros */
     138        if (z.real < 0.) {
     139            r.imag = -copysign(log(hypot(z.real/2., z.imag/2.)) +
     140                               M_LN2*2., z.imag);
     141        } else {
     142            r.imag = copysign(log(hypot(z.real/2., z.imag/2.)) +
     143                              M_LN2*2., -z.imag);
     144        }
     145    } else {
     146        s1.real = 1.-z.real;
     147        s1.imag = -z.imag;
     148        s1 = c_sqrt(s1);
     149        s2.real = 1.+z.real;
     150        s2.imag = z.imag;
     151        s2 = c_sqrt(s2);
     152        r.real = 2.*atan2(s1.real, s2.real);
     153        r.imag = m_asinh(s2.real*s1.imag - s2.imag*s1.real);
     154    }
     155    errno = 0;
     156    return r;
    156157}
    157158
     
    167168c_acosh(Py_complex z)
    168169{
    169         Py_complex s1, s2, r;
    170 
    171         SPECIAL_VALUE(z, acosh_special_values);
    172 
    173         if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
    174                 /* avoid unnecessary overflow for large arguments */
    175                 r.real = log(hypot(z.real/2., z.imag/2.)) + M_LN2*2.;
    176                 r.imag = atan2(z.imag, z.real);
    177         } else {
    178                 s1.real = z.real - 1.;
    179                 s1.imag = z.imag;
    180                 s1 = c_sqrt(s1);
    181                 s2.real = z.real + 1.;
    182                 s2.imag = z.imag;
    183                 s2 = c_sqrt(s2);
    184                 r.real = asinh(s1.real*s2.real + s1.imag*s2.imag);
    185                 r.imag = 2.*atan2(s1.imag, s2.real);
    186         }
    187         errno = 0;
    188         return r;
     170    Py_complex s1, s2, r;
     171
     172    SPECIAL_VALUE(z, acosh_special_values);
     173
     174    if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
     175        /* avoid unnecessary overflow for large arguments */
     176        r.real = log(hypot(z.real/2., z.imag/2.)) + M_LN2*2.;
     177        r.imag = atan2(z.imag, z.real);
     178    } else {
     179        s1.real = z.real - 1.;
     180        s1.imag = z.imag;
     181        s1 = c_sqrt(s1);
     182        s2.real = z.real + 1.;
     183        s2.imag = z.imag;
     184        s2 = c_sqrt(s2);
     185        r.real = m_asinh(s1.real*s2.real + s1.imag*s2.imag);
     186        r.imag = 2.*atan2(s1.imag, s2.real);
     187    }
     188    errno = 0;
     189    return r;
    189190}
    190191
     
    198199c_asin(Py_complex z)
    199200{
    200         /* asin(z) = -i asinh(iz) */
    201         Py_complex s, r;
    202         s.real = -z.imag;
    203         s.imag = z.real;
    204         s = c_asinh(s);
    205         r.real = s.imag;
    206         r.imag = -s.real;
    207         return r;
     201    /* asin(z) = -i asinh(iz) */
     202    Py_complex s, r;
     203    s.real = -z.imag;
     204    s.imag = z.real;
     205    s = c_asinh(s);
     206    r.real = s.imag;
     207    r.imag = -s.real;
     208    return r;
    208209}
    209210
     
    219220c_asinh(Py_complex z)
    220221{
    221         Py_complex s1, s2, r;
    222 
    223         SPECIAL_VALUE(z, asinh_special_values);
    224 
    225         if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
    226                 if (z.imag >= 0.) {
    227                         r.real = copysign(log(hypot(z.real/2., z.imag/2.)) +
    228                                           M_LN2*2., z.real);
    229                 } else {
    230                         r.real = -copysign(log(hypot(z.real/2., z.imag/2.)) +
    231                                            M_LN2*2., -z.real);
    232                 }
    233                 r.imag = atan2(z.imag, fabs(z.real));
    234         } else {
    235                 s1.real = 1.+z.imag;
    236                 s1.imag = -z.real;
    237                 s1 = c_sqrt(s1);
    238                 s2.real = 1.-z.imag;
    239                 s2.imag = z.real;
    240                 s2 = c_sqrt(s2);
    241                 r.real = asinh(s1.real*s2.imag-s2.real*s1.imag);
    242                 r.imag = atan2(z.imag, s1.real*s2.real-s1.imag*s2.imag);
    243         }
    244         errno = 0;
    245         return r;
     222    Py_complex s1, s2, r;
     223
     224    SPECIAL_VALUE(z, asinh_special_values);
     225
     226    if (fabs(z.real) > CM_LARGE_DOUBLE || fabs(z.imag) > CM_LARGE_DOUBLE) {
     227        if (z.imag >= 0.) {
     228            r.real = copysign(log(hypot(z.real/2., z.imag/2.)) +
     229                              M_LN2*2., z.real);
     230        } else {
     231            r.real = -copysign(log(hypot(z.real/2., z.imag/2.)) +
     232                               M_LN2*2., -z.real);
     233        }
     234        r.imag = atan2(z.imag, fabs(z.real));
     235    } else {
     236        s1.real = 1.+z.imag;
     237        s1.imag = -z.real;
     238        s1 = c_sqrt(s1);
     239        s2.real = 1.-z.imag;
     240        s2.imag = z.real;
     241        s2 = c_sqrt(s2);
     242        r.real = m_asinh(s1.real*s2.imag-s2.real*s1.imag);
     243        r.imag = atan2(z.imag, s1.real*s2.real-s1.imag*s2.imag);
     244    }
     245    errno = 0;
     246    return r;
    246247}
    247248
     
    255256c_atan(Py_complex z)
    256257{
    257         /* atan(z) = -i atanh(iz) */
    258         Py_complex s, r;
    259         s.real = -z.imag;
    260         s.imag = z.real;
    261         s = c_atanh(s);
    262         r.real = s.imag;
    263         r.imag = -s.real;
    264         return r;
     258    /* atan(z) = -i atanh(iz) */
     259    Py_complex s, r;
     260    s.real = -z.imag;
     261    s.imag = z.real;
     262    s = c_atanh(s);
     263    r.real = s.imag;
     264    r.imag = -s.real;
     265    return r;
    265266}
    266267
     
    270271c_atan2(Py_complex z)
    271272{
    272         if (Py_IS_NAN(z.real) || Py_IS_NAN(z.imag))
    273                 return Py_NAN;
    274         if (Py_IS_INFINITY(z.imag)) {
    275                 if (Py_IS_INFINITY(z.real)) {
    276                         if (copysign(1., z.real) == 1.)
    277                                 /* atan2(+-inf, +inf) == +-pi/4 */
    278                                 return copysign(0.25*Py_MATH_PI, z.imag);
    279                         else
    280                                 /* atan2(+-inf, -inf) == +-pi*3/4 */
    281                                 return copysign(0.75*Py_MATH_PI, z.imag);
    282                 }
    283                 /* atan2(+-inf, x) == +-pi/2 for finite x */
    284                 return copysign(0.5*Py_MATH_PI, z.imag);
    285         }
    286         if (Py_IS_INFINITY(z.real) || z.imag == 0.) {
    287                 if (copysign(1., z.real) == 1.)
    288                         /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
    289                         return copysign(0., z.imag);
    290                 else
    291                         /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
    292                         return copysign(Py_MATH_PI, z.imag);
    293         }
    294         return atan2(z.imag, z.real);
     273    if (Py_IS_NAN(z.real) || Py_IS_NAN(z.imag))
     274        return Py_NAN;
     275    if (Py_IS_INFINITY(z.imag)) {
     276        if (Py_IS_INFINITY(z.real)) {
     277            if (copysign(1., z.real) == 1.)
     278                /* atan2(+-inf, +inf) == +-pi/4 */
     279                return copysign(0.25*Py_MATH_PI, z.imag);
     280            else
     281                /* atan2(+-inf, -inf) == +-pi*3/4 */
     282                return copysign(0.75*Py_MATH_PI, z.imag);
     283        }
     284        /* atan2(+-inf, x) == +-pi/2 for finite x */
     285        return copysign(0.5*Py_MATH_PI, z.imag);
     286    }
     287    if (Py_IS_INFINITY(z.real) || z.imag == 0.) {
     288        if (copysign(1., z.real) == 1.)
     289            /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
     290            return copysign(0., z.imag);
     291        else
     292            /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
     293            return copysign(Py_MATH_PI, z.imag);
     294    }
     295    return atan2(z.imag, z.real);
    295296}
    296297
     
    306307c_atanh(Py_complex z)
    307308{
    308         Py_complex r;
    309         double ay, h;
    310 
    311         SPECIAL_VALUE(z, atanh_special_values);
    312 
    313         /* Reduce to case where z.real >= 0., using atanh(z) = -atanh(-z). */
    314         if (z.real < 0.) {
    315                 return c_neg(c_atanh(c_neg(z)));
    316         }
    317 
    318         ay = fabs(z.imag);
    319         if (z.real > CM_SQRT_LARGE_DOUBLE || ay > CM_SQRT_LARGE_DOUBLE) {
    320                 /*
    321                    if abs(z) is large then we use the approximation
    322                    atanh(z) ~ 1/z +/- i*pi/2 (+/- depending on the sign
    323                    of z.imag)
    324                 */
    325                 h = hypot(z.real/2., z.imag/2.);  /* safe from overflow */
    326                 r.real = z.real/4./h/h;
    327                 /* the two negations in the next line cancel each other out
    328                    except when working with unsigned zeros: they're there to
    329                    ensure that the branch cut has the correct continuity on
    330                    systems that don't support signed zeros */
    331                 r.imag = -copysign(Py_MATH_PI/2., -z.imag);
    332                 errno = 0;
    333         } else if (z.real == 1. && ay < CM_SQRT_DBL_MIN) {
    334                 /* C99 standard says:  atanh(1+/-0.) should be inf +/- 0i */
    335                 if (ay == 0.) {
    336                         r.real = INF;
    337                         r.imag = z.imag;
    338                         errno = EDOM;
    339                 } else {
    340                         r.real = -log(sqrt(ay)/sqrt(hypot(ay, 2.)));
    341                         r.imag = copysign(atan2(2., -ay)/2, z.imag);
    342                         errno = 0;
    343                 }
    344         } else {
    345                 r.real = log1p(4.*z.real/((1-z.real)*(1-z.real) + ay*ay))/4.;
    346                 r.imag = -atan2(-2.*z.imag, (1-z.real)*(1+z.real) - ay*ay)/2.;
    347                 errno = 0;
    348         }
    349         return r;
     309    Py_complex r;
     310    double ay, h;
     311
     312    SPECIAL_VALUE(z, atanh_special_values);
     313
     314    /* Reduce to case where z.real >= 0., using atanh(z) = -atanh(-z). */
     315    if (z.real < 0.) {
     316        return c_neg(c_atanh(c_neg(z)));
     317    }
     318
     319    ay = fabs(z.imag);
     320    if (z.real > CM_SQRT_LARGE_DOUBLE || ay > CM_SQRT_LARGE_DOUBLE) {
     321        /*
     322           if abs(z) is large then we use the approximation
     323           atanh(z) ~ 1/z +/- i*pi/2 (+/- depending on the sign
     324           of z.imag)
     325        */
     326        h = hypot(z.real/2., z.imag/2.);  /* safe from overflow */
     327        r.real = z.real/4./h/h;
     328        /* the two negations in the next line cancel each other out
     329           except when working with unsigned zeros: they're there to
     330           ensure that the branch cut has the correct continuity on
     331           systems that don't support signed zeros */
     332        r.imag = -copysign(Py_MATH_PI/2., -z.imag);
     333        errno = 0;
     334    } else if (z.real == 1. && ay < CM_SQRT_DBL_MIN) {
     335        /* C99 standard says:  atanh(1+/-0.) should be inf +/- 0i */
     336        if (ay == 0.) {
     337            r.real = INF;
     338            r.imag = z.imag;
     339            errno = EDOM;
     340        } else {
     341            r.real = -log(sqrt(ay)/sqrt(hypot(ay, 2.)));
     342            r.imag = copysign(atan2(2., -ay)/2, z.imag);
     343            errno = 0;
     344        }
     345    } else {
     346        r.real = m_log1p(4.*z.real/((1-z.real)*(1-z.real) + ay*ay))/4.;
     347        r.imag = -atan2(-2.*z.imag, (1-z.real)*(1+z.real) - ay*ay)/2.;
     348        errno = 0;
     349    }
     350    return r;
    350351}
    351352
     
    359360c_cos(Py_complex z)
    360361{
    361         /* cos(z) = cosh(iz) */
    362         Py_complex r;
    363         r.real = -z.imag;
    364         r.imag = z.real;
    365         r = c_cosh(r);
    366         return r;
     362    /* cos(z) = cosh(iz) */
     363    Py_complex r;
     364    r.real = -z.imag;
     365    r.imag = z.real;
     366    r = c_cosh(r);
     367    return r;
    367368}
    368369
     
    379380c_cosh(Py_complex z)
    380381{
    381         Py_complex r;
    382         double x_minus_one;
    383 
    384         /* special treatment for cosh(+/-inf + iy) if y is not a NaN */
    385         if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
    386                 if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) &&
    387                     (z.imag != 0.)) {
    388                         if (z.real > 0) {
    389                                 r.real = copysign(INF, cos(z.imag));
    390                                 r.imag = copysign(INF, sin(z.imag));
    391                         }
    392                         else {
    393                                 r.real = copysign(INF, cos(z.imag));
    394                                 r.imag = -copysign(INF, sin(z.imag));
    395                         }
    396                 }
    397                 else {
    398                         r = cosh_special_values[special_type(z.real)]
    399                                                [special_type(z.imag)];
    400                 }
    401                 /* need to set errno = EDOM if y is +/- infinity and x is not
    402                    a NaN */
    403                 if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real))
    404                         errno = EDOM;
    405                 else
    406                         errno = 0;
    407                 return r;
    408         }
    409 
    410         if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
    411                 /* deal correctly with cases where cosh(z.real) overflows but
    412                    cosh(z) does not. */
    413                 x_minus_one = z.real - copysign(1., z.real);
    414                 r.real = cos(z.imag) * cosh(x_minus_one) * Py_MATH_E;
    415                 r.imag = sin(z.imag) * sinh(x_minus_one) * Py_MATH_E;
    416         } else {
    417                 r.real = cos(z.imag) * cosh(z.real);
    418                 r.imag = sin(z.imag) * sinh(z.real);
    419         }
    420         /* detect overflow, and set errno accordingly */
    421         if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
    422                 errno = ERANGE;
    423         else
    424                 errno = 0;
    425         return r;
     382    Py_complex r;
     383    double x_minus_one;
     384
     385    /* special treatment for cosh(+/-inf + iy) if y is not a NaN */
     386    if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
     387        if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag) &&
     388            (z.imag != 0.)) {
     389            if (z.real > 0) {
     390                r.real = copysign(INF, cos(z.imag));
     391                r.imag = copysign(INF, sin(z.imag));
     392            }
     393            else {
     394                r.real = copysign(INF, cos(z.imag));
     395                r.imag = -copysign(INF, sin(z.imag));
     396            }
     397        }
     398        else {
     399            r = cosh_special_values[special_type(z.real)]
     400                                   [special_type(z.imag)];
     401        }
     402        /* need to set errno = EDOM if y is +/- infinity and x is not
     403           a NaN */
     404        if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real))
     405            errno = EDOM;
     406        else
     407            errno = 0;
     408        return r;
     409    }
     410
     411    if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
     412        /* deal correctly with cases where cosh(z.real) overflows but
     413           cosh(z) does not. */
     414        x_minus_one = z.real - copysign(1., z.real);
     415        r.real = cos(z.imag) * cosh(x_minus_one) * Py_MATH_E;
     416        r.imag = sin(z.imag) * sinh(x_minus_one) * Py_MATH_E;
     417    } else {
     418        r.real = cos(z.imag) * cosh(z.real);
     419        r.imag = sin(z.imag) * sinh(z.real);
     420    }
     421    /* detect overflow, and set errno accordingly */
     422    if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
     423        errno = ERANGE;
     424    else
     425        errno = 0;
     426    return r;
    426427}
    427428
     
    439440c_exp(Py_complex z)
    440441{
    441         Py_complex r;
    442         double l;
    443 
    444         if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
    445                 if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
    446                     && (z.imag != 0.)) {
    447                         if (z.real > 0) {
    448                                 r.real = copysign(INF, cos(z.imag));
    449                                 r.imag = copysign(INF, sin(z.imag));
    450                         }
    451                         else {
    452                                 r.real = copysign(0., cos(z.imag));
    453                                 r.imag = copysign(0., sin(z.imag));
    454                         }
    455                 }
    456                 else {
    457                         r = exp_special_values[special_type(z.real)]
    458                                               [special_type(z.imag)];
    459                 }
    460                 /* need to set errno = EDOM if y is +/- infinity and x is not
    461                    a NaN and not -infinity */
    462                 if (Py_IS_INFINITY(z.imag) &&
    463                     (Py_IS_FINITE(z.real) ||
    464                      (Py_IS_INFINITY(z.real) && z.real > 0)))
    465                         errno = EDOM;
    466                 else
    467                         errno = 0;
    468                 return r;
    469         }
    470 
    471         if (z.real > CM_LOG_LARGE_DOUBLE) {
    472                 l = exp(z.real-1.);
    473                 r.real = l*cos(z.imag)*Py_MATH_E;
    474                 r.imag = l*sin(z.imag)*Py_MATH_E;
    475         } else {
    476                 l = exp(z.real);
    477                 r.real = l*cos(z.imag);
    478                 r.imag = l*sin(z.imag);
    479         }
    480         /* detect overflow, and set errno accordingly */
    481         if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
    482                 errno = ERANGE;
    483         else
    484                 errno = 0;
    485         return r;
     442    Py_complex r;
     443    double l;
     444
     445    if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
     446        if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
     447            && (z.imag != 0.)) {
     448            if (z.real > 0) {
     449                r.real = copysign(INF, cos(z.imag));
     450                r.imag = copysign(INF, sin(z.imag));
     451            }
     452            else {
     453                r.real = copysign(0., cos(z.imag));
     454                r.imag = copysign(0., sin(z.imag));
     455            }
     456        }
     457        else {
     458            r = exp_special_values[special_type(z.real)]
     459                                  [special_type(z.imag)];
     460        }
     461        /* need to set errno = EDOM if y is +/- infinity and x is not
     462           a NaN and not -infinity */
     463        if (Py_IS_INFINITY(z.imag) &&
     464            (Py_IS_FINITE(z.real) ||
     465             (Py_IS_INFINITY(z.real) && z.real > 0)))
     466            errno = EDOM;
     467        else
     468            errno = 0;
     469        return r;
     470    }
     471
     472    if (z.real > CM_LOG_LARGE_DOUBLE) {
     473        l = exp(z.real-1.);
     474        r.real = l*cos(z.imag)*Py_MATH_E;
     475        r.imag = l*sin(z.imag)*Py_MATH_E;
     476    } else {
     477        l = exp(z.real);
     478        r.real = l*cos(z.imag);
     479        r.imag = l*sin(z.imag);
     480    }
     481    /* detect overflow, and set errno accordingly */
     482    if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
     483        errno = ERANGE;
     484    else
     485        errno = 0;
     486    return r;
    486487}
    487488
     
    497498c_log(Py_complex z)
    498499{
    499         /*
    500            The usual formula for the real part is log(hypot(z.real, z.imag)).
    501            There are four situations where this formula is potentially
    502            problematic:
    503 
    504            (1) the absolute value of z is subnormal.  Then hypot is subnormal,
    505            so has fewer than the usual number of bits of accuracy, hence may
    506            have large relative error.  This then gives a large absolute error
    507            in the log.  This can be solved by rescaling z by a suitable power
    508            of 2.
    509 
    510            (2) the absolute value of z is greater than DBL_MAX (e.g. when both
    511            z.real and z.imag are within a factor of 1/sqrt(2) of DBL_MAX)
    512            Again, rescaling solves this.
    513 
    514            (3) the absolute value of z is close to 1.  In this case it's
    515            difficult to achieve good accuracy, at least in part because a
    516            change of 1ulp in the real or imaginary part of z can result in a
    517            change of billions of ulps in the correctly rounded answer.
    518 
    519            (4) z = 0.  The simplest thing to do here is to call the
    520            floating-point log with an argument of 0, and let its behaviour
    521            (returning -infinity, signaling a floating-point exception, setting
    522            errno, or whatever) determine that of c_log.  So the usual formula
    523            is fine here.
    524 
    525         */
    526 
    527         Py_complex r;
    528         double ax, ay, am, an, h;
    529 
    530         SPECIAL_VALUE(z, log_special_values);
    531 
    532         ax = fabs(z.real);
    533         ay = fabs(z.imag);
    534 
    535         if (ax > CM_LARGE_DOUBLE || ay > CM_LARGE_DOUBLE) {
    536                 r.real = log(hypot(ax/2., ay/2.)) + M_LN2;
    537         } else if (ax < DBL_MIN && ay < DBL_MIN) {
    538                 if (ax > 0. || ay > 0.) {
    539                         /* catch cases where hypot(ax, ay) is subnormal */
    540                         r.real = log(hypot(ldexp(ax, DBL_MANT_DIG),
    541                                 ldexp(ay, DBL_MANT_DIG))) - DBL_MANT_DIG*M_LN2;
    542                 }
    543                 else {
    544                         /* log(+/-0. +/- 0i) */
    545                         r.real = -INF;
    546                         r.imag = atan2(z.imag, z.real);
    547                         errno = EDOM;
    548                         return r;
    549                 }
    550         } else {
    551                 h = hypot(ax, ay);
    552                 if (0.71 <= h && h <= 1.73) {
    553                         am = ax > ay ? ax : ay;  /* max(ax, ay) */
    554                         an = ax > ay ? ay : ax;  /* min(ax, ay) */
    555                         r.real = log1p((am-1)*(am+1)+an*an)/2.;
    556                 } else {
    557                         r.real = log(h);
    558                 }
    559         }
    560         r.imag = atan2(z.imag, z.real);
    561         errno = 0;
    562         return r;
     500    /*
     501       The usual formula for the real part is log(hypot(z.real, z.imag)).
     502       There are four situations where this formula is potentially
     503       problematic:
     504
     505       (1) the absolute value of z is subnormal.  Then hypot is subnormal,
     506       so has fewer than the usual number of bits of accuracy, hence may
     507       have large relative error.  This then gives a large absolute error
     508       in the log.  This can be solved by rescaling z by a suitable power
     509       of 2.
     510
     511       (2) the absolute value of z is greater than DBL_MAX (e.g. when both
     512       z.real and z.imag are within a factor of 1/sqrt(2) of DBL_MAX)
     513       Again, rescaling solves this.
     514
     515       (3) the absolute value of z is close to 1.  In this case it's
     516       difficult to achieve good accuracy, at least in part because a
     517       change of 1ulp in the real or imaginary part of z can result in a
     518       change of billions of ulps in the correctly rounded answer.
     519
     520       (4) z = 0.  The simplest thing to do here is to call the
     521       floating-point log with an argument of 0, and let its behaviour
     522       (returning -infinity, signaling a floating-point exception, setting
     523       errno, or whatever) determine that of c_log.  So the usual formula
     524       is fine here.
     525
     526    */
     527
     528    Py_complex r;
     529    double ax, ay, am, an, h;
     530
     531    SPECIAL_VALUE(z, log_special_values);
     532
     533    ax = fabs(z.real);
     534    ay = fabs(z.imag);
     535
     536    if (ax > CM_LARGE_DOUBLE || ay > CM_LARGE_DOUBLE) {
     537        r.real = log(hypot(ax/2., ay/2.)) + M_LN2;
     538    } else if (ax < DBL_MIN && ay < DBL_MIN) {
     539        if (ax > 0. || ay > 0.) {
     540            /* catch cases where hypot(ax, ay) is subnormal */
     541            r.real = log(hypot(ldexp(ax, DBL_MANT_DIG),
     542                    ldexp(ay, DBL_MANT_DIG))) - DBL_MANT_DIG*M_LN2;
     543        }
     544        else {
     545            /* log(+/-0. +/- 0i) */
     546            r.real = -INF;
     547            r.imag = atan2(z.imag, z.real);
     548            errno = EDOM;
     549            return r;
     550        }
     551    } else {
     552        h = hypot(ax, ay);
     553        if (0.71 <= h && h <= 1.73) {
     554            am = ax > ay ? ax : ay;  /* max(ax, ay) */
     555            an = ax > ay ? ay : ax;  /* min(ax, ay) */
     556            r.real = m_log1p((am-1)*(am+1)+an*an)/2.;
     557        } else {
     558            r.real = log(h);
     559        }
     560    }
     561    r.imag = atan2(z.imag, z.real);
     562    errno = 0;
     563    return r;
    563564}
    564565
     
    567568c_log10(Py_complex z)
    568569{
    569         Py_complex r;
    570         int errno_save;
    571 
    572         r = c_log(z);
    573         errno_save = errno; /* just in case the divisions affect errno */
    574         r.real = r.real / M_LN10;
    575         r.imag = r.imag / M_LN10;
    576         errno = errno_save;
    577         return r;
     570    Py_complex r;
     571    int errno_save;
     572
     573    r = c_log(z);
     574    errno_save = errno; /* just in case the divisions affect errno */
     575    r.real = r.real / M_LN10;
     576    r.imag = r.imag / M_LN10;
     577    errno = errno_save;
     578    return r;
    578579}
    579580
     
    587588c_sin(Py_complex z)
    588589{
    589         /* sin(z) = -i sin(iz) */
    590         Py_complex s, r;
    591         s.real = -z.imag;
    592         s.imag = z.real;
    593         s = c_sinh(s);
    594         r.real = s.imag;
    595         r.imag = -s.real;
    596         return r;
     590    /* sin(z) = -i sin(iz) */
     591    Py_complex s, r;
     592    s.real = -z.imag;
     593    s.imag = z.real;
     594    s = c_sinh(s);
     595    r.real = s.imag;
     596    r.imag = -s.real;
     597    return r;
    597598}
    598599
     
    609610c_sinh(Py_complex z)
    610611{
    611         Py_complex r;
    612         double x_minus_one;
    613 
    614         /* special treatment for sinh(+/-inf + iy) if y is finite and
    615            nonzero */
    616         if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
    617                 if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
    618                     && (z.imag != 0.)) {
    619                         if (z.real > 0) {
    620                                 r.real = copysign(INF, cos(z.imag));
    621                                 r.imag = copysign(INF, sin(z.imag));
    622                         }
    623                         else {
    624                                 r.real = -copysign(INF, cos(z.imag));
    625                                 r.imag = copysign(INF, sin(z.imag));
    626                         }
    627                 }
    628                 else {
    629                         r = sinh_special_values[special_type(z.real)]
    630                                                [special_type(z.imag)];
    631                 }
    632                 /* need to set errno = EDOM if y is +/- infinity and x is not
    633                    a NaN */
    634                 if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real))
    635                         errno = EDOM;
    636                 else
    637                         errno = 0;
    638                 return r;
    639         }
    640 
    641         if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
    642                 x_minus_one = z.real - copysign(1., z.real);
    643                 r.real = cos(z.imag) * sinh(x_minus_one) * Py_MATH_E;
    644                 r.imag = sin(z.imag) * cosh(x_minus_one) * Py_MATH_E;
    645         } else {
    646                 r.real = cos(z.imag) * sinh(z.real);
    647                 r.imag = sin(z.imag) * cosh(z.real);
    648         }
    649         /* detect overflow, and set errno accordingly */
    650         if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
    651                 errno = ERANGE;
    652         else
    653                 errno = 0;
    654         return r;
     612    Py_complex r;
     613    double x_minus_one;
     614
     615    /* special treatment for sinh(+/-inf + iy) if y is finite and
     616       nonzero */
     617    if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
     618        if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
     619            && (z.imag != 0.)) {
     620            if (z.real > 0) {
     621                r.real = copysign(INF, cos(z.imag));
     622                r.imag = copysign(INF, sin(z.imag));
     623            }
     624            else {
     625                r.real = -copysign(INF, cos(z.imag));
     626                r.imag = copysign(INF, sin(z.imag));
     627            }
     628        }
     629        else {
     630            r = sinh_special_values[special_type(z.real)]
     631                                   [special_type(z.imag)];
     632        }
     633        /* need to set errno = EDOM if y is +/- infinity and x is not
     634           a NaN */
     635        if (Py_IS_INFINITY(z.imag) && !Py_IS_NAN(z.real))
     636            errno = EDOM;
     637        else
     638            errno = 0;
     639        return r;
     640    }
     641
     642    if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
     643        x_minus_one = z.real - copysign(1., z.real);
     644        r.real = cos(z.imag) * sinh(x_minus_one) * Py_MATH_E;
     645        r.imag = sin(z.imag) * cosh(x_minus_one) * Py_MATH_E;
     646    } else {
     647        r.real = cos(z.imag) * sinh(z.real);
     648        r.imag = sin(z.imag) * cosh(z.real);
     649    }
     650    /* detect overflow, and set errno accordingly */
     651    if (Py_IS_INFINITY(r.real) || Py_IS_INFINITY(r.imag))
     652        errno = ERANGE;
     653    else
     654        errno = 0;
     655    return r;
    655656}
    656657
     
    666667c_sqrt(Py_complex z)
    667668{
    668         /*
    669            Method: use symmetries to reduce to the case when x = z.real and y
    670            = z.imag are nonnegative.  Then the real part of the result is
    671            given by
    672 
    673              s = sqrt((x + hypot(x, y))/2)
    674 
    675            and the imaginary part is
    676 
    677              d = (y/2)/s
    678 
    679            If either x or y is very large then there's a risk of overflow in
    680            computation of the expression x + hypot(x, y).  We can avoid this
    681            by rewriting the formula for s as:
    682 
    683              s = 2*sqrt(x/8 + hypot(x/8, y/8))
    684 
    685            This costs us two extra multiplications/divisions, but avoids the
    686            overhead of checking for x and y large.
    687 
    688            If both x and y are subnormal then hypot(x, y) may also be
    689            subnormal, so will lack full precision.  We solve this by rescaling
    690            x and y by a sufficiently large power of 2 to ensure that x and y
    691            are normal.
    692         */
    693 
    694 
    695         Py_complex r;
    696         double s,d;
    697         double ax, ay;
    698 
    699         SPECIAL_VALUE(z, sqrt_special_values);
    700 
    701         if (z.real == 0. && z.imag == 0.) {
    702                 r.real = 0.;
    703                 r.imag = z.imag;
    704                 return r;
    705         }
    706 
    707         ax = fabs(z.real);
    708         ay = fabs(z.imag);
    709 
    710         if (ax < DBL_MIN && ay < DBL_MIN && (ax > 0. || ay > 0.)) {
    711                 /* here we catch cases where hypot(ax, ay) is subnormal */
    712                 ax = ldexp(ax, CM_SCALE_UP);
    713                 s = ldexp(sqrt(ax + hypot(ax, ldexp(ay, CM_SCALE_UP))),
    714                           CM_SCALE_DOWN);
    715         } else {
    716                 ax /= 8.;
    717                 s = 2.*sqrt(ax + hypot(ax, ay/8.));
    718         }
    719         d = ay/(2.*s);
    720 
    721         if (z.real >= 0.) {
    722                 r.real = s;
    723                 r.imag = copysign(d, z.imag);
    724         } else {
    725                 r.real = d;
    726                 r.imag = copysign(s, z.imag);
    727         }
    728         errno = 0;
    729         return r;
     669    /*
     670       Method: use symmetries to reduce to the case when x = z.real and y
     671       = z.imag are nonnegative.  Then the real part of the result is
     672       given by
     673
     674         s = sqrt((x + hypot(x, y))/2)
     675
     676       and the imaginary part is
     677
     678         d = (y/2)/s
     679
     680       If either x or y is very large then there's a risk of overflow in
     681       computation of the expression x + hypot(x, y).  We can avoid this
     682       by rewriting the formula for s as:
     683
     684         s = 2*sqrt(x/8 + hypot(x/8, y/8))
     685
     686       This costs us two extra multiplications/divisions, but avoids the
     687       overhead of checking for x and y large.
     688
     689       If both x and y are subnormal then hypot(x, y) may also be
     690       subnormal, so will lack full precision.  We solve this by rescaling
     691       x and y by a sufficiently large power of 2 to ensure that x and y
     692       are normal.
     693    */
     694
     695
     696    Py_complex r;
     697    double s,d;
     698    double ax, ay;
     699
     700    SPECIAL_VALUE(z, sqrt_special_values);
     701
     702    if (z.real == 0. && z.imag == 0.) {
     703        r.real = 0.;
     704        r.imag = z.imag;
     705        return r;
     706    }
     707
     708    ax = fabs(z.real);
     709    ay = fabs(z.imag);
     710
     711    if (ax < DBL_MIN && ay < DBL_MIN && (ax > 0. || ay > 0.)) {
     712        /* here we catch cases where hypot(ax, ay) is subnormal */
     713        ax = ldexp(ax, CM_SCALE_UP);
     714        s = ldexp(sqrt(ax + hypot(ax, ldexp(ay, CM_SCALE_UP))),
     715                  CM_SCALE_DOWN);
     716    } else {
     717        ax /= 8.;
     718        s = 2.*sqrt(ax + hypot(ax, ay/8.));
     719    }
     720    d = ay/(2.*s);
     721
     722    if (z.real >= 0.) {
     723        r.real = s;
     724        r.imag = copysign(d, z.imag);
     725    } else {
     726        r.real = d;
     727        r.imag = copysign(s, z.imag);
     728    }
     729    errno = 0;
     730    return r;
    730731}
    731732
     
    739740c_tan(Py_complex z)
    740741{
    741         /* tan(z) = -i tanh(iz) */
    742         Py_complex s, r;
    743         s.real = -z.imag;
    744         s.imag = z.real;
    745         s = c_tanh(s);
    746         r.real = s.imag;
    747         r.imag = -s.real;
    748         return r;
     742    /* tan(z) = -i tanh(iz) */
     743    Py_complex s, r;
     744    s.real = -z.imag;
     745    s.imag = z.real;
     746    s = c_tanh(s);
     747    r.real = s.imag;
     748    r.imag = -s.real;
     749    return r;
    749750}
    750751
     
    761762c_tanh(Py_complex z)
    762763{
    763         /* Formula:
    764 
    765            tanh(x+iy) = (tanh(x)(1+tan(y)^2) + i tan(y)(1-tanh(x))^2) /
    766            (1+tan(y)^2 tanh(x)^2)
    767 
    768            To avoid excessive roundoff error, 1-tanh(x)^2 is better computed
    769            as 1/cosh(x)^2.  When abs(x) is large, we approximate 1-tanh(x)^2
    770            by 4 exp(-2*x) instead, to avoid possible overflow in the
    771            computation of cosh(x).
    772 
    773         */
    774 
    775         Py_complex r;
    776         double tx, ty, cx, txty, denom;
    777 
    778         /* special treatment for tanh(+/-inf + iy) if y is finite and
    779            nonzero */
    780         if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
    781                 if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
    782                     && (z.imag != 0.)) {
    783                         if (z.real > 0) {
    784                                 r.real = 1.0;
    785                                 r.imag = copysign(0.,
    786                                                   2.*sin(z.imag)*cos(z.imag));
    787                         }
    788                         else {
    789                                 r.real = -1.0;
    790                                 r.imag = copysign(0.,
    791                                                   2.*sin(z.imag)*cos(z.imag));
    792                         }
    793                 }
    794                 else {
    795                         r = tanh_special_values[special_type(z.real)]
    796                                                [special_type(z.imag)];
    797                 }
    798                 /* need to set errno = EDOM if z.imag is +/-infinity and
    799                    z.real is finite */
    800                 if (Py_IS_INFINITY(z.imag) && Py_IS_FINITE(z.real))
    801                         errno = EDOM;
    802                 else
    803                         errno = 0;
    804                 return r;
    805         }
    806 
    807         /* danger of overflow in 2.*z.imag !*/
    808         if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
    809                 r.real = copysign(1., z.real);
    810                 r.imag = 4.*sin(z.imag)*cos(z.imag)*exp(-2.*fabs(z.real));
    811         } else {
    812                 tx = tanh(z.real);
    813                 ty = tan(z.imag);
    814                 cx = 1./cosh(z.real);
    815                 txty = tx*ty;
    816                 denom = 1. + txty*txty;
    817                 r.real = tx*(1.+ty*ty)/denom;
    818                 r.imag = ((ty/denom)*cx)*cx;
    819         }
    820         errno = 0;
    821         return r;
     764    /* Formula:
     765
     766       tanh(x+iy) = (tanh(x)(1+tan(y)^2) + i tan(y)(1-tanh(x))^2) /
     767       (1+tan(y)^2 tanh(x)^2)
     768
     769       To avoid excessive roundoff error, 1-tanh(x)^2 is better computed
     770       as 1/cosh(x)^2.  When abs(x) is large, we approximate 1-tanh(x)^2
     771       by 4 exp(-2*x) instead, to avoid possible overflow in the
     772       computation of cosh(x).
     773
     774    */
     775
     776    Py_complex r;
     777    double tx, ty, cx, txty, denom;
     778
     779    /* special treatment for tanh(+/-inf + iy) if y is finite and
     780       nonzero */
     781    if (!Py_IS_FINITE(z.real) || !Py_IS_FINITE(z.imag)) {
     782        if (Py_IS_INFINITY(z.real) && Py_IS_FINITE(z.imag)
     783            && (z.imag != 0.)) {
     784            if (z.real > 0) {
     785                r.real = 1.0;
     786                r.imag = copysign(0.,
     787                                  2.*sin(z.imag)*cos(z.imag));
     788            }
     789            else {
     790                r.real = -1.0;
     791                r.imag = copysign(0.,
     792                                  2.*sin(z.imag)*cos(z.imag));
     793            }
     794        }
     795        else {
     796            r = tanh_special_values[special_type(z.real)]
     797                                   [special_type(z.imag)];
     798        }
     799        /* need to set errno = EDOM if z.imag is +/-infinity and
     800           z.real is finite */
     801        if (Py_IS_INFINITY(z.imag) && Py_IS_FINITE(z.real))
     802            errno = EDOM;
     803        else
     804            errno = 0;
     805        return r;
     806    }
     807
     808    /* danger of overflow in 2.*z.imag !*/
     809    if (fabs(z.real) > CM_LOG_LARGE_DOUBLE) {
     810        r.real = copysign(1., z.real);
     811        r.imag = 4.*sin(z.imag)*cos(z.imag)*exp(-2.*fabs(z.real));
     812    } else {
     813        tx = tanh(z.real);
     814        ty = tan(z.imag);
     815        cx = 1./cosh(z.real);
     816        txty = tx*ty;
     817        denom = 1. + txty*txty;
     818        r.real = tx*(1.+ty*ty)/denom;
     819        r.imag = ((ty/denom)*cx)*cx;
     820    }
     821    errno = 0;
     822    return r;
    822823}
    823824
     
    831832cmath_log(PyObject *self, PyObject *args)
    832833{
    833         Py_complex x;
    834         Py_complex y;
    835 
    836         if (!PyArg_ParseTuple(args, "D|D", &x, &y))
    837                 return NULL;
    838 
    839         errno = 0;
    840         PyFPE_START_PROTECT("complex function", return 0)
    841         x = c_log(x);
    842         if (PyTuple_GET_SIZE(args) == 2) {
    843                 y = c_log(y);
    844                 x = c_quot(x, y);
    845         }
    846         PyFPE_END_PROTECT(x)
    847         if (errno != 0)
    848                 return math_error();
    849         return PyComplex_FromCComplex(x);
     834    Py_complex x;
     835    Py_complex y;
     836
     837    if (!PyArg_ParseTuple(args, "D|D", &x, &y))
     838        return NULL;
     839
     840    errno = 0;
     841    PyFPE_START_PROTECT("complex function", return 0)
     842    x = c_log(x);
     843    if (PyTuple_GET_SIZE(args) == 2) {
     844        y = c_log(y);
     845        x = c_quot(x, y);
     846    }
     847    PyFPE_END_PROTECT(x)
     848    if (errno != 0)
     849        return math_error();
     850    return PyComplex_FromCComplex(x);
    850851}
    851852
     
    860861math_error(void)
    861862{
    862         if (errno == EDOM)
    863                 PyErr_SetString(PyExc_ValueError, "math domain error");
    864         else if (errno == ERANGE)
    865                 PyErr_SetString(PyExc_OverflowError, "math range error");
    866         else    /* Unexpected math error */
    867                 PyErr_SetFromErrno(PyExc_ValueError);
    868         return NULL;
     863    if (errno == EDOM)
     864        PyErr_SetString(PyExc_ValueError, "math domain error");
     865    else if (errno == ERANGE)
     866        PyErr_SetString(PyExc_OverflowError, "math range error");
     867    else    /* Unexpected math error */
     868        PyErr_SetFromErrno(PyExc_ValueError);
     869    return NULL;
    869870}
    870871
     
    872873math_1(PyObject *args, Py_complex (*func)(Py_complex))
    873874{
    874         Py_complex x,r ;
    875         if (!PyArg_ParseTuple(args, "D", &x))
    876                 return NULL;
    877         errno = 0;
    878         PyFPE_START_PROTECT("complex function", return 0);
    879         r = (*func)(x);
    880         PyFPE_END_PROTECT(r);
    881         if (errno == EDOM) {
    882                 PyErr_SetString(PyExc_ValueError, "math domain error");
    883                 return NULL;
    884         }
    885         else if (errno == ERANGE) {
    886                 PyErr_SetString(PyExc_OverflowError, "math range error");
    887                 return NULL;
    888         }
    889         else {
    890                 return PyComplex_FromCComplex(r);
    891         }
     875    Py_complex x,r ;
     876    if (!PyArg_ParseTuple(args, "D", &x))
     877        return NULL;
     878    errno = 0;
     879    PyFPE_START_PROTECT("complex function", return 0);
     880    r = (*func)(x);
     881    PyFPE_END_PROTECT(r);
     882    if (errno == EDOM) {
     883        PyErr_SetString(PyExc_ValueError, "math domain error");
     884        return NULL;
     885    }
     886    else if (errno == ERANGE) {
     887        PyErr_SetString(PyExc_OverflowError, "math range error");
     888        return NULL;
     889    }
     890    else {
     891        return PyComplex_FromCComplex(r);
     892    }
    892893}
    893894
    894895#define FUNC1(stubname, func) \
    895         static PyObject * stubname(PyObject *self, PyObject *args) { \
    896                 return math_1(args, func); \
    897         }
     896    static PyObject * stubname(PyObject *self, PyObject *args) { \
     897        return math_1(args, func); \
     898    }
    898899
    899900FUNC1(cmath_acos, c_acos)
     
    916917cmath_phase(PyObject *self, PyObject *args)
    917918{
    918         Py_complex z;
    919         double phi;
    920         if (!PyArg_ParseTuple(args, "D:phase", &z))
    921                 return NULL;
    922         errno = 0;
    923         PyFPE_START_PROTECT("arg function", return 0)
    924         phi = c_atan2(z);
    925         PyFPE_END_PROTECT(phi)
    926         if (errno != 0)
    927                 return math_error();
    928         else
    929                 return PyFloat_FromDouble(phi);
     919    Py_complex z;
     920    double phi;
     921    if (!PyArg_ParseTuple(args, "D:phase", &z))
     922        return NULL;
     923    errno = 0;
     924    PyFPE_START_PROTECT("arg function", return 0)
     925    phi = c_atan2(z);
     926    PyFPE_END_PROTECT(phi)
     927    if (errno != 0)
     928        return math_error();
     929    else
     930        return PyFloat_FromDouble(phi);
    930931}
    931932
     
    937938cmath_polar(PyObject *self, PyObject *args)
    938939{
    939         Py_complex z;
    940         double r, phi;
    941         if (!PyArg_ParseTuple(args, "D:polar", &z))
    942                 return NULL;
    943         PyFPE_START_PROTECT("polar function", return 0)
    944         phi = c_atan2(z); /* should not cause any exception */
    945         r = c_abs(z); /* sets errno to ERANGE on overflow;  otherwise 0 */
    946         PyFPE_END_PROTECT(r)
    947         if (errno != 0)
    948                 return math_error();
    949         else
    950                 return Py_BuildValue("dd", r, phi);
     940    Py_complex z;
     941    double r, phi;
     942    if (!PyArg_ParseTuple(args, "D:polar", &z))
     943        return NULL;
     944    PyFPE_START_PROTECT("polar function", return 0)
     945    phi = c_atan2(z); /* should not cause any exception */
     946    r = c_abs(z); /* sets errno to ERANGE on overflow;  otherwise 0 */
     947    PyFPE_END_PROTECT(r)
     948    if (errno != 0)
     949        return math_error();
     950    else
     951        return Py_BuildValue("dd", r, phi);
    951952}
    952953
     
    972973cmath_rect(PyObject *self, PyObject *args)
    973974{
    974         Py_complex z;
    975         double r, phi;
    976         if (!PyArg_ParseTuple(args, "dd:rect", &r, &phi))
    977                 return NULL;
    978         errno = 0;
    979         PyFPE_START_PROTECT("rect function", return 0)
    980 
    981         /* deal with special values */
    982         if (!Py_IS_FINITE(r) || !Py_IS_FINITE(phi)) {
    983                 /* if r is +/-infinity and phi is finite but nonzero then
    984                    result is (+-INF +-INF i), but we need to compute cos(phi)
    985                    and sin(phi) to figure out the signs. */
    986                 if (Py_IS_INFINITY(r) && (Py_IS_FINITE(phi)
    987                                           && (phi != 0.))) {
    988                         if (r > 0) {
    989                                 z.real = copysign(INF, cos(phi));
    990                                 z.imag = copysign(INF, sin(phi));
    991                         }
    992                         else {
    993                                 z.real = -copysign(INF, cos(phi));
    994                                 z.imag = -copysign(INF, sin(phi));
    995                         }
    996                 }
    997                 else {
    998                         z = rect_special_values[special_type(r)]
    999                                                [special_type(phi)];
    1000                 }
    1001                 /* need to set errno = EDOM if r is a nonzero number and phi
    1002                    is infinite */
    1003                 if (r != 0. && !Py_IS_NAN(r) && Py_IS_INFINITY(phi))
    1004                         errno = EDOM;
    1005                 else
    1006                         errno = 0;
    1007         }
    1008         else {
    1009                 z.real = r * cos(phi);
    1010                 z.imag = r * sin(phi);
    1011                 errno = 0;
    1012         }
    1013 
    1014         PyFPE_END_PROTECT(z)
    1015         if (errno != 0)
    1016                 return math_error();
    1017         else
    1018                 return PyComplex_FromCComplex(z);
     975    Py_complex z;
     976    double r, phi;
     977    if (!PyArg_ParseTuple(args, "dd:rect", &r, &phi))
     978        return NULL;
     979    errno = 0;
     980    PyFPE_START_PROTECT("rect function", return 0)
     981
     982    /* deal with special values */
     983    if (!Py_IS_FINITE(r) || !Py_IS_FINITE(phi)) {
     984        /* if r is +/-infinity and phi is finite but nonzero then
     985           result is (+-INF +-INF i), but we need to compute cos(phi)
     986           and sin(phi) to figure out the signs. */
     987        if (Py_IS_INFINITY(r) && (Py_IS_FINITE(phi)
     988                                  && (phi != 0.))) {
     989            if (r > 0) {
     990                z.real = copysign(INF, cos(phi));
     991                z.imag = copysign(INF, sin(phi));
     992            }
     993            else {
     994                z.real = -copysign(INF, cos(phi));
     995                z.imag = -copysign(INF, sin(phi));
     996            }
     997        }
     998        else {
     999            z = rect_special_values[special_type(r)]
     1000                                   [special_type(phi)];
     1001        }
     1002        /* need to set errno = EDOM if r is a nonzero number and phi
     1003           is infinite */
     1004        if (r != 0. && !Py_IS_NAN(r) && Py_IS_INFINITY(phi))
     1005            errno = EDOM;
     1006        else
     1007            errno = 0;
     1008    }
     1009    else if (phi == 0.0) {
     1010        /* Workaround for buggy results with phi=-0.0 on OS X 10.8.  See
     1011           bugs.python.org/issue18513. */
     1012        z.real = r;
     1013        z.imag = r * phi;
     1014        errno = 0;
     1015    }
     1016    else {
     1017        z.real = r * cos(phi);
     1018        z.imag = r * sin(phi);
     1019        errno = 0;
     1020    }
     1021
     1022    PyFPE_END_PROTECT(z)
     1023    if (errno != 0)
     1024        return math_error();
     1025    else
     1026        return PyComplex_FromCComplex(z);
    10191027}
    10201028
     
    10261034cmath_isnan(PyObject *self, PyObject *args)
    10271035{
    1028         Py_complex z;
    1029         if (!PyArg_ParseTuple(args, "D:isnan", &z))
    1030                 return NULL;
    1031         return PyBool_FromLong(Py_IS_NAN(z.real) || Py_IS_NAN(z.imag));
     1036    Py_complex z;
     1037    if (!PyArg_ParseTuple(args, "D:isnan", &z))
     1038        return NULL;
     1039    return PyBool_FromLong(Py_IS_NAN(z.real) || Py_IS_NAN(z.imag));
    10321040}
    10331041
     
    10391047cmath_isinf(PyObject *self, PyObject *args)
    10401048{
    1041         Py_complex z;
    1042         if (!PyArg_ParseTuple(args, "D:isnan", &z))
    1043                 return NULL;
    1044         return PyBool_FromLong(Py_IS_INFINITY(z.real) ||
    1045                                Py_IS_INFINITY(z.imag));
     1049    Py_complex z;
     1050    if (!PyArg_ParseTuple(args, "D:isnan", &z))
     1051        return NULL;
     1052    return PyBool_FromLong(Py_IS_INFINITY(z.real) ||
     1053                           Py_IS_INFINITY(z.imag));
    10461054}
    10471055
     
    10561064
    10571065static PyMethodDef cmath_methods[] = {
    1058         {"acos",   cmath_acos,  METH_VARARGS, c_acos_doc},
    1059         {"acosh",  cmath_acosh, METH_VARARGS, c_acosh_doc},
    1060         {"asin",   cmath_asin,  METH_VARARGS, c_asin_doc},
    1061         {"asinh",  cmath_asinh, METH_VARARGS, c_asinh_doc},
    1062         {"atan",   cmath_atan,  METH_VARARGS, c_atan_doc},
    1063         {"atanh",  cmath_atanh, METH_VARARGS, c_atanh_doc},
    1064         {"cos",    cmath_cos,   METH_VARARGS, c_cos_doc},
    1065         {"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
    1066         {"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
    1067         {"isinf",  cmath_isinf, METH_VARARGS, cmath_isinf_doc},
    1068         {"isnan",  cmath_isnan, METH_VARARGS, cmath_isnan_doc},
    1069         {"log",    cmath_log,   METH_VARARGS, cmath_log_doc},
    1070         {"log10",  cmath_log10, METH_VARARGS, c_log10_doc},
    1071         {"phase",  cmath_phase, METH_VARARGS, cmath_phase_doc},
    1072         {"polar",  cmath_polar, METH_VARARGS, cmath_polar_doc},
    1073         {"rect",   cmath_rect,  METH_VARARGS, cmath_rect_doc},
    1074         {"sin",    cmath_sin,   METH_VARARGS, c_sin_doc},
    1075         {"sinh",   cmath_sinh,  METH_VARARGS, c_sinh_doc},
    1076         {"sqrt",   cmath_sqrt,  METH_VARARGS, c_sqrt_doc},
    1077         {"tan",    cmath_tan,   METH_VARARGS, c_tan_doc},
    1078         {"tanh",   cmath_tanh,  METH_VARARGS, c_tanh_doc},
    1079         {NULL,          NULL}           /* sentinel */
     1066    {"acos",   cmath_acos,  METH_VARARGS, c_acos_doc},
     1067    {"acosh",  cmath_acosh, METH_VARARGS, c_acosh_doc},
     1068    {"asin",   cmath_asin,  METH_VARARGS, c_asin_doc},
     1069    {"asinh",  cmath_asinh, METH_VARARGS, c_asinh_doc},
     1070    {"atan",   cmath_atan,  METH_VARARGS, c_atan_doc},
     1071    {"atanh",  cmath_atanh, METH_VARARGS, c_atanh_doc},
     1072    {"cos",    cmath_cos,   METH_VARARGS, c_cos_doc},
     1073    {"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
     1074    {"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
     1075    {"isinf",  cmath_isinf, METH_VARARGS, cmath_isinf_doc},
     1076    {"isnan",  cmath_isnan, METH_VARARGS, cmath_isnan_doc},
     1077    {"log",    cmath_log,   METH_VARARGS, cmath_log_doc},
     1078    {"log10",  cmath_log10, METH_VARARGS, c_log10_doc},
     1079    {"phase",  cmath_phase, METH_VARARGS, cmath_phase_doc},
     1080    {"polar",  cmath_polar, METH_VARARGS, cmath_polar_doc},
     1081    {"rect",   cmath_rect,  METH_VARARGS, cmath_rect_doc},
     1082    {"sin",    cmath_sin,   METH_VARARGS, c_sin_doc},
     1083    {"sinh",   cmath_sinh,  METH_VARARGS, c_sinh_doc},
     1084    {"sqrt",   cmath_sqrt,  METH_VARARGS, c_sqrt_doc},
     1085    {"tan",    cmath_tan,   METH_VARARGS, c_tan_doc},
     1086    {"tanh",   cmath_tanh,  METH_VARARGS, c_tanh_doc},
     1087    {NULL,              NULL}           /* sentinel */
    10801088};
    10811089
     
    10831091initcmath(void)
    10841092{
    1085         PyObject *m;
    1086 
    1087         m = Py_InitModule3("cmath", cmath_methods, module_doc);
    1088         if (m == NULL)
    1089                 return;
    1090 
    1091         PyModule_AddObject(m, "pi",
    1092                            PyFloat_FromDouble(Py_MATH_PI));
    1093         PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
    1094 
    1095         /* initialize special value tables */
     1093    PyObject *m;
     1094
     1095    m = Py_InitModule3("cmath", cmath_methods, module_doc);
     1096    if (m == NULL)
     1097        return;
     1098
     1099    PyModule_AddObject(m, "pi",
     1100                       PyFloat_FromDouble(Py_MATH_PI));
     1101    PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
     1102
     1103    /* initialize special value tables */
    10961104
    10971105#define INIT_SPECIAL_VALUES(NAME, BODY) { Py_complex* p = (Py_complex*)NAME; BODY }
    10981106#define C(REAL, IMAG) p->real = REAL; p->imag = IMAG; ++p;
    10991107
    1100         INIT_SPECIAL_VALUES(acos_special_values, {
    1101           C(P34,INF) C(P,INF)  C(P,INF)  C(P,-INF)  C(P,-INF)  C(P34,-INF) C(N,INF)
    1102           C(P12,INF) C(U,U)    C(U,U)    C(U,U)     C(U,U)     C(P12,-INF) C(N,N)
    1103           C(P12,INF) C(U,U)    C(P12,0.) C(P12,-0.) C(U,U)     C(P12,-INF) C(P12,N)
    1104           C(P12,INF) C(U,U)    C(P12,0.) C(P12,-0.) C(U,U)     C(P12,-INF) C(P12,N)
    1105           C(P12,INF) C(U,U)    C(U,U)    C(U,U)     C(U,U)     C(P12,-INF) C(N,N)
    1106           C(P14,INF) C(0.,INF) C(0.,INF) C(0.,-INF) C(0.,-INF) C(P14,-INF) C(N,INF)
    1107           C(N,INF)   C(N,N)    C(N,N)    C(N,N)     C(N,N)     C(N,-INF)   C(N,N)
    1108         })
    1109 
    1110         INIT_SPECIAL_VALUES(acosh_special_values, {
    1111           C(INF,-P34) C(INF,-P)  C(INF,-P)  C(INF,P)  C(INF,P)  C(INF,P34) C(INF,N)
    1112           C(INF,-P12) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,P12) C(N,N)
    1113           C(INF,-P12) C(U,U)     C(0.,-P12) C(0.,P12) C(U,U)    C(INF,P12) C(N,N)
    1114           C(INF,-P12) C(U,U)     C(0.,-P12) C(0.,P12) C(U,U)    C(INF,P12) C(N,N)
    1115           C(INF,-P12) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,P12) C(N,N)
    1116           C(INF,-P14) C(INF,-0.) C(INF,-0.) C(INF,0.) C(INF,0.) C(INF,P14) C(INF,N)
    1117           C(INF,N)    C(N,N)     C(N,N)     C(N,N)    C(N,N)    C(INF,N)   C(N,N)
    1118         })
    1119 
    1120         INIT_SPECIAL_VALUES(asinh_special_values, {
    1121           C(-INF,-P14) C(-INF,-0.) C(-INF,-0.) C(-INF,0.) C(-INF,0.) C(-INF,P14) C(-INF,N)
    1122           C(-INF,-P12) C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(-INF,P12) C(N,N)
    1123           C(-INF,-P12) C(U,U)      C(-0.,-0.)  C(-0.,0.)  C(U,U)     C(-INF,P12) C(N,N)
    1124           C(INF,-P12)  C(U,U)      C(0.,-0.)   C(0.,0.)   C(U,U)     C(INF,P12)  C(N,N)
    1125           C(INF,-P12)  C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(INF,P12)  C(N,N)
    1126           C(INF,-P14)  C(INF,-0.)  C(INF,-0.)  C(INF,0.)  C(INF,0.)  C(INF,P14)  C(INF,N)
    1127           C(INF,N)     C(N,N)      C(N,-0.)    C(N,0.)    C(N,N)     C(INF,N)    C(N,N)
    1128         })
    1129 
    1130         INIT_SPECIAL_VALUES(atanh_special_values, {
    1131           C(-0.,-P12) C(-0.,-P12) C(-0.,-P12) C(-0.,P12) C(-0.,P12) C(-0.,P12) C(-0.,N)
    1132           C(-0.,-P12) C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(-0.,P12) C(N,N)
    1133           C(-0.,-P12) C(U,U)      C(-0.,-0.)  C(-0.,0.)  C(U,U)     C(-0.,P12) C(-0.,N)
    1134           C(0.,-P12)  C(U,U)      C(0.,-0.)   C(0.,0.)   C(U,U)     C(0.,P12)  C(0.,N)
    1135           C(0.,-P12)  C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(0.,P12)  C(N,N)
    1136           C(0.,-P12)  C(0.,-P12)  C(0.,-P12)  C(0.,P12)  C(0.,P12)  C(0.,P12)  C(0.,N)
    1137           C(0.,-P12)  C(N,N)      C(N,N)      C(N,N)     C(N,N)     C(0.,P12)  C(N,N)
    1138         })
    1139 
    1140         INIT_SPECIAL_VALUES(cosh_special_values, {
    1141           C(INF,N) C(U,U) C(INF,0.)  C(INF,-0.) C(U,U) C(INF,N) C(INF,N)
    1142           C(N,N)   C(U,U) C(U,U)     C(U,U)     C(U,U) C(N,N)   C(N,N)
    1143           C(N,0.)  C(U,U) C(1.,0.)   C(1.,-0.)  C(U,U) C(N,0.)  C(N,0.)
    1144           C(N,0.)  C(U,U) C(1.,-0.)  C(1.,0.)   C(U,U) C(N,0.)  C(N,0.)
    1145           C(N,N)   C(U,U) C(U,U)     C(U,U)     C(U,U) C(N,N)   C(N,N)
    1146           C(INF,N) C(U,U) C(INF,-0.) C(INF,0.)  C(U,U) C(INF,N) C(INF,N)
    1147           C(N,N)   C(N,N) C(N,0.)    C(N,0.)    C(N,N) C(N,N)   C(N,N)
    1148         })
    1149 
    1150         INIT_SPECIAL_VALUES(exp_special_values, {
    1151           C(0.,0.) C(U,U) C(0.,-0.)  C(0.,0.)  C(U,U) C(0.,0.) C(0.,0.)
    1152           C(N,N)   C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)   C(N,N)
    1153           C(N,N)   C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(N,N)   C(N,N)
    1154           C(N,N)   C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(N,N)   C(N,N)
    1155           C(N,N)   C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)   C(N,N)
    1156           C(INF,N) C(U,U) C(INF,-0.) C(INF,0.) C(U,U) C(INF,N) C(INF,N)
    1157           C(N,N)   C(N,N) C(N,-0.)   C(N,0.)   C(N,N) C(N,N)   C(N,N)
    1158         })
    1159 
    1160         INIT_SPECIAL_VALUES(log_special_values, {
    1161           C(INF,-P34) C(INF,-P)  C(INF,-P)   C(INF,P)   C(INF,P)  C(INF,P34)  C(INF,N)
    1162           C(INF,-P12) C(U,U)     C(U,U)      C(U,U)     C(U,U)    C(INF,P12)  C(N,N)
    1163           C(INF,-P12) C(U,U)     C(-INF,-P)  C(-INF,P)  C(U,U)    C(INF,P12)  C(N,N)
    1164           C(INF,-P12) C(U,U)     C(-INF,-0.) C(-INF,0.) C(U,U)    C(INF,P12)  C(N,N)
    1165           C(INF,-P12) C(U,U)     C(U,U)      C(U,U)     C(U,U)    C(INF,P12)  C(N,N)
    1166           C(INF,-P14) C(INF,-0.) C(INF,-0.)  C(INF,0.)  C(INF,0.) C(INF,P14)  C(INF,N)
    1167           C(INF,N)    C(N,N)     C(N,N)      C(N,N)     C(N,N)    C(INF,N)    C(N,N)
    1168         })
    1169 
    1170         INIT_SPECIAL_VALUES(sinh_special_values, {
    1171           C(INF,N) C(U,U) C(-INF,-0.) C(-INF,0.) C(U,U) C(INF,N) C(INF,N)
    1172           C(N,N)   C(U,U) C(U,U)      C(U,U)     C(U,U) C(N,N)   C(N,N)
    1173           C(0.,N)  C(U,U) C(-0.,-0.)  C(-0.,0.)  C(U,U) C(0.,N)  C(0.,N)
    1174           C(0.,N)  C(U,U) C(0.,-0.)   C(0.,0.)   C(U,U) C(0.,N)  C(0.,N)
    1175           C(N,N)   C(U,U) C(U,U)      C(U,U)     C(U,U) C(N,N)   C(N,N)
    1176           C(INF,N) C(U,U) C(INF,-0.)  C(INF,0.)  C(U,U) C(INF,N) C(INF,N)
    1177           C(N,N)   C(N,N) C(N,-0.)    C(N,0.)    C(N,N) C(N,N)   C(N,N)
    1178         })
    1179 
    1180         INIT_SPECIAL_VALUES(sqrt_special_values, {
    1181           C(INF,-INF) C(0.,-INF) C(0.,-INF) C(0.,INF) C(0.,INF) C(INF,INF) C(N,INF)
    1182           C(INF,-INF) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,INF) C(N,N)
    1183           C(INF,-INF) C(U,U)     C(0.,-0.)  C(0.,0.)  C(U,U)    C(INF,INF) C(N,N)
    1184           C(INF,-INF) C(U,U)     C(0.,-0.)  C(0.,0.)  C(U,U)    C(INF,INF) C(N,N)
    1185           C(INF,-INF) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,INF) C(N,N)
    1186           C(INF,-INF) C(INF,-0.) C(INF,-0.) C(INF,0.) C(INF,0.) C(INF,INF) C(INF,N)
    1187           C(INF,-INF) C(N,N)     C(N,N)     C(N,N)    C(N,N)    C(INF,INF) C(N,N)
    1188         })
    1189 
    1190         INIT_SPECIAL_VALUES(tanh_special_values, {
    1191           C(-1.,0.) C(U,U) C(-1.,-0.) C(-1.,0.) C(U,U) C(-1.,0.) C(-1.,0.)
    1192           C(N,N)    C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)    C(N,N)
    1193           C(N,N)    C(U,U) C(-0.,-0.) C(-0.,0.) C(U,U) C(N,N)    C(N,N)
    1194           C(N,N)    C(U,U) C(0.,-0.)  C(0.,0.)  C(U,U) C(N,N)    C(N,N)
    1195           C(N,N)    C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)    C(N,N)
    1196           C(1.,0.)  C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(1.,0.)  C(1.,0.)
    1197           C(N,N)    C(N,N) C(N,-0.)   C(N,0.)   C(N,N) C(N,N)    C(N,N)
    1198         })
    1199 
    1200         INIT_SPECIAL_VALUES(rect_special_values, {
    1201           C(INF,N) C(U,U) C(-INF,0.) C(-INF,-0.) C(U,U) C(INF,N) C(INF,N)
    1202           C(N,N)   C(U,U) C(U,U)     C(U,U)      C(U,U) C(N,N)   C(N,N)
    1203           C(0.,0.) C(U,U) C(-0.,0.)  C(-0.,-0.)  C(U,U) C(0.,0.) C(0.,0.)
    1204           C(0.,0.) C(U,U) C(0.,-0.)  C(0.,0.)    C(U,U) C(0.,0.) C(0.,0.)
    1205           C(N,N)   C(U,U) C(U,U)     C(U,U)      C(U,U) C(N,N)   C(N,N)
    1206           C(INF,N) C(U,U) C(INF,-0.) C(INF,0.)   C(U,U) C(INF,N) C(INF,N)
    1207           C(N,N)   C(N,N) C(N,0.)    C(N,0.)     C(N,N) C(N,N)   C(N,N)
    1208         })
    1209 }
     1108    INIT_SPECIAL_VALUES(acos_special_values, {
     1109      C(P34,INF) C(P,INF)  C(P,INF)  C(P,-INF)  C(P,-INF)  C(P34,-INF) C(N,INF)
     1110      C(P12,INF) C(U,U)    C(U,U)    C(U,U)     C(U,U)     C(P12,-INF) C(N,N)
     1111      C(P12,INF) C(U,U)    C(P12,0.) C(P12,-0.) C(U,U)     C(P12,-INF) C(P12,N)
     1112      C(P12,INF) C(U,U)    C(P12,0.) C(P12,-0.) C(U,U)     C(P12,-INF) C(P12,N)
     1113      C(P12,INF) C(U,U)    C(U,U)    C(U,U)     C(U,U)     C(P12,-INF) C(N,N)
     1114      C(P14,INF) C(0.,INF) C(0.,INF) C(0.,-INF) C(0.,-INF) C(P14,-INF) C(N,INF)
     1115      C(N,INF)   C(N,N)    C(N,N)    C(N,N)     C(N,N)     C(N,-INF)   C(N,N)
     1116    })
     1117
     1118    INIT_SPECIAL_VALUES(acosh_special_values, {
     1119      C(INF,-P34) C(INF,-P)  C(INF,-P)  C(INF,P)  C(INF,P)  C(INF,P34) C(INF,N)
     1120      C(INF,-P12) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,P12) C(N,N)
     1121      C(INF,-P12) C(U,U)     C(0.,-P12) C(0.,P12) C(U,U)    C(INF,P12) C(N,N)
     1122      C(INF,-P12) C(U,U)     C(0.,-P12) C(0.,P12) C(U,U)    C(INF,P12) C(N,N)
     1123      C(INF,-P12) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,P12) C(N,N)
     1124      C(INF,-P14) C(INF,-0.) C(INF,-0.) C(INF,0.) C(INF,0.) C(INF,P14) C(INF,N)
     1125      C(INF,N)    C(N,N)     C(N,N)     C(N,N)    C(N,N)    C(INF,N)   C(N,N)
     1126    })
     1127
     1128    INIT_SPECIAL_VALUES(asinh_special_values, {
     1129      C(-INF,-P14) C(-INF,-0.) C(-INF,-0.) C(-INF,0.) C(-INF,0.) C(-INF,P14) C(-INF,N)
     1130      C(-INF,-P12) C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(-INF,P12) C(N,N)
     1131      C(-INF,-P12) C(U,U)      C(-0.,-0.)  C(-0.,0.)  C(U,U)     C(-INF,P12) C(N,N)
     1132      C(INF,-P12)  C(U,U)      C(0.,-0.)   C(0.,0.)   C(U,U)     C(INF,P12)  C(N,N)
     1133      C(INF,-P12)  C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(INF,P12)  C(N,N)
     1134      C(INF,-P14)  C(INF,-0.)  C(INF,-0.)  C(INF,0.)  C(INF,0.)  C(INF,P14)  C(INF,N)
     1135      C(INF,N)     C(N,N)      C(N,-0.)    C(N,0.)    C(N,N)     C(INF,N)    C(N,N)
     1136    })
     1137
     1138    INIT_SPECIAL_VALUES(atanh_special_values, {
     1139      C(-0.,-P12) C(-0.,-P12) C(-0.,-P12) C(-0.,P12) C(-0.,P12) C(-0.,P12) C(-0.,N)
     1140      C(-0.,-P12) C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(-0.,P12) C(N,N)
     1141      C(-0.,-P12) C(U,U)      C(-0.,-0.)  C(-0.,0.)  C(U,U)     C(-0.,P12) C(-0.,N)
     1142      C(0.,-P12)  C(U,U)      C(0.,-0.)   C(0.,0.)   C(U,U)     C(0.,P12)  C(0.,N)
     1143      C(0.,-P12)  C(U,U)      C(U,U)      C(U,U)     C(U,U)     C(0.,P12)  C(N,N)
     1144      C(0.,-P12)  C(0.,-P12)  C(0.,-P12)  C(0.,P12)  C(0.,P12)  C(0.,P12)  C(0.,N)
     1145      C(0.,-P12)  C(N,N)      C(N,N)      C(N,N)     C(N,N)     C(0.,P12)  C(N,N)
     1146    })
     1147
     1148    INIT_SPECIAL_VALUES(cosh_special_values, {
     1149      C(INF,N) C(U,U) C(INF,0.)  C(INF,-0.) C(U,U) C(INF,N) C(INF,N)
     1150      C(N,N)   C(U,U) C(U,U)     C(U,U)     C(U,U) C(N,N)   C(N,N)
     1151      C(N,0.)  C(U,U) C(1.,0.)   C(1.,-0.)  C(U,U) C(N,0.)  C(N,0.)
     1152      C(N,0.)  C(U,U) C(1.,-0.)  C(1.,0.)   C(U,U) C(N,0.)  C(N,0.)
     1153      C(N,N)   C(U,U) C(U,U)     C(U,U)     C(U,U) C(N,N)   C(N,N)
     1154      C(INF,N) C(U,U) C(INF,-0.) C(INF,0.)  C(U,U) C(INF,N) C(INF,N)
     1155      C(N,N)   C(N,N) C(N,0.)    C(N,0.)    C(N,N) C(N,N)   C(N,N)
     1156    })
     1157
     1158    INIT_SPECIAL_VALUES(exp_special_values, {
     1159      C(0.,0.) C(U,U) C(0.,-0.)  C(0.,0.)  C(U,U) C(0.,0.) C(0.,0.)
     1160      C(N,N)   C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)   C(N,N)
     1161      C(N,N)   C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(N,N)   C(N,N)
     1162      C(N,N)   C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(N,N)   C(N,N)
     1163      C(N,N)   C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)   C(N,N)
     1164      C(INF,N) C(U,U) C(INF,-0.) C(INF,0.) C(U,U) C(INF,N) C(INF,N)
     1165      C(N,N)   C(N,N) C(N,-0.)   C(N,0.)   C(N,N) C(N,N)   C(N,N)
     1166    })
     1167
     1168    INIT_SPECIAL_VALUES(log_special_values, {
     1169      C(INF,-P34) C(INF,-P)  C(INF,-P)   C(INF,P)   C(INF,P)  C(INF,P34)  C(INF,N)
     1170      C(INF,-P12) C(U,U)     C(U,U)      C(U,U)     C(U,U)    C(INF,P12)  C(N,N)
     1171      C(INF,-P12) C(U,U)     C(-INF,-P)  C(-INF,P)  C(U,U)    C(INF,P12)  C(N,N)
     1172      C(INF,-P12) C(U,U)     C(-INF,-0.) C(-INF,0.) C(U,U)    C(INF,P12)  C(N,N)
     1173      C(INF,-P12) C(U,U)     C(U,U)      C(U,U)     C(U,U)    C(INF,P12)  C(N,N)
     1174      C(INF,-P14) C(INF,-0.) C(INF,-0.)  C(INF,0.)  C(INF,0.) C(INF,P14)  C(INF,N)
     1175      C(INF,N)    C(N,N)     C(N,N)      C(N,N)     C(N,N)    C(INF,N)    C(N,N)
     1176    })
     1177
     1178    INIT_SPECIAL_VALUES(sinh_special_values, {
     1179      C(INF,N) C(U,U) C(-INF,-0.) C(-INF,0.) C(U,U) C(INF,N) C(INF,N)
     1180      C(N,N)   C(U,U) C(U,U)      C(U,U)     C(U,U) C(N,N)   C(N,N)
     1181      C(0.,N)  C(U,U) C(-0.,-0.)  C(-0.,0.)  C(U,U) C(0.,N)  C(0.,N)
     1182      C(0.,N)  C(U,U) C(0.,-0.)   C(0.,0.)   C(U,U) C(0.,N)  C(0.,N)
     1183      C(N,N)   C(U,U) C(U,U)      C(U,U)     C(U,U) C(N,N)   C(N,N)
     1184      C(INF,N) C(U,U) C(INF,-0.)  C(INF,0.)  C(U,U) C(INF,N) C(INF,N)
     1185      C(N,N)   C(N,N) C(N,-0.)    C(N,0.)    C(N,N) C(N,N)   C(N,N)
     1186    })
     1187
     1188    INIT_SPECIAL_VALUES(sqrt_special_values, {
     1189      C(INF,-INF) C(0.,-INF) C(0.,-INF) C(0.,INF) C(0.,INF) C(INF,INF) C(N,INF)
     1190      C(INF,-INF) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,INF) C(N,N)
     1191      C(INF,-INF) C(U,U)     C(0.,-0.)  C(0.,0.)  C(U,U)    C(INF,INF) C(N,N)
     1192      C(INF,-INF) C(U,U)     C(0.,-0.)  C(0.,0.)  C(U,U)    C(INF,INF) C(N,N)
     1193      C(INF,-INF) C(U,U)     C(U,U)     C(U,U)    C(U,U)    C(INF,INF) C(N,N)
     1194      C(INF,-INF) C(INF,-0.) C(INF,-0.) C(INF,0.) C(INF,0.) C(INF,INF) C(INF,N)
     1195      C(INF,-INF) C(N,N)     C(N,N)     C(N,N)    C(N,N)    C(INF,INF) C(N,N)
     1196    })
     1197
     1198    INIT_SPECIAL_VALUES(tanh_special_values, {
     1199      C(-1.,0.) C(U,U) C(-1.,-0.) C(-1.,0.) C(U,U) C(-1.,0.) C(-1.,0.)
     1200      C(N,N)    C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)    C(N,N)
     1201      C(N,N)    C(U,U) C(-0.,-0.) C(-0.,0.) C(U,U) C(N,N)    C(N,N)
     1202      C(N,N)    C(U,U) C(0.,-0.)  C(0.,0.)  C(U,U) C(N,N)    C(N,N)
     1203      C(N,N)    C(U,U) C(U,U)     C(U,U)    C(U,U) C(N,N)    C(N,N)
     1204      C(1.,0.)  C(U,U) C(1.,-0.)  C(1.,0.)  C(U,U) C(1.,0.)  C(1.,0.)
     1205      C(N,N)    C(N,N) C(N,-0.)   C(N,0.)   C(N,N) C(N,N)    C(N,N)
     1206    })
     1207
     1208    INIT_SPECIAL_VALUES(rect_special_values, {
     1209      C(INF,N) C(U,U) C(-INF,0.) C(-INF,-0.) C(U,U) C(INF,N) C(INF,N)
     1210      C(N,N)   C(U,U) C(U,U)     C(U,U)      C(U,U) C(N,N)   C(N,N)
     1211      C(0.,0.) C(U,U) C(-0.,0.)  C(-0.,-0.)  C(U,U) C(0.,0.) C(0.,0.)
     1212      C(0.,0.) C(U,U) C(0.,-0.)  C(0.,0.)    C(U,U) C(0.,0.) C(0.,0.)
     1213      C(N,N)   C(U,U) C(U,U)     C(U,U)      C(U,U) C(N,N)   C(N,N)
     1214      C(INF,N) C(U,U) C(INF,-0.) C(INF,0.)   C(U,U) C(INF,N) C(INF,N)
     1215      C(N,N)   C(N,N) C(N,0.)    C(N,0.)     C(N,N) C(N,N)   C(N,N)
     1216    })
     1217}
Note: See TracChangeset for help on using the changeset viewer.