Print this page
11210 libm should be cstyle(1ONBLD) clean


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */

  25 /*
  26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #pragma weak __csqrtf = csqrtf
  31 
  32 #include "libm.h"               /* sqrt/fabsf/sqrtf */
  33 #include "complex_wrapper.h"
  34 
  35 /* INDENT OFF */
  36 static const float zero = 0.0F;
  37 /* INDENT ON */
  38 
  39 fcomplex
  40 csqrtf(fcomplex z) {

  41         fcomplex ans;
  42         double dt, dx, dy;
  43         float x, y, t, ax, ay, w;
  44         int ix, iy, hx, hy;
  45 
  46         x = F_RE(z);
  47         y = F_IM(z);
  48         hx = THE_WORD(x);
  49         hy = THE_WORD(y);
  50         ix = hx & 0x7fffffff;
  51         iy = hy & 0x7fffffff;
  52         ay = fabsf(y);
  53         ax = fabsf(x);

  54         if (ix >= 0x7f800000 || iy >= 0x7f800000) {
  55                 /* x or y is Inf or NaN */
  56                 if (iy == 0x7f800000)
  57                         F_IM(ans) = F_RE(ans) = ay;
  58                 else if (ix == 0x7f800000) {
  59                         if (hx > 0) {
  60                                 F_RE(ans) = ax;
  61                                 F_IM(ans) = ay * zero;
  62                         } else {
  63                                 F_RE(ans) = ay * zero;
  64                                 F_IM(ans) = ax;
  65                         }
  66                 } else
  67                         F_IM(ans) = F_RE(ans) = ax + ay;

  68         } else if (iy == 0) {
  69                 if (hx >= 0) {
  70                         F_RE(ans) = sqrtf(ax);
  71                         F_IM(ans) = zero;
  72                 } else {
  73                         F_IM(ans) = sqrtf(ax);
  74                         F_RE(ans) = zero;
  75                 }
  76         } else {
  77                 dx = (double) ax;
  78                 dy = (double) ay;
  79                 dt = sqrt(0.5 * (sqrt(dx * dx + dy * dy) + dx));
  80                 t = (float) dt;
  81                 w = (float) (dy / (dt + dt));

  82                 if (hx >= 0) {
  83                         F_RE(ans) = t;
  84                         F_IM(ans) = w;
  85                 } else {
  86                         F_IM(ans) = t;
  87                         F_RE(ans) = w;
  88                 }
  89         }

  90         if (hy < 0)
  91                 F_IM(ans) = -F_IM(ans);

  92         return (ans);
  93 }


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #pragma weak __csqrtf = csqrtf
  32 
  33 #include "libm.h"                       /* sqrt/fabsf/sqrtf */
  34 #include "complex_wrapper.h"
  35 

  36 static const float zero = 0.0F;
  37 
  38 
  39 fcomplex
  40 csqrtf(fcomplex z)
  41 {
  42         fcomplex ans;
  43         double dt, dx, dy;
  44         float x, y, t, ax, ay, w;
  45         int ix, iy, hx, hy;
  46 
  47         x = F_RE(z);
  48         y = F_IM(z);
  49         hx = THE_WORD(x);
  50         hy = THE_WORD(y);
  51         ix = hx & 0x7fffffff;
  52         iy = hy & 0x7fffffff;
  53         ay = fabsf(y);
  54         ax = fabsf(x);
  55 
  56         if (ix >= 0x7f800000 || iy >= 0x7f800000) {
  57                 /* x or y is Inf or NaN */
  58                 if (iy == 0x7f800000) {
  59                         F_IM(ans) = F_RE(ans) = ay;
  60                 } else if (ix == 0x7f800000) {
  61                         if (hx > 0) {
  62                                 F_RE(ans) = ax;
  63                                 F_IM(ans) = ay * zero;
  64                         } else {
  65                                 F_RE(ans) = ay * zero;
  66                                 F_IM(ans) = ax;
  67                         }
  68                 } else {
  69                         F_IM(ans) = F_RE(ans) = ax + ay;
  70                 }
  71         } else if (iy == 0) {
  72                 if (hx >= 0) {
  73                         F_RE(ans) = sqrtf(ax);
  74                         F_IM(ans) = zero;
  75                 } else {
  76                         F_IM(ans) = sqrtf(ax);
  77                         F_RE(ans) = zero;
  78                 }
  79         } else {
  80                 dx = (double)ax;
  81                 dy = (double)ay;
  82                 dt = sqrt(0.5 * (sqrt(dx * dx + dy * dy) + dx));
  83                 t = (float)dt;
  84                 w = (float)(dy / (dt + dt));
  85 
  86                 if (hx >= 0) {
  87                         F_RE(ans) = t;
  88                         F_IM(ans) = w;
  89                 } else {
  90                         F_IM(ans) = t;
  91                         F_RE(ans) = w;
  92                 }
  93         }
  94 
  95         if (hy < 0)
  96                 F_IM(ans) = -F_IM(ans);
  97 
  98         return (ans);
  99 }