Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>


  43  *
  44  * Note that the arctangent ranges from -PI to +PI, thus the imaginary
  45  * part of clog is atan2(y,x).
  46  *
  47  * EXCEPTION CASES (conform to ISO/IEC 9899:1999(E)):
  48  *    clog(-0 + i 0   ) =  -inf + i pi
  49  *    clog( 0 + i 0   ) =  -inf + i 0
  50  *    clog( x + i inf ) =  -inf + i pi/2, for finite x
  51  *    clog( x + i NaN ) =  NaN  + i NaN with invalid for finite x
  52  *    clog(-inf + iy   )=  +inf + i pi, for finite positive-signed y
  53  *    clog(+inf + iy   )=  +inf + i 0 , for finite positive-signed y
  54  *    clog(-inf + i inf)=  inf  + i 3pi/4
  55  *    clog(+inf + i inf)=  inf  + i pi/4
  56  *    clog(+-inf+ i NaN)=  inf  + i NaN
  57  *    clog(NaN  + i y  )=  NaN  + i NaN for finite y
  58  *    clog(NaN  + i inf)=  inf  + i NaN
  59  *    clog(NaN  + i NaN)=  NaN  + i NaN
  60  */
  61 /* INDENT ON */
  62 
  63 #include "libm_synonyms.h"
  64 #include <math.h>         /* atan2/fabs/log/log1p */
  65 #include "complex_wrapper.h"
  66 #include "libm_protos.h"        /* __k_clog_r */
  67 
  68 
  69 static const double half = 0.5, one = 1.0;
  70 
  71 dcomplex
  72 clog(dcomplex z) {
  73         dcomplex        ans;
  74         double          x, y, t, ax, ay, w;
  75         int             n, ix, iy, hx, hy;
  76         unsigned        lx, ly;
  77 
  78         x = D_RE(z);
  79         y = D_IM(z);
  80         hx = HI_WORD(x);
  81         lx = LO_WORD(x);
  82         hy = HI_WORD(y);
  83         ly = LO_WORD(y);
  84         ix = hx & 0x7fffffff;
  85         iy = hy & 0x7fffffff;
  86         ay = fabs(y);
  87         ax = fabs(x);
  88         D_IM(ans) = carg(z);
  89         if (ix < iy || (ix == iy && lx < ly)) {
  90                 /* swap x and y to force ax >= ay */
  91                 t = ax;
  92                 ax = ay;




  43  *
  44  * Note that the arctangent ranges from -PI to +PI, thus the imaginary
  45  * part of clog is atan2(y,x).
  46  *
  47  * EXCEPTION CASES (conform to ISO/IEC 9899:1999(E)):
  48  *    clog(-0 + i 0   ) =  -inf + i pi
  49  *    clog( 0 + i 0   ) =  -inf + i 0
  50  *    clog( x + i inf ) =  -inf + i pi/2, for finite x
  51  *    clog( x + i NaN ) =  NaN  + i NaN with invalid for finite x
  52  *    clog(-inf + iy   )=  +inf + i pi, for finite positive-signed y
  53  *    clog(+inf + iy   )=  +inf + i 0 , for finite positive-signed y
  54  *    clog(-inf + i inf)=  inf  + i 3pi/4
  55  *    clog(+inf + i inf)=  inf  + i pi/4
  56  *    clog(+-inf+ i NaN)=  inf  + i NaN
  57  *    clog(NaN  + i y  )=  NaN  + i NaN for finite y
  58  *    clog(NaN  + i inf)=  inf  + i NaN
  59  *    clog(NaN  + i NaN)=  NaN  + i NaN
  60  */
  61 /* INDENT ON */
  62 

  63 #include <math.h>         /* atan2/fabs/log/log1p */
  64 #include "complex_wrapper.h"
  65 #include "libm_protos.h"        /* __k_clog_r */
  66 
  67 
  68 static const double half = 0.5, one = 1.0;
  69 
  70 dcomplex
  71 __clog(dcomplex z) {
  72         dcomplex        ans;
  73         double          x, y, t, ax, ay, w;
  74         int             n, ix, iy, hx, hy;
  75         unsigned        lx, ly;
  76 
  77         x = D_RE(z);
  78         y = D_IM(z);
  79         hx = HI_WORD(x);
  80         lx = LO_WORD(x);
  81         hy = HI_WORD(y);
  82         ly = LO_WORD(y);
  83         ix = hx & 0x7fffffff;
  84         iy = hy & 0x7fffffff;
  85         ay = fabs(y);
  86         ax = fabs(x);
  87         D_IM(ans) = carg(z);
  88         if (ix < iy || (ix == iy && lx < ly)) {
  89                 /* swap x and y to force ax >= ay */
  90                 t = ax;
  91                 ax = ay;