libc.obj:

- Formatted by clang-format (WebKit-style).
- Removed unnecessary errno linux. 
- Added KOS error codes. 
- String functions have been replaced with more optimal ones for x86. 
- Changed wrappers for 70 sysfunction.

git-svn-id: svn://kolibrios.org@9765 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat
2022-04-15 09:00:55 +00:00
parent dff8056cd6
commit cde4fa851d
68 changed files with 1628 additions and 1762 deletions

View File

@@ -1,8 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
acosh(double x)
double acosh(double x)
{
return log(x + sqrt(x*x - 1));
}
return log(x + sqrt(x * x - 1));
}

View File

@@ -1,9 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
asinh(double x)
double asinh(double x)
{
return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x);
return x > 0 ? log(x + sqrt(x * x + 1)) : -log(sqrt(x * x + 1) - x);
}

View File

@@ -30,7 +30,7 @@ doit:
fpatan
ret
isanan:
movl $1, _errno
movl $1, __errno
fstp %st(0)
fstp %st(0)
fldl nan

View File

@@ -1,8 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
atanh(double x)
double atanh(double x)
{
return log((1+x)/(1-x)) / 2.0;
return log((1 + x) / (1 - x)) / 2.0;
}

View File

@@ -3,6 +3,6 @@
double cosh(double x)
{
const double ebig = exp(fabs(x));
return (ebig + 1.0/ebig) / 2.0;
const double ebig = exp(fabs(x));
return (ebig + 1.0 / ebig) / 2.0;
}

View File

@@ -1,26 +1,25 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
frexp(double x, int *exptr)
double frexp(double x, int* exptr)
{
union {
double d;
unsigned char c[8];
} u;
union {
double d;
unsigned char c[8];
} u;
u.d = x;
/*
* The format of the number is:
* Sign, 12 exponent bits, 51 mantissa bits
* The exponent is 1023 biased and there is an implicit zero.
* We get the exponent from the upper bits and set the exponent
* to 0x3fe (1022).
*/
*exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
u.c[7] &= 0x80;
u.c[7] |= 0x3f;
u.c[6] &= 0x0f;
u.c[6] |= 0xe0;
return u.d;
u.d = x;
/*
* The format of the number is:
* Sign, 12 exponent bits, 51 mantissa bits
* The exponent is 1023 biased and there is an implicit zero.
* We get the exponent from the upper bits and set the exponent
* to 0x3fe (1022).
*/
*exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
u.c[7] &= 0x80;
u.c[7] |= 0x3f;
u.c[6] &= 0x0f;
u.c[6] |= 0xe0;
return u.d;
}

View File

@@ -17,84 +17,80 @@
*/
/// #include <float.h>
#include <math.h>
#include <errno.h>
#include <math.h>
/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers
between these two shouldn't neither overflow nor underflow
when squared. */
#define __SQRT_DBL_MAX 1.3e+154
#define __SQRT_DBL_MIN 2.3e-162
double
hypot(double x, double y)
double hypot(double x, double y)
{
double abig = fabs(x), asmall = fabs(y);
double ratio;
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
if (abig < asmall)
{
double temp = abig;
abig = asmall;
asmall = temp;
double abig = fabs(x), asmall = fabs(y);
double ratio;
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
if (abig < asmall) {
double temp = abig;
abig = asmall;
asmall = temp;
}
/* Trivial case. */
if (asmall == 0.)
return abig;
/* Scale the numbers as much as possible by using its ratio.
For example, if both ABIG and ASMALL are VERY small, then
X^2 + Y^2 might be VERY inaccurate due to loss of
significant digits. Dividing ASMALL by ABIG scales them
to a certain degree, so that accuracy is better. */
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
return abig * sqrt(1.0 + ratio*ratio);
else
{
/* Slower but safer algorithm due to Moler and Morrison. Never
produces any intermediate result greater than roughly the
larger of X and Y. Should converge to machine-precision
accuracy in 3 iterations. */
double r = ratio*ratio, t, s, p = abig, q = asmall;
do {
t = 4. + r;
if (t == 4.)
break;
s = r / t;
p += 2. * s * p;
q *= s;
r = (q / p) * (q / p);
} while (1);
return p;
/* Trivial case. */
if (asmall == 0.)
return abig;
/* Scale the numbers as much as possible by using its ratio.
For example, if both ABIG and ASMALL are VERY small, then
X^2 + Y^2 might be VERY inaccurate due to loss of
significant digits. Dividing ASMALL by ABIG scales them
to a certain degree, so that accuracy is better. */
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
return abig * sqrt(1.0 + ratio * ratio);
else {
/* Slower but safer algorithm due to Moler and Morrison. Never
produces any intermediate result greater than roughly the
larger of X and Y. Should converge to machine-precision
accuracy in 3 iterations. */
double r = ratio * ratio, t, s, p = abig, q = asmall;
do {
t = 4. + r;
if (t == 4.)
break;
s = r / t;
p += 2. * s * p;
q *= s;
r = (q / p) * (q / p);
} while (1);
return p;
}
}
#ifdef TEST
#ifdef TEST
#include <stdio.h>
int
main(void)
int main(void)
{
printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.));
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150));
printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306));
printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n",
hypot(3.e-320, 4.e-320));
printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n",
hypot(0.7*DBL_MAX, 0.7*DBL_MAX));
printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0));
printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX));
printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX));
return 0;
printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.));
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150));
printf("hypot(3*10^306, 4*10^306) =\t %25.17g\n", hypot(3.e+306, 4.e+306));
printf("hypot(3*10^-320, 4*10^-320) =\t %25.17g\n",
hypot(3.e-320, 4.e-320));
printf("hypot(0.7*DBL_MAX, 0.7*DBL_MAX) =%25.17g\n",
hypot(0.7 * DBL_MAX, 0.7 * DBL_MAX));
printf("hypot(DBL_MAX, 1.0) =\t\t %25.17g\n", hypot(DBL_MAX, 1.0));
printf("hypot(1.0, DBL_MAX) =\t\t %25.17g\n", hypot(1.0, DBL_MAX));
printf("hypot(0.0, DBL_MAX) =\t\t %25.17g\n", hypot(0.0, DBL_MAX));
return 0;
}
#endif

View File

@@ -2,31 +2,27 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
double
ldexp(double v, int e)
double ldexp(double v, int e)
{
double two = 2.0;
double two = 2.0;
if (e < 0)
{
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0) return 0.0;
while (e > 0)
{
if (e & 1) v /= two;
two *= two;
e >>= 1;
if (e < 0) {
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0)
return 0.0;
while (e > 0) {
if (e & 1)
v /= two;
two *= two;
e >>= 1;
}
} else if (e > 0) {
while (e > 0) {
if (e & 1)
v *= two;
two *= two;
e >>= 1;
}
}
}
else if (e > 0)
{
while (e > 0)
{
if (e & 1) v *= two;
two *= two;
e >>= 1;
}
}
return v;
return v;
}

View File

@@ -3,14 +3,11 @@
double sinh(double x)
{
if(x >= 0.0)
{
const double epos = exp(x);
return (epos - 1.0/epos) / 2.0;
}
else
{
const double eneg = exp(-x);
return (1.0/eneg - eneg) / 2.0;
}
if (x >= 0.0) {
const double epos = exp(x);
return (epos - 1.0 / epos) / 2.0;
} else {
const double eneg = exp(-x);
return (1.0 / eneg - eneg) / 2.0;
}
}

View File

@@ -3,15 +3,13 @@
double tanh(double x)
{
if (x > 50)
return 1;
else if (x < -50)
return -1;
else
{
const double ebig = exp(x);
const double esmall = 1.0/ebig;
return (ebig - esmall) / (ebig + esmall);
}
if (x > 50)
return 1;
else if (x < -50)
return -1;
else {
const double ebig = exp(x);
const double esmall = 1.0 / ebig;
return (ebig - esmall) / (ebig + esmall);
}
}