download atanl.c
Language: C
License: GPL
Copyright: Copyright 2001 by Stephen L. Moshier
LOC: 138
Project Info
gnulib - portability library(gnulib)
Server: Savannah GNU
Type: cvs
...g\gnulib\gnulib\gnulib\lib\
   .cppi-disable
   .cvsignore
   __fpending.c
   __fpending.h
   acl-internal.h
   acl.c
   acl.h
   acl_entries.c
   acosl.c
   alloca.c
   alloca_.h
   arcfour.c
   arcfour.h
   arctwo.c
   arctwo.h
   areadlink-with-size.c
   areadlink.h
   argmatch.c
   argmatch.h
   argp-ba.c
   argp-eexst.c
   argp-fmtstream.c
   argp-fmtstream.h
   argp-fs-xinl.c
   argp-help.c
   argp-namefrob.h
   argp-parse.c
   argp-pin.c
   argp-pv.c
   argp-pvh.c
   argp-xinl.c
   argp.h
   argz.c
   argz_.h
   asinl.c
   asnprintf.c
   asprintf.c
   at-func.c
   atanl.c
   atexit.c
   backupfile.c
   backupfile.h
   base64.c
   base64.h
   basename.c
   bcopy.c
   binary-io.h
   byteswap_.h
   c-ctype.c
   c-ctype.h
   c-stack.c
   c-stack.h
   c-strcase.h
   c-strcasecmp.c
   c-strcaseeq.h
   c-strcasestr.c
   c-strcasestr.h
   c-strncasecmp.c
   c-strstr.c
   c-strstr.h
   c-strtod.c
   c-strtod.h
   c-strtold.c
   calloc.c
   canon-host.c
   canon-host.h
   canonicalize-lgpl.c
   canonicalize.c
   canonicalize.h
   ceill.c
   chdir-long.c
   chdir-long.h
   chdir-safer.c
   chdir-safer.h
   check-version.c
   check-version.h
   chown.c
   classpath.c
   classpath.h
   clean-temp.c
   clean-temp.h
   cloexec.c
   cloexec.h
   close-stream.c
   close-stream.h
   closein.c
   closein.h
   closeout.c
   closeout.h
   concat-filename.c
   config.charset
   copy-file.c
   copy-file.h
   cosl.c
   count-one-bits.h
   crc.c
   crc.h
   creat-safer.c
   csharpcomp.c
   csharpcomp.h
   csharpexec.c
   csharpexec.h
   cycle-check.c
   cycle-check.h
   des.c
   des.h
   dev-ino.h
   diacrit.c
   diacrit.h
   diffseq.h
   dirchownmod.c
   dirchownmod.h
   dirent_.h
   dirfd.c
   dirfd.h
   dirname.c
   dirname.h
   dummy.c
   dup-safer.c
   dup2.c
   eealloc.h
   error.c
   error.h
   euidaccess.c
   euidaccess.h
   exclude.c
   exclude.h
   execute.c
   execute.h
   exitfail.c
   exitfail.h
   expl.c
   fatal-signal.c
   fatal-signal.h
   fbufmode.c
   fbufmode.h
   fchdir.c
   fchmodat.c
   fchown-stub.c
   fchownat.c
   fcntl--.h
   fcntl-safer.h
   fcntl_.h
   fd-safer.c
   fflush.c
   file-has-acl.c
   file-type.c
   file-type.h
   fileblocks.c
   filemode.c
   filemode.h
   filename.h
   filenamecat.c
   filenamecat.h
   findprog.c
   findprog.h
   float+.h
   float_.h
   floorl.c
   fnmatch.c
   fnmatch_.h
   fnmatch_loop.c
   fopen-safer.c
   fprintf.c
   fprintftime.c
   fprintftime.h
   fpucw.h
   fpurge.c
   fpurge.h
   freadable.c
   freadable.h
   freadahead.c
   freadahead.h
   freading.c
   freading.h
   free.c
   frexp.c
   frexpl.c
   fseek.c
   fseeko.c
   fseterr.c
   fseterr.h
   fstatat.c
   fstrcmp.c
   fstrcmp.h
   fsusage.c
   fsusage.h
   ftell.c
   ftello.c
   ftruncate.c
   fts-cycle.c
   fts.c
   fts_.h
   full-read.c
   full-read.h
   full-write.c
   full-write.h
   fwritable.c
   fwritable.h
   fwriteerror.c
   fwriteerror.h
   fwriting.c
   fwriting.h
   gai_strerror.c
   gc-gnulib.c
   gc-libgcrypt.c
   gc-pbkdf2-sha1.c
   gc.h
   gcd.c
   gcd.h
   getaddrinfo.c
   getaddrinfo.h
   getcwd.c
   getdate.h
   getdate.y
   getdelim.c
   getdomainname.c
   getdomainname.h
   getgroups.c
   gethostname.c
   gethrxtime.c
   gethrxtime.h
   getline.c
   getloadavg.c
   getlogin_r.c
   getndelim2.c
   getndelim2.h
   getnline.c
   getnline.h
   getopt.c
   getopt_.h
   getopt_int.h
   getopt1.c
   getpagesize.h
   getpass.c
   getpass.h
   getsubopt.c
   gettext.h
   gettime.c
   gettimeofday.c
   getugroups.c
   getugroups.h
   getusershell.c
   gl_anyavltree_list1.h
   gl_anyavltree_list2.h
   gl_anyhash_list1.h
   gl_anyhash_list2.h
   gl_anylinked_list1.h
   gl_anylinked_list2.h
   gl_anyrbtree_list1.h
   gl_anyrbtree_list2.h
   gl_anytree_list1.h
   gl_anytree_list2.h
   gl_anytree_oset.h
   gl_anytreehash_list1.h
   gl_anytreehash_list2.h
   gl_array_list.c
   gl_array_list.h
   gl_array_oset.c
   gl_array_oset.h
   gl_avltree_list.c
   gl_avltree_list.h
   gl_avltree_oset.c
   gl_avltree_oset.h
   gl_avltreehash_list.c
   gl_avltreehash_list.h
   gl_carray_list.c
   gl_carray_list.h
   gl_linked_list.c
   gl_linked_list.h
   gl_linkedhash_list.c
   gl_linkedhash_list.h
   gl_list.c
   gl_list.h
   gl_oset.c
   gl_oset.h
   gl_rbtree_list.c
   gl_rbtree_list.h
   gl_rbtree_oset.c
   gl_rbtree_oset.h
   gl_rbtreehash_list.c
   gl_rbtreehash_list.h
   gl_sublist.c
   gl_sublist.h
   glob-libc.h
   glob.c
   glob_.h
   group-member.c
   group-member.h
   hard-locale.c
   hard-locale.h
   hash-pjw.c
   hash-pjw.h
   hash.c
   hash.h
   hmac-md5.c
   hmac-sha1.c
   hmac.h
   human.c
   human.h
   i-ring-test.c
   i-ring.c
   i-ring.h
   iconv_.h
   iconv_open-aix.gperf
   iconv_open-hpux.gperf
   iconv_open-irix.gperf
   iconv_open-osf.gperf
   iconv_open.c
   idcache.c
   idcache.h
   imaxabs.c
   imaxdiv.c
   imaxtostr.c
   inet_ntop.c
   inet_ntop.h
   inet_pton.c
   inet_pton.h
   intprops.h
   inttostr.c
   inttostr.h
   inttypes_.h
   isapipe.c
   isapipe.h
   isdir.c
   isnan.c
   isnan.h
   isnanf.c
   isnanf.h
   isnanl-nolibm.h
   isnanl.c
   isnanl.h
   javacomp.c
   javacomp.h
   javaexec.c
   javaexec.h
   javaversion.c
   javaversion.h
   javaversion.java
   lbrkprop.h
   lchmod.h
   lchown.c
   ldexpl.c
   linebreak.c
   linebreak.h
   linebuffer.c
   linebuffer.h
   localcharset.c
   localcharset.h
   locale_.h
   localename.c
   localename.h
   lock.c
   lock.h
   logl.c
   long-options.c
   long-options.h
   lseek.c
   lstat.c
   lstat.h
   malloc.c
   malloca.c
   malloca.h
   malloca.valgrind
   math_.h
   mbchar.c
   mbchar.h
   mbfile.h
   mbiter.h
   mbscasecmp.c
   mbscasestr.c
   mbschr.c
   mbscspn.c
   mbslen.c
   mbsncasecmp.c
   mbsnlen.c
   mbspbrk.c
   mbspcasecmp.c
   mbsrchr.c
   mbssep.c
   mbsspn.c
   mbsstr.c
   mbstok_r.c
   mbswidth.c
   mbswidth.h
   mbuiter.h
   md2.c
   md2.h
   md4.c
   md4.h
   md5.c
   md5.h
   memcasecmp.c
   memcasecmp.h
   memchr.c
   memcmp.c
   memcoll.c
   memcoll.h
   memcpy.c
   memmem.c
   memmove.c
   mempcpy.c
   memrchr.c
   memset.c
   memxor.c
   memxor.h
   minmax.h
   mkancesdirs.c
   mkancesdirs.h
   mkdir-p.c
   mkdir-p.h
   mkdir.c
   mkdirat.c
   mkdtemp.c
   mkstemp-safer.c
   mkstemp.c
   mktime.c
   modechange.c
   modechange.h
   mountlist.c
   mountlist.h
   mpsort.c
   mpsort.h
   nanosleep.c
   netinet_in_.h
   obstack.c
   obstack.h
   offtostr.c
   open-safer.c
   openat-die.c
   openat-priv.h
   openat-proc.c
   openat.c
   openat.h
   pagealign_alloc.c
   pagealign_alloc.h
   pathmax.h
   physmem.c
   physmem.h
   pipe-safer.c
   pipe.c
   pipe.h
   poll.c
   poll_.h
   posixtm.c
   posixtm.h
   posixver.c
   posixver.h
   printf-args.c
   printf-args.h
   printf-frexp.c
   printf-frexp.h
   printf-frexpl.c
   printf-frexpl.h
   printf-parse.c
   printf-parse.h
   printf.c
   progname.c
   progname.h
   progreloc.c
   putenv.c
   quote.c
   quote.h
   quotearg.c
   quotearg.h
   raise.c
   read-file.c
   read-file.h
   readline.c
   readline.h
   readlink.c
   readtokens.c
   readtokens.h
   readtokens0.c
   readtokens0.h
   readutmp.c
   readutmp.h
   realloc.c
   ref-add.sin
   ref-del.sin
   regcomp.c
   regex.c
   regex.h
   regex_internal.c
   regex_internal.h
   regexec.c
   relocatable.c
   relocatable.h
   relocwrapper.c
   rename-dest-slash.c
   rename.c
   rijndael-alg-fst.c
   rijndael-alg-fst.h
   rijndael-api-fst.c
   rijndael-api-fst.h
   rmdir.c
   rpmatch.c
   safe-read.c
   safe-read.h
   safe-write.c
   safe-write.h
   same-inode.h
   same.c
   same.h
   save-cwd.c
   save-cwd.h
   savedir.c
   savedir.h
   savewd.c
   savewd.h
   search_.h
   setenv.c
   setenv.h
   settime.c
   sh-quote.c
   sh-quote.h
   sha1.c
   sha1.h
   sig2str.c
   sig2str.h
   signal_.h
   signbitd.c
   signbitf.c
   signbitl.c
   sigprocmask.c
   sincosl.c
   sinl.c
   size_max.h
   sleep.c
   snprintf.c
   sprintf.c
   sqrtl.c
   stat-macros.h
   stat-time.h
   stdbool_.h
   stdint_.h
   stdio--.h
   stdio-safer.h
   stdio_.h
   stdlib--.h
   stdlib-safer.h
   stdlib_.h
   stpcpy.c
   stpncpy.c
   strcasecmp.c
   strcasestr.c
   strchrnul.c
   strcspn.c
   strdup.c
   streq.h
   strerror.c
   strftime.c
   strftime.h
   striconv.c
   striconv.h
   striconveh.c
   striconveh.h
   striconveha.c
   striconveha.h
   string_.h
   stripslash.c
   strncasecmp.c
   strndup.c
   strnlen.c
   strnlen1.c
   strnlen1.h
   strpbrk.c
   strptime.c
   strsep.c
   strtod.c
   strtoimax.c
   strtok_r.c
   strtol.c
   strtoll.c
   strtoul.c
   strtoull.c
   strtoumax.c
   strverscmp.c
   strverscmp.h
   sys_select_.h
   sys_socket_.h
   sys_stat_.h
   sys_time_.h
   sysexits_.h
   tanl.c
   tempname.c
   tempname.h
   time_.h
   time_r.c
   timegm.c
   timespec.h
   tls.c
   tls.h
   tmpdir.c
   tmpdir.h
   tmpfile-safer.c
   tmpfile.c
   trigl.c
   trigl.h
   trim.c
   trim.h
   tsearch.c
   uinttostr.c
   umaxtostr.c
   unicodeio.c
   unicodeio.h
   uniconv.h
   uniname.h
   unistd--.h
   unistd-safer.h
   unistd_.h
   unistdio.h
   unistr.h
   unitypes.h
   uniwidth.h
   unlinkdir.c
   unlinkdir.h
   unlocked-io.h
   unsetenv.c
   userspec.c
   userspec.h
   utime.c
   utimecmp.c
   utimecmp.h
   utimens.c
   utimens.h
   vasnprintf.c
   vasnprintf.h
   vasprintf.c
   verify.h
   verror.c
   verror.h
   version-etc-fsf.c
   version-etc.c
   version-etc.h
   vfprintf.c
   vprintf.c
   vsnprintf.c
   vsprintf.c
   w32spawn.h
   wait-process.c
   wait-process.h
   wchar_.h
   wctype_.h
   wcwidth.c
   write-any-file.c
   write-any-file.h
   xalloc-die.c
   xalloc.h
   xasprintf.c
   xgetcwd.c
   xgetcwd.h
   xgetdomainname.c
   xgetdomainname.h
   xgethostname.c
   xgethostname.h
   xmalloc.c
   xmalloca.c
   xmalloca.h
   xmemcoll.c
   xmemcoll.h
   xnanosleep.c
   xnanosleep.h
   xreadlink.c
   xreadlink.h
   xsetenv.c
   xsetenv.h
   xsize.h
   xstriconv.c
   xstriconv.h
   xstrndup.c
   xstrndup.h
   xstrtod.c
   xstrtod.h
   xstrtoimax.c
   xstrtol-error.c
   xstrtol.c
   xstrtol.h
   xstrtold.c
   xstrtoul.c
   xstrtoumax.c
   xtime.h
   xvasprintf.c
   xvasprintf.h
   yesno.c
   yesno.h

/* Copyright 2001 by Stephen L. Moshier <moshier@na-net.ornl.gov>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.
   If not, write to the Free Software Foundation,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#include <config.h>

/* Specification.  */
#include <math.h>

/*							s_atanl.c
 *
 *	Inverse circular tangent for 128-bit long double precision
 *      (arctangent)
 *
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, atanl();
 *
 * y = atanl( x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns radian angle between -pi/2 and +pi/2 whose tangent is x.
 *
 * The function uses a rational approximation of the form
 * t + t^3 P(t^2)/Q(t^2), optimized for |t| < 0.09375.
 *
 * The argument is reduced using the identity
 *    arctan x - arctan u  =  arctan ((x-u)/(1 + ux))
 * and an 83-entry lookup table for arctan u, with u = 0, 1/8, ..., 10.25.
 * Use of the table improves the execution speed of the routine.
 *
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      -19, 19       4e5       1.7e-34     5.4e-35
 *
 *
 * WARNING:
 *
 * This program uses integer operations on bit fields of floating-point
 * numbers.  It does not work with data structures other than the
 * structure assumed.
 *
 */

#include "isnanl.h"

/* arctan(k/8), k = 0, ..., 82 */
static const long double atantbl[84] = {
  0.0000000000000000000000000000000000000000E0L,
  1.2435499454676143503135484916387102557317E-1L, /* arctan(0.125)  */
  2.4497866312686415417208248121127581091414E-1L,
  3.5877067027057222039592006392646049977698E-1L,
  4.6364760900080611621425623146121440202854E-1L,
  5.5859931534356243597150821640166127034645E-1L,
  6.4350110879328438680280922871732263804151E-1L,
  7.1882999962162450541701415152590465395142E-1L,
  7.8539816339744830961566084581987572104929E-1L,
  8.4415398611317100251784414827164750652594E-1L,
  8.9605538457134395617480071802993782702458E-1L,
  9.4200004037946366473793717053459358607166E-1L,
  9.8279372324732906798571061101466601449688E-1L,
  1.0191413442663497346383429170230636487744E0L,
  1.0516502125483736674598673120862998296302E0L,
  1.0808390005411683108871567292171998202703E0L,
  1.1071487177940905030170654601785370400700E0L,
  1.1309537439791604464709335155363278047493E0L,
  1.1525719972156675180401498626127513797495E0L,
  1.1722738811284763866005949441337046149712E0L,
  1.1902899496825317329277337748293183376012E0L,
  1.2068173702852525303955115800565576303133E0L,
  1.2220253232109896370417417439225704908830E0L,
  1.2360594894780819419094519711090786987027E0L,
  1.2490457723982544258299170772810901230778E0L,
  1.2610933822524404193139408812473357720101E0L,
  1.2722973952087173412961937498224804940684E0L,
  1.2827408797442707473628852511364955306249E0L,
  1.2924966677897852679030914214070816845853E0L,
  1.3016288340091961438047858503666855921414E0L,
  1.3101939350475556342564376891719053122733E0L,
  1.3182420510168370498593302023271362531155E0L,
  1.3258176636680324650592392104284756311844E0L,
  1.3329603993374458675538498697331558093700E0L,
  1.3397056595989995393283037525895557411039E0L,
  1.3460851583802539310489409282517796256512E0L,
  1.3521273809209546571891479413898128509842E0L,
  1.3578579772154994751124898859640585287459E0L,
  1.3633001003596939542892985278250991189943E0L,
  1.3684746984165928776366381936948529556191E0L,
  1.3734007669450158608612719264449611486510E0L,
  1.3780955681325110444536609641291551522494E0L,
  1.3825748214901258580599674177685685125566E0L,
  1.3868528702577214543289381097042486034883E0L,
  1.3909428270024183486427686943836432060856E0L,
  1.3948567013423687823948122092044222644895E0L,
  1.3986055122719575950126700816114282335732E0L,
  1.4021993871854670105330304794336492676944E0L,
  1.4056476493802697809521934019958079881002E0L,
  1.4089588955564736949699075250792569287156E0L,
  1.4121410646084952153676136718584891599630E0L,
  1.4152014988178669079462550975833894394929E0L,
  1.4181469983996314594038603039700989523716E0L,
  1.4209838702219992566633046424614466661176E0L,
  1.4237179714064941189018190466107297503086E0L,
  1.4263547484202526397918060597281265695725E0L,
  1.4288992721907326964184700745371983590908E0L,
  1.4313562697035588982240194668401779312122E0L,
  1.4337301524847089866404719096698873648610E0L,
  1.4360250423171655234964275337155008780675E0L,
  1.4382447944982225979614042479354815855386E0L,
  1.4403930189057632173997301031392126865694E0L,
  1.4424730991091018200252920599377292525125E0L,
  1.4444882097316563655148453598508037025938E0L,
  1.4464413322481351841999668424758804165254E0L,
  1.4483352693775551917970437843145232637695E0L,
  1.4501726582147939000905940595923466567576E0L,
  1.4519559822271314199339700039142990228105E0L,
  1.4536875822280323362423034480994649820285E0L,
  1.4553696664279718992423082296859928222270E0L,
  1.4570043196511885530074841089245667532358E0L,
  1.4585935117976422128825857356750737658039E0L,
  1.4601391056210009726721818194296893361233E0L,
  1.4616428638860188872060496086383008594310E0L,
  1.4631064559620759326975975316301202111560E0L,
  1.4645314639038178118428450961503371619177E0L,
  1.4659193880646627234129855241049975398470E0L,
  1.4672716522843522691530527207287398276197E0L,
  1.4685896086876430842559640450619880951144E0L,
  1.4698745421276027686510391411132998919794E0L,
  1.4711276743037345918528755717617308518553E0L,
  1.4723501675822635384916444186631899205983E0L,
  1.4735431285433308455179928682541563973416E0L, /* arctan(10.25) */
  1.5707963267948966192313216916397514420986E0L  /* pi/2 */
};


/* arctan t = t + t^3 p(t^2) / q(t^2)
   |t| <= 0.09375
   peak relative error 5.3e-37 */

static const long double
  p0 = -4.283708356338736809269381409828726405572E1L,
  p1 = -8.636132499244548540964557273544599863825E1L,
  p2 = -5.713554848244551350855604111031839613216E1L,
  p3 = -1.371405711877433266573835355036413750118E1L,
  p4 = -8.638214309119210906997318946650189640184E-1L,
  q0 = 1.285112506901621042780814422948906537959E2L,
  q1 = 3.361907253914337187957855834229672347089E2L,
  q2 = 3.180448303864130128268191635189365331680E2L,
  q3 = 1.307244136980865800160844625025280344686E2L,
  q4 = 2.173623741810414221251136181221172551416E1L;
  /* q5 = 1.000000000000000000000000000000000000000E0 */


long double
atanl (long double x)
{
  int k, sign;
  long double t, u, p, q;

  /* Check for zero or NaN.  */
  if (isnanl (x) || x == 0.0)
    return x + x;

  sign = x < 0.0;

  if (x + x == x)
    {
      /* Infinity. */
      if (sign)
	return -atantbl[83];
      else
	return atantbl[83];
    }

  if (sign)
      x = -x;

  if (x >= 10.25)
    {
      k = 83;
      t = -1.0/x;
    }
  else
    {
      /* Index of nearest table element.
	 Roundoff to integer is asymmetrical to avoid cancellation when t < 0
         (cf. fdlibm). */
      k = 8.0 * x + 0.25;
      u = 0.125 * k;
      /* Small arctan argument.  */
      t = (x - u) / (1.0 + x * u);
    }

  /* Arctan of small argument t.  */
  u = t * t;
  p =     ((((p4 * u) + p3) * u + p2) * u + p1) * u + p0;
  q = ((((u + q4) * u + q3) * u + q2) * u + q1) * u + q0;
  u = t * u * p / q  +  t;

  /* arctan x = arctan u  +  arctan t */
  u = atantbl[k] + u;
  if (sign)
    return (-u);
  else
    return u;
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us