ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/09/11/23:42:47

From: gkochanski AT attmail DOT com
Date: 12 Sep 92 02:46:27 GMT
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Message-Version: 2
>To: internet!sun.soe.clarkson.edu!djgpp
Original-Date: Sat Sep 12 02:46:27 GMT 1992
Original-From: attmail!gkochanski (Greg Kochanski )
Mts-Message-Id: <gkochanski2560246270>
Ua-Content-Id: <gkochanski2560246270>
Email-Version: 2
Subject: Math Library
Ua-Message-Id: <gkochanski2560246270>
Original-To: attmail!internet!sun.soe.clarkson.edu!djgpp

The hyperbolic trig routines in libm.a are rather inefficient.
For example, tanh() calls exp() four times, when only one call
is necessary.  Since the files are so small, and the changes are
so complete (from version 1.08), I will just include the files,
rather than using diff.

The asinh() routine fixes a loss of significance for large negative
arguments.


######################## libsrc/m/src/tanh.c ####################
#include <math.h>

double tanh(double x)
{
  const double ebig = exp(fabs(x));
  const double esmall = 1.0/ebig;
  return (ebig - esmall) / (ebig + esmall);
}

######################## libsrc/m/src/cosh.c ####################
#include <math.h>

double cosh(double x)
{
  const double ebig = exp(fabs(x));
  return (ebig + 1.0/ebig) / 2.0;
}

######################## libsrc/m/src/sinh.c ####################
#include <math.h>

double sinh(double x)
{
 if(x >= 0.0)   {
        const double epos = exp(x);
        return (epos - 1.0/epos) / 2.0;
        }

  {
  const double eneg = exp(-x);
  return (1.0/eneg - eneg) / 2.0;
 }
}

######################## libsrc/m/src/asinh.c ####################
#include <math.h>

double asinh(double x)
{
  return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x);
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019