Back to index

glibc  2.9
s_cbrtl.c
Go to the documentation of this file.
00001 /* Compute cubic root of double value.
00002    Copyright (C) 1997 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Dirk Alboth <dirka@uni-paderborn.de> and
00005    Ulrich Drepper <drepper@cygnus.com>, 1997.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include "math.h"
00023 #include "math_private.h"
00024 
00025 
00026 #define CBRT2 1.2599210498948731648              /* 2^(1/3) */
00027 #define SQR_CBRT2 1.5874010519681994748          /* 2^(2/3) */
00028 
00029 /* We don't use long double values here since U need not be computed
00030    with full precision.  */
00031 static const double factor[5] =
00032 {
00033   1.0 / SQR_CBRT2,
00034   1.0 / CBRT2,
00035   1.0,
00036   CBRT2,
00037   SQR_CBRT2
00038 };
00039 
00040 static const long double third = 0.3333333333333333333333333L;
00041 
00042 long double
00043 __cbrtl (long double x)
00044 {
00045   long double xm, u;
00046   int xe;
00047 
00048   /* Reduce X.  XM now is an range 1.0 to 0.5.  */
00049   xm = __frexpl (fabs (x), &xe);
00050 
00051   /* If X is not finite or is null return it (with raising exceptions
00052      if necessary.
00053      Note: *Our* version of `frexp' sets XE to zero if the argument is
00054      Inf or NaN.  This is not portable but faster.  */
00055   if (xe == 0 && fpclassify (x) <= FP_ZERO)
00056     return x + x;
00057 
00058   u = (((-1.34661104733595206551E-1 * xm
00059          + 5.46646013663955245034E-1) * xm
00060         - 9.54382247715094465250E-1) * xm
00061        + 1.13999833547172932737E0) * xm
00062        + 4.02389795645447521269E-1;
00063 
00064   u *= factor[2 + xe % 3];
00065   u = __ldexpl (x > 0.0 ? u : -u, xe / 3);
00066 
00067   u -= (u - (x / (u * u))) * third;
00068   u -= (u - (x / (u * u))) * third;
00069   return u;
00070 }
00071 weak_alias (__cbrtl, cbrtl)