mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-15 15:20:02 +00:00
Improve cosmo's conformance to libc-test
This change addresses various open source compatibility issues, so that we pass 313/411 of the tests in https://github.com/jart/libc-test where earlier today we were passing about 30/411 of them, due to header toil. Please note that Glibc only passes 341/411 so 313 today is pretty good! - Make the conformance of libc/isystem/ headers nearly perfect - Import more of the remaining math library routines from Musl - Fix inconsistencies with type signatures of calls like umask - Write tests for getpriority/setpriority which work great now - conform to `struct sockaddr *` on remaining socket functions - Import a bunch of uninteresting stdlib functions e.g. rand48 - Introduce readdir_r, scandir, pthread_kill, sigsetjmp, etc.. Follow the instructions in our `tool/scripts/cosmocc` toolchain to run these tests yourself. You use `make CC=cosmocc` on the test repository
This commit is contained in:
parent
467a332e38
commit
e557058ac8
189 changed files with 5091 additions and 884 deletions
|
@ -1,33 +1,101 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
#if FLT_EVAL_METHOD > 1U && LDBL_MANT_DIG == 64
|
||||
#define SPLIT (0x1p32 + 1)
|
||||
#else
|
||||
#define SPLIT (0x1p27 + 1)
|
||||
#endif
|
||||
|
||||
static void sq(double_t *hi, double_t *lo, double x)
|
||||
{
|
||||
double_t xh, xl, xc;
|
||||
|
||||
xc = (double_t)x*SPLIT;
|
||||
xh = x - xc + xc;
|
||||
xl = x - xh;
|
||||
*hi = (double_t)x*x;
|
||||
*lo = xh*xh - *hi + 2*xh*xl + xl*xl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns euclidean distance.
|
||||
*/
|
||||
double hypot(double a, double b) {
|
||||
double r, t;
|
||||
if (isinf(a) || isinf(b)) return INFINITY;
|
||||
a = fabs(a);
|
||||
b = fabs(b);
|
||||
if (a < b) t = b, b = a, a = t;
|
||||
if (!a) return b;
|
||||
r = b / a;
|
||||
return a * sqrt(1 + r * r);
|
||||
double hypot(double x, double y)
|
||||
{
|
||||
union {double f; uint64_t i;} ux = {x}, uy = {y}, ut;
|
||||
int ex, ey;
|
||||
double_t hx, lx, hy, ly, z;
|
||||
|
||||
/* arrange |x| >= |y| */
|
||||
ux.i &= -1ULL>>1;
|
||||
uy.i &= -1ULL>>1;
|
||||
if (ux.i < uy.i) {
|
||||
ut = ux;
|
||||
ux = uy;
|
||||
uy = ut;
|
||||
}
|
||||
|
||||
/* special cases */
|
||||
ex = ux.i>>52;
|
||||
ey = uy.i>>52;
|
||||
x = ux.f;
|
||||
y = uy.f;
|
||||
/* note: hypot(inf,nan) == inf */
|
||||
if (ey == 0x7ff)
|
||||
return y;
|
||||
if (ex == 0x7ff || uy.i == 0)
|
||||
return x;
|
||||
/* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */
|
||||
/* 64 difference is enough for ld80 double_t */
|
||||
if (ex - ey > 64)
|
||||
return x + y;
|
||||
|
||||
/* precise sqrt argument in nearest rounding mode without overflow */
|
||||
/* xh*xh must not overflow and xl*xl must not underflow in sq */
|
||||
z = 1;
|
||||
if (ex > 0x3ff+510) {
|
||||
z = 0x1p700;
|
||||
x *= 0x1p-700;
|
||||
y *= 0x1p-700;
|
||||
} else if (ey < 0x3ff-450) {
|
||||
z = 0x1p-700;
|
||||
x *= 0x1p700;
|
||||
y *= 0x1p700;
|
||||
}
|
||||
sq(&hx, &lx, x);
|
||||
sq(&hy, &ly, y);
|
||||
return z*sqrt(ly+lx+hy+hx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue