Bring back gc() function

Renaming gc() to _gc() was a mistake since the better thing to do is put
it behind the _COSMO_SOURCE macro. We need this change because I haven't
wanted to use my amazing garbage collector ever since we renamed it. You
now need to define _COSMO_SOURCE yourself when using amalgamation header
and cosmocc users need to pass the -mcosmo flag to get the gc() function

Some other issues relating to cancelation have been fixed along the way.
We're also now putting cosmocc in a folder named `.cosmocc` so it can be
more safely excluded by grep --exclude-dir=.cosmocc --exclude-dir=o etc.
This commit is contained in:
Justine Tunney 2024-01-08 10:07:35 -08:00
parent 6cb0354e19
commit a4b455185b
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
280 changed files with 1362 additions and 1407 deletions

View file

@ -20,7 +20,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/alloca.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"

View file

@ -25,7 +25,7 @@
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/stdio/rand.h"

View file

@ -38,7 +38,7 @@ void SetUpOnce(void) {
void Make(const char *path, int mode) {
int fd, n = lemur64() & 0xfffff;
char *data = _gc(malloc(n));
char *data = gc(malloc(n));
rngset(data, n, lemur64, -1);
ASSERT_NE(-1, (fd = creat(path, mode)));
ASSERT_SYS(0, n, write(fd, data, n));
@ -77,8 +77,8 @@ TEST(copy_file_range, test) {
size_t n, m;
Make("foo", 0644);
Copy("foo", "bar");
p = _gc(xslurp("foo", &n));
q = _gc(xslurp("bar", &m));
p = gc(xslurp("foo", &n));
q = gc(xslurp("bar", &m));
ASSERT_EQ(n, m);
ASSERT_EQ(0, memcmp(p, q, n));
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"

View file

@ -23,7 +23,7 @@
#include "libc/errno.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -22,7 +22,7 @@
#include "libc/fmt/libgen.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/serialize.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"

View file

@ -22,7 +22,6 @@
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/errno.h"
#include "libc/serialize.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
@ -30,6 +29,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"
#include "libc/serialize.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
@ -70,7 +70,7 @@ void *TortureWorker(void *arg) {
TEST(getrandom, test) {
int i, n = 999;
double e, w = 7.7;
char *buf = _gc(calloc(1, n));
char *buf = gc(calloc(1, n));
ASSERT_SYS(0, 0, getrandom(0, 0, 0));
ASSERT_SYS(0, n, getrandom(buf, n, 0));
ASSERT_SYS(EFAULT, -1, getrandom(0, n, 0));
@ -92,7 +92,7 @@ TEST(getrandom, test2) {
double e, w = 7.7;
struct sigaction sa;
int i, k, m, n = 999;
char *buf = _gc(calloc(1, n));
char *buf = gc(calloc(1, n));
sa.sa_flags = 0;
sa.sa_handler = OnSig;
sigemptyset(&sa.sa_mask);

View file

@ -20,7 +20,7 @@
#include "libc/calls/internal.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"

View file

@ -20,7 +20,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/assert.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/proc/ntspawn.h"
#include "libc/str/str.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/proc/ntspawn.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#if SupportsWindows()

View file

@ -24,7 +24,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"

View file

@ -96,7 +96,7 @@ TEST(poll, testNegativeOneFd_isIgnored) {
EXPECT_SYS(0, 0, poll(fds, ARRAYLEN(fds), 1));
EXPECT_STREQ("fd:-1 revents:<TODO:kPollNames>\n"
"fd:3 revents:<TODO:kPollNames>\n",
_gc(FormatPollFd(&fds[0])));
gc(FormatPollFd(&fds[0])));
ASSERT_SYS(0, 0, close(3));
}

View file

@ -23,7 +23,7 @@
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"

View file

@ -23,7 +23,7 @@
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"

View file

@ -22,7 +22,7 @@
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"

View file

@ -23,7 +23,7 @@
#include "libc/calls/ucontext.h"
#include "libc/intrin/kprintf.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"

View file

@ -23,7 +23,7 @@
#include "libc/calls/ucontext.h"
#include "libc/intrin/kprintf.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"

View file

@ -25,7 +25,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/nt/files.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -23,7 +23,7 @@
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
@ -55,7 +55,7 @@ TEST(writev, negative_einvalOrEfault) {
TEST(writev, exceedsIovMax_einval) {
if (IsWindows()) return; // it's complicated
int i, n = IOV_MAX + 1;
struct iovec *v = _gc(malloc(sizeof(struct iovec) * n));
struct iovec *v = gc(malloc(sizeof(struct iovec) * n));
for (i = 0; i < n; ++i) {
v[i].iov_base = "x";
v[i].iov_len = 1;

View file

@ -18,7 +18,7 @@
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/libgen.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

View file

@ -19,7 +19,7 @@
#include "libc/fmt/leb128.h"
#include "libc/limits.h"
#include "libc/mem/mem.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
TEST(zleb64, testZero) {

View file

@ -20,7 +20,7 @@
#include "libc/cosmo.h"
#include "libc/dce.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/intrin/popcnt.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"

View file

@ -21,7 +21,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/timespec.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -25,7 +25,7 @@
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"

View file

@ -19,7 +19,7 @@
#include "libc/assert.h"
#include "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/cachesize.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -115,7 +115,7 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
EXPECT_EQ(78 << 8, ws);
ASSERT_TRUE(!!strstr(output, "UNFREED MEMORY"));
if (IsAsan()) {
@ -207,7 +207,7 @@ TEST(ShowCrashReports, testDivideByZero) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
if (IsModeDbg()) {
EXPECT_EQ(77 << 8, ws);
} else {
@ -222,32 +222,32 @@ TEST(ShowCrashReports, testDivideByZero) {
// UBSAN handled it
} else {
// ShowCrashReports() handled it
if (!strstr(output, _gc(xasprintf("%d", pid)))) {
if (!strstr(output, gc(xasprintf("%d", pid)))) {
fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "SIGFPE")) {
fprintf(stderr, "ERROR: crash report didn't have signal name\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
// XXX: WSL doesn't save and restore x87 registers to ucontext_t
if (!__iswsl1()) {
if (!strstr(output, "3.141")) {
fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
if (!strstr(output, "0f0e0d0c0b0a09080706050403020100")) {
fprintf(stderr, "ERROR: crash report didn't have sse register\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "3133731337")) {
fprintf(stderr, "ERROR: crash report didn't have general register\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -332,7 +332,7 @@ TEST(ShowCrashReports, testBssOverrunCrash) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
EXPECT_EQ(77 << 8, ws);
/* NULL is stopgap until we can copy symbol tablces into binary */
#ifdef __FNO_OMIT_FRAME_POINTER__
@ -407,7 +407,7 @@ TEST(ShowCrashReports, testNpeCrash) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
EXPECT_EQ(77 << 8, ws);
/* NULL is stopgap until we can copy symbol tables into binary */
ASSERT_TRUE(!!strstr(output, "null pointer"));
@ -451,7 +451,7 @@ TEST(ShowCrashReports, testDataOverrunCrash) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
EXPECT_EQ(77 << 8, ws);
/* NULL is stopgap until we can copy symbol tablces into binary */
#ifdef __FNO_OMIT_FRAME_POINTER__
@ -499,7 +499,7 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) {
}
close(fds[0]);
ASSERT_NE(-1, wait(&ws));
// tinyprint(2, _gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
// tinyprint(2, gc(IndentLines(output, -1, 0, 4)), "\n", NULL);
if (IsModeDbg()) {
EXPECT_EQ(77 << 8, ws);
} else {
@ -509,13 +509,13 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) {
/* NULL is stopgap until we can copy symbol tables into binary */
if (!strstr(output, IsAsan() ? "null pointer" : "Uncaught SIGSEGV (SEGV_")) {
fprintf(stderr, "ERROR: crash report didn't diagnose the problem\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "NpeCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif

View file

@ -54,9 +54,9 @@ void insertionsort(int32_t *a, size_t n) {
TEST(djbsort, test4) {
static const int kA[] = {4, 3, 2, 1};
n = ARRAYLEN(kA);
a = memcpy(_gc(malloc(n * 4)), kA, n * 4);
b = memcpy(_gc(malloc(n * 4)), kA, n * 4);
c = memcpy(_gc(malloc(n * 4)), kA, n * 4);
a = memcpy(gc(malloc(n * 4)), kA, n * 4);
b = memcpy(gc(malloc(n * 4)), kA, n * 4);
c = memcpy(gc(malloc(n * 4)), kA, n * 4);
insertionsort(a, n);
djbsort_avx2(b, n);
djbsort(c, n);
@ -82,9 +82,9 @@ TEST(djbsort, test64) {
-1323943608, -1219421355, -582289873, 1062699814,
};
n = ARRAYLEN(kA);
a = memcpy(_gc(malloc(n * 4)), kA, n * 4);
b = memcpy(_gc(malloc(n * 4)), kA, n * 4);
c = memcpy(_gc(malloc(n * 4)), kA, n * 4);
a = memcpy(gc(malloc(n * 4)), kA, n * 4);
b = memcpy(gc(malloc(n * 4)), kA, n * 4);
c = memcpy(gc(malloc(n * 4)), kA, n * 4);
insertionsort(a, n);
djbsort(c, n);
ASSERT_EQ(0, memcmp(a, c, n * 4));
@ -104,7 +104,7 @@ static int CompareInt(const void *a, const void *b) {
BENCH(djbsort, bench) {
n = 256;
a = _gc(memalign(32, n * 4));
a = gc(memalign(32, n * 4));
EZBENCH2("insertionsort[255]", rngset(a, n * 4, _rand64, -1),
insertionsort(a, n));
EZBENCH2("djbsort[255]", rngset(a, n * 4, _rand64, -1), djbsort(a, n));

View file

@ -26,7 +26,7 @@
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h"
@ -210,7 +210,7 @@ void *Worker(void *arg) {
BENCH(malloc, torture) {
int i, n = __get_cpu_count() * 2;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
if (!n) return;
printf("\nmalloc torture test w/ %d threads and %d iterations\n", n,
ITERATIONS);

View file

@ -19,7 +19,7 @@
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -18,9 +18,7 @@
*/
#include "libc/log/log.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/gc.internal.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
@ -32,7 +30,7 @@
#ifdef __x86_64__
// TODO(jart): get gclongjmp() working properly on aarch64
#define GC(x) _defer(Free, x)
#define GC(x) defer(Free, x)
char *x;
char *y;
@ -83,7 +81,7 @@ TEST(gclongjmp, test) {
void crawl(const char *path) {
if (!strcmp(path, "/") || !strcmp(path, ".")) return;
crawl(_gc(xdirname(path)));
crawl(gc(xdirname(path)));
}
void *Worker(void *arg) {
@ -99,8 +97,8 @@ TEST(gc, torture) {
}
void crawl2(jmp_buf jb, const char *path) {
if (!strcmp(path, "/") || !strcmp(path, ".")) _gclongjmp(jb, 1);
crawl2(jb, _gc(xdirname(path)));
if (!strcmp(path, "/") || !strcmp(path, ".")) gclongjmp(jb, 1);
crawl2(jb, gc(xdirname(path)));
}
void *Worker2(void *arg) {
@ -111,7 +109,7 @@ void *Worker2(void *arg) {
return 0;
}
TEST(_gclongjmp, torture) {
TEST(gclongjmp, torture) {
int i, n = 32;
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
for (i = 0; i < n; ++i) {

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/check.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/testlib/testlib.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -36,7 +36,7 @@
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/proc/proc.internal.h"
#include "libc/runtime/internal.h"
@ -245,7 +245,7 @@ void *Torturer(void *arg) {
TEST(posix_spawn, agony) {
int i, n = 4;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
testlib_extract("/zip/echo.com", "echo.com", 0755);
for (i = 0; i < n; ++i) {
ASSERT_EQ(0, pthread_create(t + i, 0, Torturer, 0));

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/paths.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
@ -73,7 +73,7 @@ TEST(system, haveShell) {
TEST(system, echo) {
ASSERT_EQ(0, system("echo hello >\"hello there.txt\""));
EXPECT_STREQ("hello\n", _gc(xslurp("hello there.txt", 0)));
EXPECT_STREQ("hello\n", gc(xslurp("hello there.txt", 0)));
}
TEST(system, exit) {
@ -83,13 +83,13 @@ TEST(system, exit) {
TEST(system, testStdoutRedirect) {
testlib_extract("/zip/echo.com", "echo.com", 0755);
ASSERT_EQ(0, system("./echo.com hello >hello.txt"));
EXPECT_STREQ("hello\n", _gc(xslurp("hello.txt", 0)));
EXPECT_STREQ("hello\n", gc(xslurp("hello.txt", 0)));
}
TEST(system, testStdoutRedirect_withSpacesInFilename) {
testlib_extract("/zip/echo.com", "echo.com", 0755);
ASSERT_EQ(0, system("./echo.com hello >\"hello there.txt\""));
EXPECT_STREQ("hello\n", _gc(xslurp("hello there.txt", 0)));
EXPECT_STREQ("hello\n", gc(xslurp("hello there.txt", 0)));
}
TEST(system, testStderrRedirect_toStdout) {

View file

@ -33,8 +33,10 @@ o/$(MODE)/test/libc/release/smoke.o: \
-o $@ \
-c \
-Os \
-Werror \
-fno-pie \
-nostdinc \
-D_COSMO_SOURCE \
-Wl,--gc-sections \
-fno-omit-frame-pointer \
-include o/cosmopolitan.h \
@ -114,10 +116,12 @@ o/$(MODE)/test/libc/release/smoke-chibicc.o: \
-c \
-Os \
-static \
-Werror \
-fno-pie \
-nostdlib \
-nostdinc \
-mno-red-zone \
-D_COSMO_SOURCE \
-fno-omit-frame-pointer \
-include o/cosmopolitan.h \
$<
@ -188,9 +192,11 @@ o/$(MODE)/test/libc/release/smokeansi.o: \
-c \
-Os \
-ansi \
-Werror \
-static \
-fno-pie \
-nostdinc \
-D_COSMO_SOURCE \
-Wl,--gc-sections \
-fno-omit-frame-pointer \
-include o/cosmopolitan.h \

View file

@ -6,8 +6,8 @@ int main(int argc, char *argv[]) {
s = strdup(argv[0]);
s[0] = 'Z';
f = fopen("/dev/null", "w");
fputs(_gc(xiso8601ts(NULL)), f);
fputs(_gc(xasprintf("hello world %d %s\n", argc, s)), f);
/* fputs(gc(xiso8601ts(NULL)), f); */
fputs(gc(xasprintf("hello world %d %s\n", argc, s)), f);
fclose(f);
free(s);
return 0;

View file

@ -1,6 +1,4 @@
int main() {
int rc;
FILE *f;
int *x = new int[32];
x[0] = 2;
x[1] = 2;

View file

@ -35,7 +35,7 @@ TEST(ftrace, test) {
}
const char *ftraceasm;
testlib_extract("/zip/ftraceasm.txt", "ftraceasm.txt", 0755);
ftraceasm = _gc(xslurp("ftraceasm.txt", 0));
ftraceasm = gc(xslurp("ftraceasm.txt", 0));
#ifdef __x86_64__
if (strstr(ftraceasm, "%xmm") || //
strstr(ftraceasm, "%ymm") || //

View file

@ -236,15 +236,15 @@ TEST(isheap, nullPtr) {
}
TEST(isheap, malloc) {
ASSERT_TRUE(_isheap(_gc(malloc(1))));
ASSERT_TRUE(_isheap(gc(malloc(1))));
}
/* TEST(isheap, emptyMalloc) { */
/* ASSERT_TRUE(_isheap(_gc(malloc(0)))); */
/* ASSERT_TRUE(_isheap(gc(malloc(0)))); */
/* } */
/* TEST(isheap, mallocOffset) { */
/* char *p = _gc(malloc(131072)); */
/* char *p = gc(malloc(131072)); */
/* ASSERT_TRUE(_isheap(p + 100000)); */
/* } */

View file

@ -23,7 +23,7 @@
#include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -21,7 +21,7 @@
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"

View file

@ -22,7 +22,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/msghdr.h"

View file

@ -19,7 +19,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"

View file

@ -27,7 +27,7 @@
#include "libc/limits.h"
#include "libc/mem/critbit0.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/internal.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/hex.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -25,7 +25,7 @@
TEST(fcvt, test) {
int decpt, sign;
ASSERT_STREQ("3.14159265358979",
_gc(xasprintf("%.14f", 3.14159265358979323846)));
gc(xasprintf("%.14f", 3.14159265358979323846)));
ASSERT_STREQ("3141592653589793",
fcvt(3.14159265358979323846, 15, &decpt, &sign));
ASSERT_EQ(1, decpt);

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/temp.h"

View file

@ -25,52 +25,52 @@
#include "libc/x/xasprintf.h"
TEST(fmt, d) {
EXPECT_STREQ("-123", _gc(xasprintf("%d", -123)));
EXPECT_STREQ("-1", _gc(xasprintf("%d", -1)));
EXPECT_STREQ("1", _gc(xasprintf("%d", 1)));
EXPECT_STREQ("16", _gc(xasprintf("%d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%d", INT_MIN)));
EXPECT_STREQ(" -123", _gc(xasprintf("%10d", -123)));
EXPECT_STREQ(" -1", _gc(xasprintf("%10d", -1)));
EXPECT_STREQ(" 1", _gc(xasprintf("%10d", 1)));
EXPECT_STREQ(" 16", _gc(xasprintf("%10d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%10d", INT_MIN)));
EXPECT_STREQ("-000000123", _gc(xasprintf("%010d", -123)));
EXPECT_STREQ("-000000001", _gc(xasprintf("%010d", -1)));
EXPECT_STREQ("0000000001", _gc(xasprintf("%010d", 1)));
EXPECT_STREQ("0000000016", _gc(xasprintf("%010d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%010d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%010d", INT_MIN)));
EXPECT_STREQ("-123 ", _gc(xasprintf("%-10d", -123)));
EXPECT_STREQ("-1 ", _gc(xasprintf("%-10d", -1)));
EXPECT_STREQ("1 ", _gc(xasprintf("%-10d", 1)));
EXPECT_STREQ("16 ", _gc(xasprintf("%-10d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%-10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%-10d", INT_MIN)));
EXPECT_STREQ(" -123", _gc(xasprintf("%+10d", -123)));
EXPECT_STREQ(" -1", _gc(xasprintf("%+10d", -1)));
EXPECT_STREQ(" +1", _gc(xasprintf("%+10d", 1)));
EXPECT_STREQ(" +16", _gc(xasprintf("%+10d", 16)));
EXPECT_STREQ("+2147483647", _gc(xasprintf("%+10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%+10d", INT_MIN)));
EXPECT_STREQ("-123", _gc(xasprintf("% d", -123)));
EXPECT_STREQ("-1", _gc(xasprintf("% d", -1)));
EXPECT_STREQ(" 1", _gc(xasprintf("% d", 1)));
EXPECT_STREQ(" 16", _gc(xasprintf("% d", 16)));
EXPECT_STREQ(" 2147483647", _gc(xasprintf("% d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("% d", INT_MIN)));
EXPECT_STREQ("042 ", _gc(xasprintf("%-4.3d", 42)));
EXPECT_STREQ("-00054", _gc(xasprintf("%-1.5lld", -54ll)));
EXPECT_STREQ("00109", _gc(xasprintf("%-.5lld", 109ll)));
EXPECT_STREQ("-00116", _gc(xasprintf("%-.5lld", -116ll)));
EXPECT_STREQ("00108 ", _gc(xasprintf("%-8.5lld", 108ll)));
EXPECT_STREQ("-00054 ", _gc(xasprintf("%-8.5lld", -54ll)));
EXPECT_STREQ("-123", gc(xasprintf("%d", -123)));
EXPECT_STREQ("-1", gc(xasprintf("%d", -1)));
EXPECT_STREQ("1", gc(xasprintf("%d", 1)));
EXPECT_STREQ("16", gc(xasprintf("%d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%d", INT_MIN)));
EXPECT_STREQ(" -123", gc(xasprintf("%10d", -123)));
EXPECT_STREQ(" -1", gc(xasprintf("%10d", -1)));
EXPECT_STREQ(" 1", gc(xasprintf("%10d", 1)));
EXPECT_STREQ(" 16", gc(xasprintf("%10d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%10d", INT_MIN)));
EXPECT_STREQ("-000000123", gc(xasprintf("%010d", -123)));
EXPECT_STREQ("-000000001", gc(xasprintf("%010d", -1)));
EXPECT_STREQ("0000000001", gc(xasprintf("%010d", 1)));
EXPECT_STREQ("0000000016", gc(xasprintf("%010d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%010d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%010d", INT_MIN)));
EXPECT_STREQ("-123 ", gc(xasprintf("%-10d", -123)));
EXPECT_STREQ("-1 ", gc(xasprintf("%-10d", -1)));
EXPECT_STREQ("1 ", gc(xasprintf("%-10d", 1)));
EXPECT_STREQ("16 ", gc(xasprintf("%-10d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%-10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%-10d", INT_MIN)));
EXPECT_STREQ(" -123", gc(xasprintf("%+10d", -123)));
EXPECT_STREQ(" -1", gc(xasprintf("%+10d", -1)));
EXPECT_STREQ(" +1", gc(xasprintf("%+10d", 1)));
EXPECT_STREQ(" +16", gc(xasprintf("%+10d", 16)));
EXPECT_STREQ("+2147483647", gc(xasprintf("%+10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%+10d", INT_MIN)));
EXPECT_STREQ("-123", gc(xasprintf("% d", -123)));
EXPECT_STREQ("-1", gc(xasprintf("% d", -1)));
EXPECT_STREQ(" 1", gc(xasprintf("% d", 1)));
EXPECT_STREQ(" 16", gc(xasprintf("% d", 16)));
EXPECT_STREQ(" 2147483647", gc(xasprintf("% d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("% d", INT_MIN)));
EXPECT_STREQ("042 ", gc(xasprintf("%-4.3d", 42)));
EXPECT_STREQ("-00054", gc(xasprintf("%-1.5lld", -54ll)));
EXPECT_STREQ("00109", gc(xasprintf("%-.5lld", 109ll)));
EXPECT_STREQ("-00116", gc(xasprintf("%-.5lld", -116ll)));
EXPECT_STREQ("00108 ", gc(xasprintf("%-8.5lld", 108ll)));
EXPECT_STREQ("-00054 ", gc(xasprintf("%-8.5lld", -54ll)));
}
TEST(fmt, u) {
EXPECT_STREQ("042 ", _gc(xasprintf("%-4.3u", 42)));
EXPECT_STREQ("042 ", gc(xasprintf("%-4.3u", 42)));
}
TEST(fmt, c) {
@ -92,314 +92,309 @@ TEST(fmt, c) {
}
TEST(fmt, x) {
EXPECT_STREQ("0x01 ", _gc(xasprintf("%#-07.2x", 1)));
EXPECT_STREQ("0x00136d ", _gc(xasprintf("%#-010.6x", 4973)));
EXPECT_STREQ("0X1", _gc(xasprintf("%#X", 1)));
EXPECT_STREQ("0XA", _gc(xasprintf("%#X", 10)));
EXPECT_STREQ("0XFFFF", _gc(xasprintf("%#X", 65535)));
EXPECT_STREQ("0XABCDEF", _gc(xasprintf("%#X", 0xABCDEF)));
EXPECT_STREQ("0X1", _gc(xasprintf("%#hX", (short)1)));
EXPECT_STREQ("0XA", _gc(xasprintf("%#hX", (short)10)));
EXPECT_STREQ("0XFFFF", _gc(xasprintf("%#hX", (short)65535)));
EXPECT_STREQ("0XABCD", _gc(xasprintf("%#hX", (short)0xABCD)));
EXPECT_STREQ(" 0X308C6705", _gc(xasprintf("%#20X", 814507781)));
EXPECT_STREQ("0X0000000000308C6705", _gc(xasprintf("%#020X", 814507781)));
EXPECT_STREQ("0x01 ", gc(xasprintf("%#-07.2x", 1)));
EXPECT_STREQ("0x00136d ", gc(xasprintf("%#-010.6x", 4973)));
EXPECT_STREQ("0X1", gc(xasprintf("%#X", 1)));
EXPECT_STREQ("0XA", gc(xasprintf("%#X", 10)));
EXPECT_STREQ("0XFFFF", gc(xasprintf("%#X", 65535)));
EXPECT_STREQ("0XABCDEF", gc(xasprintf("%#X", 0xABCDEF)));
EXPECT_STREQ("0X1", gc(xasprintf("%#hX", (short)1)));
EXPECT_STREQ("0XA", gc(xasprintf("%#hX", (short)10)));
EXPECT_STREQ("0XFFFF", gc(xasprintf("%#hX", (short)65535)));
EXPECT_STREQ("0XABCD", gc(xasprintf("%#hX", (short)0xABCD)));
EXPECT_STREQ(" 0X308C6705", gc(xasprintf("%#20X", 814507781)));
EXPECT_STREQ("0X0000000000308C6705", gc(xasprintf("%#020X", 814507781)));
EXPECT_STREQ(" 0X6705",
_gc(xasprintf("%#20hX", (short)814507781)));
gc(xasprintf("%#20hX", (short)814507781)));
EXPECT_STREQ("0X000000000000006705",
_gc(xasprintf("%#020hX", (short)814507781)));
EXPECT_STREQ(" 0XABCDEF", _gc(xasprintf("%#20X", 0xABCDEF)));
EXPECT_STREQ("0X000000000000ABCDEF", _gc(xasprintf("%#020X", 0xABCDEF)));
gc(xasprintf("%#020hX", (short)814507781)));
EXPECT_STREQ(" 0XABCDEF", gc(xasprintf("%#20X", 0xABCDEF)));
EXPECT_STREQ("0X000000000000ABCDEF", gc(xasprintf("%#020X", 0xABCDEF)));
EXPECT_STREQ(" 0XCDEF",
_gc(xasprintf("%#20hX", (short)0xABCDEF)));
gc(xasprintf("%#20hX", (short)0xABCDEF)));
EXPECT_STREQ("0X00000000000000CDEF",
_gc(xasprintf("%#020hX", (short)0xABCDEF)));
gc(xasprintf("%#020hX", (short)0xABCDEF)));
}
TEST(fmt, o) {
EXPECT_STREQ("0000000000000037777777634", _gc(xasprintf("%#.25o", -100)));
EXPECT_STREQ("0001777777777777777777634", _gc(xasprintf("%#.25lo", -100L)));
EXPECT_STREQ("0001777777777777777777634", _gc(xasprintf("%#.25llo", -100LL)));
EXPECT_STREQ("0", _gc(xasprintf("%#.o", 0)));
EXPECT_STREQ(" 056520", _gc(xasprintf("%#8.6o", 23888)));
EXPECT_STREQ("00144 ", _gc(xasprintf("%#-8.5llo", 100ll)));
EXPECT_STREQ("0 ", _gc(xasprintf("%-#02lo", 0l)));
EXPECT_STREQ("0", _gc(xasprintf("%#01lo", 0l)));
EXPECT_STREQ("00", _gc(xasprintf("%#02lo", 0l)));
EXPECT_STREQ("0000000000000037777777634", gc(xasprintf("%#.25o", -100)));
EXPECT_STREQ("0001777777777777777777634", gc(xasprintf("%#.25lo", -100L)));
EXPECT_STREQ("0001777777777777777777634", gc(xasprintf("%#.25llo", -100LL)));
EXPECT_STREQ("0", gc(xasprintf("%#.o", 0)));
EXPECT_STREQ(" 056520", gc(xasprintf("%#8.6o", 23888)));
EXPECT_STREQ("00144 ", gc(xasprintf("%#-8.5llo", 100ll)));
EXPECT_STREQ("0 ", gc(xasprintf("%-#02lo", 0l)));
EXPECT_STREQ("0", gc(xasprintf("%#01lo", 0l)));
EXPECT_STREQ("00", gc(xasprintf("%#02lo", 0l)));
}
TEST(fmt, b) {
EXPECT_STREQ("000010100 ", _gc(xasprintf("%-14.9b", 20)));
EXPECT_STREQ("0b110", _gc(xasprintf("%#b", 6)));
EXPECT_STREQ("000010100 ", gc(xasprintf("%-14.9b", 20)));
EXPECT_STREQ("0b110", gc(xasprintf("%#b", 6)));
}
TEST(fmt, s) {
EXPECT_STREQ("123456", _gc(xasprintf("%4.*s", -5, "123456")));
EXPECT_STREQ("123456789", _gc(xasprintf("%4.*s", -5, "123456789")));
EXPECT_STREQ("123456", gc(xasprintf("%4.*s", -5, "123456")));
EXPECT_STREQ("123456789", gc(xasprintf("%4.*s", -5, "123456789")));
EXPECT_STREQ("12345678901234567890",
_gc(xasprintf("%4.*s", -5, "12345678901234567890")));
gc(xasprintf("%4.*s", -5, "12345678901234567890")));
EXPECT_STREQ("123456789012345678901234567890",
_gc(xasprintf("%4.*s", -5, "123456789012345678901234567890")));
gc(xasprintf("%4.*s", -5, "123456789012345678901234567890")));
EXPECT_STREQ(
"1234567890123456789012345678901234567890",
_gc(xasprintf("%4.*s", -5, "1234567890123456789012345678901234567890")));
gc(xasprintf("%4.*s", -5, "1234567890123456789012345678901234567890")));
EXPECT_STREQ(
"12345678901234567890123456789012345678901234567890",
_gc(xasprintf("%4.*s", -5,
"12345678901234567890123456789012345678901234567890")));
gc(xasprintf("%4.*s", -5,
"12345678901234567890123456789012345678901234567890")));
EXPECT_STREQ(
"123456789012345678901234567890123456789012345678901234567890",
_gc(xasprintf(
gc(xasprintf(
"%4.*s", -5,
"123456789012345678901234567890123456789012345678901234567890")));
EXPECT_STREQ("Wide character output test",
_gc(xasprintf("%S", L"Wide character output test")));
gc(xasprintf("%S", L"Wide character output test")));
}
TEST(fmt, g) {
EXPECT_STREQ("1", _gc(xasprintf("%g", 1.)));
EXPECT_STREQ(" 1", _gc(xasprintf("% g", 1.)));
EXPECT_STREQ("+1", _gc(xasprintf("%+g", 1.)));
EXPECT_STREQ("-1", _gc(xasprintf("%g", -1.)));
EXPECT_STREQ("10", _gc(xasprintf("%g", 10.)));
EXPECT_STREQ("-10", _gc(xasprintf("%g", -10.)));
EXPECT_STREQ("1e+01", _gc(xasprintf("%.0g", 10.)));
EXPECT_STREQ("-1e+01", _gc(xasprintf("%.0g", -10.)));
EXPECT_STREQ("1", _gc(xasprintf("%.0g", 1.0)));
EXPECT_STREQ("1e-05", _gc(xasprintf("%.0g", 0.00001)));
EXPECT_STREQ("0.0001", _gc(xasprintf("%.0g", 0.0001)));
EXPECT_STREQ("1e+01", _gc(xasprintf("%.1g", 10.)));
EXPECT_STREQ("-1e+01", _gc(xasprintf("%.1g", -10.)));
EXPECT_STREQ("1", _gc(xasprintf("%.1g", 1.0)));
EXPECT_STREQ("1e-05", _gc(xasprintf("%.1g", 0.00001)));
EXPECT_STREQ("0.0001", _gc(xasprintf("%.1g", 0.0001)));
EXPECT_STREQ("0.007812", _gc(xasprintf("%.4g", 0.0078125)));
EXPECT_STREQ("0.023438", _gc(xasprintf("%.5g", 0.0234375)));
EXPECT_STREQ("1e+100", _gc(xasprintf("%g", 1e100)));
EXPECT_STREQ("1e-100", _gc(xasprintf("%g", 1e-100)));
EXPECT_STREQ("-1e-100", _gc(xasprintf("%g", -1e-100)));
EXPECT_STREQ("0.123456", _gc(xasprintf("%g", 0.1234564)));
EXPECT_STREQ("0.123457", _gc(xasprintf("%g", 0.1234566)));
EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0", _gc(xasprintf("%g", 0.)));
EXPECT_STREQ("-0", _gc(xasprintf("%g", -0.)));
EXPECT_STREQ("nan", _gc(xasprintf("%g", NAN)));
EXPECT_STREQ("-nan", _gc(xasprintf("%g", -NAN)));
EXPECT_STREQ("inf", _gc(xasprintf("%g", INFINITY)));
EXPECT_STREQ("-inf", _gc(xasprintf("%g", -INFINITY)));
EXPECT_STREQ("2.22507e-308", _gc(xasprintf("%g", __DBL_MIN__)));
EXPECT_STREQ("1.79769e+308", _gc(xasprintf("%g", __DBL_MAX__)));
EXPECT_STREQ("0", _gc(xasprintf("%G", 0.)));
EXPECT_STREQ("-0", _gc(xasprintf("%G", -0.)));
EXPECT_STREQ("NAN", _gc(xasprintf("%G", NAN)));
EXPECT_STREQ("-NAN", _gc(xasprintf("%G", -NAN)));
EXPECT_STREQ("INF", _gc(xasprintf("%G", INFINITY)));
EXPECT_STREQ("-INF", _gc(xasprintf("%G", -INFINITY)));
EXPECT_STREQ("2.22507E-308", _gc(xasprintf("%G", __DBL_MIN__)));
EXPECT_STREQ("1.79769E+308", _gc(xasprintf("%G", __DBL_MAX__)));
EXPECT_STREQ(" 0", _gc(xasprintf("%13g", 0.)));
EXPECT_STREQ(" -0", _gc(xasprintf("%13g", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%13g", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%13g", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%13g", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%13g", -INFINITY)));
EXPECT_STREQ(" 2.22507e-308", _gc(xasprintf("%13g", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769e+308", _gc(xasprintf("%13g", __DBL_MAX__)));
EXPECT_STREQ(" 0", _gc(xasprintf("%13G", 0.)));
EXPECT_STREQ(" -0", _gc(xasprintf("%13G", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%13G", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%13G", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%13G", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%13G", -INFINITY)));
EXPECT_STREQ(" 2.22507E-308", _gc(xasprintf("%13G", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769E+308", _gc(xasprintf("%13G", __DBL_MAX__)));
EXPECT_STREQ("1", gc(xasprintf("%g", 1.)));
EXPECT_STREQ(" 1", gc(xasprintf("% g", 1.)));
EXPECT_STREQ("+1", gc(xasprintf("%+g", 1.)));
EXPECT_STREQ("-1", gc(xasprintf("%g", -1.)));
EXPECT_STREQ("10", gc(xasprintf("%g", 10.)));
EXPECT_STREQ("-10", gc(xasprintf("%g", -10.)));
EXPECT_STREQ("1e+01", gc(xasprintf("%.0g", 10.)));
EXPECT_STREQ("-1e+01", gc(xasprintf("%.0g", -10.)));
EXPECT_STREQ("1", gc(xasprintf("%.0g", 1.0)));
EXPECT_STREQ("1e-05", gc(xasprintf("%.0g", 0.00001)));
EXPECT_STREQ("0.0001", gc(xasprintf("%.0g", 0.0001)));
EXPECT_STREQ("1e+01", gc(xasprintf("%.1g", 10.)));
EXPECT_STREQ("-1e+01", gc(xasprintf("%.1g", -10.)));
EXPECT_STREQ("1", gc(xasprintf("%.1g", 1.0)));
EXPECT_STREQ("1e-05", gc(xasprintf("%.1g", 0.00001)));
EXPECT_STREQ("0.0001", gc(xasprintf("%.1g", 0.0001)));
EXPECT_STREQ("0.007812", gc(xasprintf("%.4g", 0.0078125)));
EXPECT_STREQ("0.023438", gc(xasprintf("%.5g", 0.0234375)));
EXPECT_STREQ("1e+100", gc(xasprintf("%g", 1e100)));
EXPECT_STREQ("1e-100", gc(xasprintf("%g", 1e-100)));
EXPECT_STREQ("-1e-100", gc(xasprintf("%g", -1e-100)));
EXPECT_STREQ("0.123456", gc(xasprintf("%g", 0.1234564)));
EXPECT_STREQ("0.123457", gc(xasprintf("%g", 0.1234566)));
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0", gc(xasprintf("%g", 0.)));
EXPECT_STREQ("-0", gc(xasprintf("%g", -0.)));
EXPECT_STREQ("nan", gc(xasprintf("%g", NAN)));
EXPECT_STREQ("-nan", gc(xasprintf("%g", -NAN)));
EXPECT_STREQ("inf", gc(xasprintf("%g", INFINITY)));
EXPECT_STREQ("-inf", gc(xasprintf("%g", -INFINITY)));
EXPECT_STREQ("2.22507e-308", gc(xasprintf("%g", __DBL_MIN__)));
EXPECT_STREQ("1.79769e+308", gc(xasprintf("%g", __DBL_MAX__)));
EXPECT_STREQ("0", gc(xasprintf("%G", 0.)));
EXPECT_STREQ("-0", gc(xasprintf("%G", -0.)));
EXPECT_STREQ("NAN", gc(xasprintf("%G", NAN)));
EXPECT_STREQ("-NAN", gc(xasprintf("%G", -NAN)));
EXPECT_STREQ("INF", gc(xasprintf("%G", INFINITY)));
EXPECT_STREQ("-INF", gc(xasprintf("%G", -INFINITY)));
EXPECT_STREQ("2.22507E-308", gc(xasprintf("%G", __DBL_MIN__)));
EXPECT_STREQ("1.79769E+308", gc(xasprintf("%G", __DBL_MAX__)));
EXPECT_STREQ(" 0", gc(xasprintf("%13g", 0.)));
EXPECT_STREQ(" -0", gc(xasprintf("%13g", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%13g", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%13g", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%13g", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%13g", -INFINITY)));
EXPECT_STREQ(" 2.22507e-308", gc(xasprintf("%13g", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769e+308", gc(xasprintf("%13g", __DBL_MAX__)));
EXPECT_STREQ(" 0", gc(xasprintf("%13G", 0.)));
EXPECT_STREQ(" -0", gc(xasprintf("%13G", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%13G", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%13G", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%13G", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%13G", -INFINITY)));
EXPECT_STREQ(" 2.22507E-308", gc(xasprintf("%13G", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769E+308", gc(xasprintf("%13G", __DBL_MAX__)));
}
TEST(fmt, f) {
EXPECT_STREQ("3.141593", _gc(xasprintf("%f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.141593", gc(xasprintf("%f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.1415926535897931",
_gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1)));
gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("100000000000000001590289110975991804683608085639452813"
"89781327557747838772170381060813469985856815104.000000",
_gc(xasprintf("%f", 1e100)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%f", 0.)));
EXPECT_STREQ("-0.000000", _gc(xasprintf("%f", -0.)));
EXPECT_STREQ("nan", _gc(xasprintf("%f", NAN)));
EXPECT_STREQ("-nan", _gc(xasprintf("%f", -NAN)));
EXPECT_STREQ("inf", _gc(xasprintf("%f", INFINITY)));
EXPECT_STREQ("-inf", _gc(xasprintf("%f", -INFINITY)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%f", __DBL_MIN__)));
gc(xasprintf("%f", 1e100)));
EXPECT_STREQ("0.000000", gc(xasprintf("%f", 0.)));
EXPECT_STREQ("-0.000000", gc(xasprintf("%f", -0.)));
EXPECT_STREQ("nan", gc(xasprintf("%f", NAN)));
EXPECT_STREQ("-nan", gc(xasprintf("%f", -NAN)));
EXPECT_STREQ("inf", gc(xasprintf("%f", INFINITY)));
EXPECT_STREQ("-inf", gc(xasprintf("%f", -INFINITY)));
EXPECT_STREQ("0.000000", gc(xasprintf("%f", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
_gc(xasprintf("%f", __DBL_MAX__)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%F", 0.)));
EXPECT_STREQ("-0.000000", _gc(xasprintf("%F", -0.)));
EXPECT_STREQ("NAN", _gc(xasprintf("%F", NAN)));
EXPECT_STREQ("-NAN", _gc(xasprintf("%F", -NAN)));
EXPECT_STREQ("INF", _gc(xasprintf("%F", INFINITY)));
EXPECT_STREQ("-INF", _gc(xasprintf("%F", -INFINITY)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%F", __DBL_MIN__)));
gc(xasprintf("%f", __DBL_MAX__)));
EXPECT_STREQ("0.000000", gc(xasprintf("%F", 0.)));
EXPECT_STREQ("-0.000000", gc(xasprintf("%F", -0.)));
EXPECT_STREQ("NAN", gc(xasprintf("%F", NAN)));
EXPECT_STREQ("-NAN", gc(xasprintf("%F", -NAN)));
EXPECT_STREQ("INF", gc(xasprintf("%F", INFINITY)));
EXPECT_STREQ("-INF", gc(xasprintf("%F", -INFINITY)));
EXPECT_STREQ("0.000000", gc(xasprintf("%F", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
_gc(xasprintf("%F", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", 0.)));
EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10f", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%10f", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%10f", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%10f", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%10f", -INFINITY)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", __DBL_MIN__)));
gc(xasprintf("%F", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", 0.)));
EXPECT_STREQ(" -0.000000", gc(xasprintf("%10f", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%10f", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%10f", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%10f", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%10f", -INFINITY)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
_gc(xasprintf("%10f", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", 0.)));
EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10F", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%10F", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%10F", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%10F", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%10F", -INFINITY)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", __DBL_MIN__)));
gc(xasprintf("%10f", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", 0.)));
EXPECT_STREQ(" -0.000000", gc(xasprintf("%10F", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%10F", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%10F", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%10F", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%10F", -INFINITY)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
_gc(xasprintf("%10F", __DBL_MAX__)));
gc(xasprintf("%10F", __DBL_MAX__)));
}
TEST(fmt, e) {
EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.141592653589793",
_gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("1.000000e+100", _gc(xasprintf("%e", 1e100)));
EXPECT_STREQ("1.000000E+100", _gc(xasprintf("%E", 1e100)));
EXPECT_STREQ(" 0.000000e+00", _gc(xasprintf("%24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%24e", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%24e", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%24e", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%24e", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%24e", -INFINITY)));
EXPECT_STREQ(" 2.225074e-308", _gc(xasprintf("%24e", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693e+308", _gc(xasprintf("%24e", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000E+00", _gc(xasprintf("%24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%24E", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%24E", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%24E", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%24E", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%24E", -INFINITY)));
EXPECT_STREQ(" 2.225074E-308", _gc(xasprintf("%24E", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693E+308", _gc(xasprintf("%24E", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000e+00", _gc(xasprintf("%+24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%+24e", -0.)));
EXPECT_STREQ(" +nan", _gc(xasprintf("%+24e", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%+24e", -NAN)));
EXPECT_STREQ(" +inf", _gc(xasprintf("%+24e", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%+24e", -INFINITY)));
EXPECT_STREQ(" +2.225074e-308",
_gc(xasprintf("%+24e", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693e+308",
_gc(xasprintf("%+24e", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000E+00", _gc(xasprintf("%+24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%+24E", -0.)));
EXPECT_STREQ(" +NAN", _gc(xasprintf("%+24E", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%+24E", -NAN)));
EXPECT_STREQ(" +INF", _gc(xasprintf("%+24E", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%+24E", -INFINITY)));
EXPECT_STREQ(" +2.225074E-308",
_gc(xasprintf("%+24E", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693E+308",
_gc(xasprintf("%+24E", __DBL_MAX__)));
gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("1.000000e+100", gc(xasprintf("%e", 1e100)));
EXPECT_STREQ("1.000000E+100", gc(xasprintf("%E", 1e100)));
EXPECT_STREQ(" 0.000000e+00", gc(xasprintf("%24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%24e", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%24e", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%24e", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%24e", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%24e", -INFINITY)));
EXPECT_STREQ(" 2.225074e-308", gc(xasprintf("%24e", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693e+308", gc(xasprintf("%24e", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000E+00", gc(xasprintf("%24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%24E", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%24E", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%24E", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%24E", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%24E", -INFINITY)));
EXPECT_STREQ(" 2.225074E-308", gc(xasprintf("%24E", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693E+308", gc(xasprintf("%24E", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000e+00", gc(xasprintf("%+24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%+24e", -0.)));
EXPECT_STREQ(" +nan", gc(xasprintf("%+24e", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%+24e", -NAN)));
EXPECT_STREQ(" +inf", gc(xasprintf("%+24e", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%+24e", -INFINITY)));
EXPECT_STREQ(" +2.225074e-308", gc(xasprintf("%+24e", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693e+308", gc(xasprintf("%+24e", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000E+00", gc(xasprintf("%+24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%+24E", -0.)));
EXPECT_STREQ(" +NAN", gc(xasprintf("%+24E", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%+24E", -NAN)));
EXPECT_STREQ(" +INF", gc(xasprintf("%+24E", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%+24E", -INFINITY)));
EXPECT_STREQ(" +2.225074E-308", gc(xasprintf("%+24E", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693E+308", gc(xasprintf("%+24E", __DBL_MAX__)));
}
TEST(fmt, a) {
EXPECT_STREQ("0x0p+0", _gc(xasprintf("%a", 0.)));
EXPECT_STREQ("0x0p+0", _gc(xasprintf("%.a", 0.)));
EXPECT_STREQ(" 0x0p+0", _gc(xasprintf("%7.a", 0.)));
EXPECT_STREQ("0x0.000p+0", _gc(xasprintf("%.3a", 0.)));
// EXPECT_STREQ(" 0x0.000p+0\n", _gc(xasprintf("%11.3a\n", 0.))); // TODO
EXPECT_STREQ("inf\n", _gc(xasprintf("%g\n", INFINITY)));
EXPECT_STREQ(" inf\n", _gc(xasprintf("%5g\n", INFINITY)));
EXPECT_STREQ(" +inf\n", _gc(xasprintf("%+5g\n", INFINITY)));
EXPECT_STREQ(" inf\n", _gc(xasprintf("% g\n", INFINITY)));
EXPECT_STREQ("-inf\n", _gc(xasprintf("% g\n", -INFINITY)));
EXPECT_STREQ("0x0p+0", gc(xasprintf("%a", 0.)));
EXPECT_STREQ("0x0p+0", gc(xasprintf("%.a", 0.)));
EXPECT_STREQ(" 0x0p+0", gc(xasprintf("%7.a", 0.)));
EXPECT_STREQ("0x0.000p+0", gc(xasprintf("%.3a", 0.)));
// EXPECT_STREQ(" 0x0.000p+0\n", gc(xasprintf("%11.3a\n", 0.))); // TODO
EXPECT_STREQ("inf\n", gc(xasprintf("%g\n", INFINITY)));
EXPECT_STREQ(" inf\n", gc(xasprintf("%5g\n", INFINITY)));
EXPECT_STREQ(" +inf\n", gc(xasprintf("%+5g\n", INFINITY)));
EXPECT_STREQ(" inf\n", gc(xasprintf("% g\n", INFINITY)));
EXPECT_STREQ("-inf\n", gc(xasprintf("% g\n", -INFINITY)));
EXPECT_STREQ("0x1.921fb54442d18p+1",
_gc(xasprintf("%a", 0x1.921fb54442d1846ap+1)));
gc(xasprintf("%a", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0X1.921FB54442D18P+1",
_gc(xasprintf("%A", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ(" 0x0p+0", _gc(xasprintf("%24a", 0.)));
EXPECT_STREQ(" -0x0p+0", _gc(xasprintf("%24a", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%24a", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%24a", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%24a", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%24a", -INFINITY)));
EXPECT_STREQ(" 0x1p-1022", _gc(xasprintf("%24a", __DBL_MIN__)));
EXPECT_STREQ(" 0x1.fffffffffffffp+1023", _gc(xasprintf("%24a", __DBL_MAX__)));
EXPECT_STREQ(" 0X0P+0", _gc(xasprintf("%24A", 0.)));
EXPECT_STREQ(" -0X0P+0", _gc(xasprintf("%24A", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%24A", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%24A", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%24A", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%24A", -INFINITY)));
EXPECT_STREQ(" 0X1P-1022", _gc(xasprintf("%24A", __DBL_MIN__)));
EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", _gc(xasprintf("%24A", __DBL_MAX__)));
EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", 31337.1337)));
EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", -31337.1337)));
gc(xasprintf("%A", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ(" 0x0p+0", gc(xasprintf("%24a", 0.)));
EXPECT_STREQ(" -0x0p+0", gc(xasprintf("%24a", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%24a", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%24a", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%24a", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%24a", -INFINITY)));
EXPECT_STREQ(" 0x1p-1022", gc(xasprintf("%24a", __DBL_MIN__)));
EXPECT_STREQ(" 0x1.fffffffffffffp+1023", gc(xasprintf("%24a", __DBL_MAX__)));
EXPECT_STREQ(" 0X0P+0", gc(xasprintf("%24A", 0.)));
EXPECT_STREQ(" -0X0P+0", gc(xasprintf("%24A", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%24A", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%24A", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%24A", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%24A", -INFINITY)));
EXPECT_STREQ(" 0X1P-1022", gc(xasprintf("%24A", __DBL_MIN__)));
EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", gc(xasprintf("%24A", __DBL_MAX__)));
EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", 31337.1337)));
EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", -31337.1337)));
}
TEST(fmt, p) {
EXPECT_STREQ("0x1", _gc(xasprintf("%p", 1)));
EXPECT_STREQ("0x10", _gc(xasprintf("%p", 16)));
EXPECT_STREQ("0x31337", _gc(xasprintf("%p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", _gc(xasprintf("%p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("%10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("%10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("%10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%10p", 0xffffffff)));
EXPECT_STREQ("0x1", gc(xasprintf("%p", 1)));
EXPECT_STREQ("0x10", gc(xasprintf("%p", 16)));
EXPECT_STREQ("0x31337", gc(xasprintf("%p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("%10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("%10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("%10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%10p", 0xffff800000031337)));
EXPECT_STREQ("0x00000001", gc(xasprintf("%010p", 1)));
EXPECT_STREQ("0x00000010", gc(xasprintf("%010p", 16)));
EXPECT_STREQ("0x00031337", gc(xasprintf("%010p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%010p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("%10p", 0xffff800000031337)));
EXPECT_STREQ("0x00000001", _gc(xasprintf("%010p", 1)));
EXPECT_STREQ("0x00000010", _gc(xasprintf("%010p", 16)));
EXPECT_STREQ("0x00031337", _gc(xasprintf("%010p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%010p", 0xffffffff)));
gc(xasprintf("%010p", 0xffff800000031337)));
EXPECT_STREQ("0x1 ", gc(xasprintf("%-10p", 1)));
EXPECT_STREQ("0x10 ", gc(xasprintf("%-10p", 16)));
EXPECT_STREQ("0x31337 ", gc(xasprintf("%-10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%-10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("%010p", 0xffff800000031337)));
EXPECT_STREQ("0x1 ", _gc(xasprintf("%-10p", 1)));
EXPECT_STREQ("0x10 ", _gc(xasprintf("%-10p", 16)));
EXPECT_STREQ("0x31337 ", _gc(xasprintf("%-10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%-10p", 0xffffffff)));
gc(xasprintf("%-10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("%+10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("%+10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("%+10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%+10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("%-10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("%+10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("%+10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("%+10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%+10p", 0xffffffff)));
gc(xasprintf("%+10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("% 10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("% 10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("% 10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("% 10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("%+10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("% 10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("% 10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("% 10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("% 10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("% 10p", 0xffff800000031337)));
gc(xasprintf("% 10p", 0xffff800000031337)));
}
TEST(fmt, quoted) {
ASSERT_STREQ(" \"hello\"", _gc(xasprintf("%`*.*s", 10, 5, "hello")));
ASSERT_STREQ("\"hello\" ", _gc(xasprintf("%-`*.*s", 10, 5, "hello")));
ASSERT_STREQ(" \"hello\"", gc(xasprintf("%`*.*s", 10, 5, "hello")));
ASSERT_STREQ("\"hello\" ", gc(xasprintf("%-`*.*s", 10, 5, "hello")));
}
TEST(fmt, nulCharacter) {

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"
#include "libc/x/xasprintf.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"

View file

@ -21,7 +21,7 @@
#include "libc/calls/struct/sigset.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"

View file

@ -64,7 +64,7 @@ TEST(getentropy, test) {
double e, w = 7.7;
struct sigaction sa;
int i, k, m, n = 999;
char *buf = _gc(calloc(1, n));
char *buf = gc(calloc(1, n));
sa.sa_flags = 0;
sa.sa_handler = OnSig;
sigemptyset(&sa.sa_mask);

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/stdio/iconv.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/stdio/stdio.h"

View file

@ -19,7 +19,7 @@
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"

View file

@ -39,7 +39,7 @@
#include "libc/x/xasprintf.h"
char buffer[1000];
/* #define Format(...) _gc(xasprintf(__VA_ARGS__)) */
/* #define Format(...) gc(xasprintf(__VA_ARGS__)) */
#define Format(...) (snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
TEST(sprintf, test_space_flag) {
@ -572,13 +572,13 @@ TEST(xasprintf, hugeNtoa) {
ASSERT_STREQ(
"0b1111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111",
_gc(xasprintf("%#jjb", UINT128_MAX)));
gc(xasprintf("%#jjb", UINT128_MAX)));
}
TEST(xasprintf, twosBane) {
ASSERT_STREQ("-2147483648", _gc(xasprintf("%d", 0x80000000)));
ASSERT_STREQ("-2147483648", gc(xasprintf("%d", 0x80000000)));
ASSERT_STREQ("-9223372036854775808",
_gc(xasprintf("%ld", 0x8000000000000000)));
gc(xasprintf("%ld", 0x8000000000000000)));
}
TEST(snprintf, testFixedWidthString_wontOverrunInput) {

View file

@ -162,7 +162,7 @@ TEST(popen, torture) {
return;
}
int i, n = 4;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
testlib_extract("/zip/echo.com", "echo.com", 0755);
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_join(t[i], 0));

View file

@ -22,7 +22,7 @@
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#define Format(...) _gc(xasprintf(__VA_ARGS__))
#define Format(...) gc(xasprintf(__VA_ARGS__))
/**
* @fileoverview String formatting tests.

View file

@ -88,7 +88,7 @@ TEST(tmpfile, renameToRealFile) {
f = tmpfile();
ASSERT_EQ(2, fputs("hi", f));
ASSERT_SYS(0, 0,
linkat(AT_FDCWD, _gc(xasprintf("/proc/self/fd/%d", fileno(f))),
linkat(AT_FDCWD, gc(xasprintf("/proc/self/fd/%d", fileno(f))),
AT_FDCWD, "real", AT_SYMLINK_FOLLOW));
ASSERT_EQ(0, fclose(f));
ASSERT_NE(NULL, (f = fopen("real", "r")));

View file

@ -21,7 +21,7 @@
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -19,7 +19,7 @@
#include "libc/assert.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "third_party/regex/regex.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -19,7 +19,7 @@
#include "libc/str/str.h"
#include "libc/dce.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/tab.internal.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -19,7 +19,7 @@
#include "libc/str/str.h"
#include "libc/dce.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/testlib/ezbench.h"

View file

@ -20,7 +20,7 @@
#include "libc/calls/ucontext.h"
#include "libc/dce.h"
#include "libc/limits.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"

View file

@ -20,7 +20,7 @@
#include "libc/atomic.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"

View file

@ -232,7 +232,7 @@ void *CpuBoundWorker(void *arg) {
wontleak1 = malloc(123);
(void)wontleak1;
pthread_cleanup_push(free, wontleak1);
wontleak2 = _gc(malloc(123));
wontleak2 = gc(malloc(123));
(void)wontleak2;
ASSERT_EQ(0, pthread_setspecific(key, (void *)31337));
ASSERT_EQ(0, pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0));

View file

@ -29,7 +29,7 @@
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/nexgen32e/vendor.internal.h"
@ -177,8 +177,8 @@ TEST(pthread_create, testCustomStack_withReallySmallSize) {
void *JoinMainWorker(void *arg) {
void *rc;
pthread_t main_thread = (pthread_t)arg;
_gc(malloc(32));
_gc(malloc(32));
gc(malloc(32));
gc(malloc(32));
ASSERT_EQ(0, pthread_join(main_thread, &rc));
ASSERT_EQ(123, (intptr_t)rc);
return 0;
@ -186,8 +186,8 @@ void *JoinMainWorker(void *arg) {
TEST(pthread_join, mainThread) {
pthread_t id;
_gc(malloc(32));
_gc(malloc(32));
gc(malloc(32));
gc(malloc(32));
SPAWN(fork);
ASSERT_EQ(0, pthread_create(&id, 0, JoinMainWorker, (void *)pthread_self()));
pthread_exit((void *)123);
@ -196,8 +196,8 @@ TEST(pthread_join, mainThread) {
TEST(pthread_join, mainThreadDelayed) {
pthread_t id;
_gc(malloc(32));
_gc(malloc(32));
gc(malloc(32));
gc(malloc(32));
SPAWN(fork);
ASSERT_EQ(0, pthread_create(&id, 0, JoinMainWorker, (void *)pthread_self()));
usleep(10000);

View file

@ -18,7 +18,7 @@
*/
#include "libc/atomic.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"

View file

@ -86,7 +86,7 @@ void *Worker(void *arg) {
TEST(sem_open, test) {
sem_t *a, *b;
int i, r, n = 8;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
errno = 0;
ASSERT_EQ(0, pthread_barrier_init(&barrier, 0, n));
ASSERT_NE(SEM_FAILED, (a = sem_open(name1, O_CREAT, 0644, 0)));

View file

@ -104,7 +104,7 @@ void *Worker(void *arg) {
TEST(sem_timedwait, threads) {
int i, r, n = 4;
sem_t sm[2], *s[2] = {sm, sm + 1};
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
ASSERT_SYS(0, 0, sem_init(s[0], 0, 0));
ASSERT_SYS(0, 0, sem_init(s[1], 0, 0));
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, s));

View file

@ -28,12 +28,12 @@ float _acosf(float) asm("acosf");
long double _acosl(long double) asm("acosl");
TEST(acos, test) {
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _acos(0.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _acos(-0.))));
EXPECT_STREQ("1.0471975511966", _gc(xasprintf("%.15g", _acos(.5))));
EXPECT_STREQ("2.0943951023932", _gc(xasprintf("%.15g", _acos(-.5))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _acos(1.))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", _acos(-1.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _acos(0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _acos(-0.))));
EXPECT_STREQ("1.0471975511966", gc(xasprintf("%.15g", _acos(.5))));
EXPECT_STREQ("2.0943951023932", gc(xasprintf("%.15g", _acos(-.5))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _acos(1.))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", _acos(-1.))));
EXPECT_TRUE(isnan(_acos(1.5)));
EXPECT_TRUE(isnan(_acos(-1.5)));
EXPECT_TRUE(isnan(_acos(2.)));
@ -41,7 +41,7 @@ TEST(acos, test) {
EXPECT_TRUE(isnan(_acos(-NAN)));
EXPECT_TRUE(isnan(_acos(INFINITY)));
EXPECT_TRUE(isnan(_acos(-INFINITY)));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _acos(__DBL_MIN__))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _acos(__DBL_MIN__))));
EXPECT_TRUE(isnan(_acos(__DBL_MAX__)));
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

View file

@ -27,12 +27,12 @@ double asin_(double) asm("asin");
#define asin asin_
TEST(asin, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", asin(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", asin(-0.))));
EXPECT_STREQ("0.523598775598299", _gc(xasprintf("%.15g", asin(.5))));
EXPECT_STREQ("-0.523598775598299", _gc(xasprintf("%.15g", asin(-.5))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", asin(1.))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", asin(-1.))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", asin(0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", asin(-0.))));
EXPECT_STREQ("0.523598775598299", gc(xasprintf("%.15g", asin(.5))));
EXPECT_STREQ("-0.523598775598299", gc(xasprintf("%.15g", asin(-.5))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", asin(1.))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", asin(-1.))));
EXPECT_TRUE(isnan(asin(1.5)));
EXPECT_TRUE(isnan(asin(-1.5)));
EXPECT_TRUE(isnan(asin(NAN)));
@ -40,7 +40,7 @@ TEST(asin, test) {
EXPECT_TRUE(isnan(asin(INFINITY)));
EXPECT_TRUE(isnan(asin(-INFINITY)));
EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", asin(__DBL_MIN__))));
gc(xasprintf("%.15g", asin(__DBL_MIN__))));
EXPECT_TRUE(isnan(asin(__DBL_MAX__)));
}

View file

@ -28,29 +28,29 @@ float _asinhf(float) asm("asinhf");
long double _asinhl(long double) asm("asinhl");
TEST(asinh, test) {
EXPECT_STREQ(".481211825059603", _gc(xdtoa(_asinh(+.5))));
EXPECT_STREQ("-.481211825059603", _gc(xdtoa(_asinh(-.5))));
EXPECT_STREQ("0", _gc(xdtoa(_asinh(0))));
EXPECT_STREQ("NAN", _gc(xdtoa(_asinh(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(_asinh(INFINITY))));
EXPECT_STREQ(".481211825059603", gc(xdtoa(_asinh(+.5))));
EXPECT_STREQ("-.481211825059603", gc(xdtoa(_asinh(-.5))));
EXPECT_STREQ("0", gc(xdtoa(_asinh(0))));
EXPECT_STREQ("NAN", gc(xdtoa(_asinh(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(_asinh(INFINITY))));
EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", _asinh(-2.1073424255447e-08))));
gc(xasprintf("%.15g", _asinh(-2.1073424255447e-08))));
}
TEST(asinhf, test) {
EXPECT_STREQ(".481212", _gc(xdtoaf(_asinhf(+.5))));
EXPECT_STREQ("-.481212", _gc(xdtoaf(_asinhf(-.5))));
EXPECT_STREQ("0", _gc(xdtoaf(_asinhf(0))));
EXPECT_STREQ("NAN", _gc(xdtoaf(_asinhf(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(_asinhf(INFINITY))));
EXPECT_STREQ(".481212", gc(xdtoaf(_asinhf(+.5))));
EXPECT_STREQ("-.481212", gc(xdtoaf(_asinhf(-.5))));
EXPECT_STREQ("0", gc(xdtoaf(_asinhf(0))));
EXPECT_STREQ("NAN", gc(xdtoaf(_asinhf(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(_asinhf(INFINITY))));
}
TEST(asinhl, test) {
EXPECT_STREQ(".4812118250596034", _gc(xdtoal(_asinhl(+.5))));
EXPECT_STREQ("-.4812118250596034", _gc(xdtoal(_asinhl(-.5))));
EXPECT_STREQ("0", _gc(xdtoal(_asinhl(0))));
EXPECT_STREQ("NAN", _gc(xdtoal(_asinhl(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(_asinhl(INFINITY))));
EXPECT_STREQ(".4812118250596034", gc(xdtoal(_asinhl(+.5))));
EXPECT_STREQ("-.4812118250596034", gc(xdtoal(_asinhl(-.5))));
EXPECT_STREQ("0", gc(xdtoal(_asinhl(0))));
EXPECT_STREQ("NAN", gc(xdtoal(_asinhl(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(_asinhl(INFINITY))));
}
BENCH(asinh, bench) {

View file

@ -27,145 +27,143 @@ float _atan2f(float, float) asm("atan2f");
long double _atan2l(long double, long double) asm("atan2l");
TEST(atan2, yx) {
EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", atan(-.5 / 1.5))));
EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", _atan2(-.5, 1.5))));
EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", atan(-.5 / 1.5))));
EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", _atan2(-.5, 1.5))));
}
TEST(atan2, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., 0.))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", _atan2(0., -0.))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., .5))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", _atan2(0., -.5))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., 1.))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", _atan2(0., -1.))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., 1.5))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", _atan2(0., -1.5))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., 0.))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", _atan2(0., -0.))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., .5))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", _atan2(0., -.5))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., 1.))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", _atan2(0., -1.))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., 1.5))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", _atan2(0., -1.5))));
EXPECT_TRUE(isnan(_atan2(0., NAN)));
EXPECT_TRUE(isnan(_atan2(0., -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(0., -INFINITY))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., __DBL_MIN__))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(0., __DBL_MAX__))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., 0.))));
EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", _atan2(-0., -0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., .5))));
EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", _atan2(-0., -.5))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., 1.))));
EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", _atan2(-0., -1.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., 1.5))));
EXPECT_STREQ("-3.14159265358979", _gc(xasprintf("%.15g", _atan2(-0., -1.5))));
gc(xasprintf("%.15g", _atan2(0., -INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., __DBL_MIN__))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(0., __DBL_MAX__))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., 0.))));
EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", _atan2(-0., -0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., .5))));
EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", _atan2(-0., -.5))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., 1.))));
EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", _atan2(-0., -1.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., 1.5))));
EXPECT_STREQ("-3.14159265358979", gc(xasprintf("%.15g", _atan2(-0., -1.5))));
EXPECT_TRUE(isnan(_atan2(-0., NAN)));
EXPECT_TRUE(isnan(_atan2(-0., -NAN)));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., INFINITY))));
EXPECT_STREQ("-3.14159265358979",
_gc(xasprintf("%.15g", _atan2(-0., -INFINITY))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., __DBL_MIN__))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-0., __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(.5, 0.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(.5, -0.))));
EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", _atan2(.5, .5))));
EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", _atan2(.5, -.5))));
EXPECT_STREQ("0.463647609000806", _gc(xasprintf("%.15g", _atan2(.5, 1.))));
EXPECT_STREQ("2.67794504458899", _gc(xasprintf("%.15g", _atan2(.5, -1.))));
EXPECT_STREQ("0.321750554396642", _gc(xasprintf("%.15g", _atan2(.5, 1.5))));
EXPECT_STREQ("2.81984209919315", _gc(xasprintf("%.15g", _atan2(.5, -1.5))));
gc(xasprintf("%.15g", _atan2(-0., -INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., __DBL_MIN__))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-0., __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(.5, 0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(.5, -0.))));
EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", _atan2(.5, .5))));
EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", _atan2(.5, -.5))));
EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", _atan2(.5, 1.))));
EXPECT_STREQ("2.67794504458899", gc(xasprintf("%.15g", _atan2(.5, -1.))));
EXPECT_STREQ("0.321750554396642", gc(xasprintf("%.15g", _atan2(.5, 1.5))));
EXPECT_STREQ("2.81984209919315", gc(xasprintf("%.15g", _atan2(.5, -1.5))));
EXPECT_TRUE(isnan(_atan2(.5, NAN)));
EXPECT_TRUE(isnan(_atan2(.5, -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(.5, INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(.5, INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(.5, -INFINITY))));
gc(xasprintf("%.15g", _atan2(.5, -INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(.5, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(.5, __DBL_MIN__))));
EXPECT_STREQ("2.781342323134e-309",
_gc(xasprintf("%.15g", _atan2(.5, __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-.5, 0.))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-.5, -0.))));
EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", _atan2(-.5, .5))));
EXPECT_STREQ("-2.35619449019234", _gc(xasprintf("%.15g", _atan2(-.5, -.5))));
EXPECT_STREQ("-0.463647609000806", _gc(xasprintf("%.15g", _atan2(-.5, 1.))));
EXPECT_STREQ("-2.67794504458899", _gc(xasprintf("%.15g", _atan2(-.5, -1.))));
EXPECT_STREQ("-0.321750554396642", _gc(xasprintf("%.15g", _atan2(-.5, 1.5))));
EXPECT_STREQ("-2.81984209919315", _gc(xasprintf("%.15g", _atan2(-.5, -1.5))));
gc(xasprintf("%.15g", _atan2(.5, __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-.5, 0.))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-.5, -0.))));
EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", _atan2(-.5, .5))));
EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", _atan2(-.5, -.5))));
EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", _atan2(-.5, 1.))));
EXPECT_STREQ("-2.67794504458899", gc(xasprintf("%.15g", _atan2(-.5, -1.))));
EXPECT_STREQ("-0.321750554396642", gc(xasprintf("%.15g", _atan2(-.5, 1.5))));
EXPECT_STREQ("-2.81984209919315", gc(xasprintf("%.15g", _atan2(-.5, -1.5))));
EXPECT_TRUE(isnan(_atan2(-.5, NAN)));
EXPECT_TRUE(isnan(_atan2(-.5, -NAN)));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-.5, INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-.5, INFINITY))));
EXPECT_STREQ("-3.14159265358979",
_gc(xasprintf("%.15g", _atan2(-.5, -INFINITY))));
gc(xasprintf("%.15g", _atan2(-.5, -INFINITY))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-.5, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(-.5, __DBL_MIN__))));
EXPECT_STREQ("-2.781342323134e-309",
_gc(xasprintf("%.15g", _atan2(-.5, __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(1., 0.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(1., -0.))));
EXPECT_STREQ("1.10714871779409", _gc(xasprintf("%.15g", _atan2(1., .5))));
EXPECT_STREQ("2.0344439357957", _gc(xasprintf("%.15g", _atan2(1., -.5))));
EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", _atan2(1., 1.))));
EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", _atan2(1., -1.))));
EXPECT_STREQ("0.588002603547568", _gc(xasprintf("%.15g", _atan2(1., 1.5))));
EXPECT_STREQ("2.55359005004223", _gc(xasprintf("%.15g", _atan2(1., -1.5))));
gc(xasprintf("%.15g", _atan2(-.5, __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(1., 0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(1., -0.))));
EXPECT_STREQ("1.10714871779409", gc(xasprintf("%.15g", _atan2(1., .5))));
EXPECT_STREQ("2.0344439357957", gc(xasprintf("%.15g", _atan2(1., -.5))));
EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", _atan2(1., 1.))));
EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", _atan2(1., -1.))));
EXPECT_STREQ("0.588002603547568", gc(xasprintf("%.15g", _atan2(1., 1.5))));
EXPECT_STREQ("2.55359005004223", gc(xasprintf("%.15g", _atan2(1., -1.5))));
EXPECT_TRUE(isnan(_atan2(1., NAN)));
EXPECT_TRUE(isnan(_atan2(1., -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(1., INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(1., INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(1., -INFINITY))));
gc(xasprintf("%.15g", _atan2(1., -INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(1., __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(1., __DBL_MIN__))));
EXPECT_STREQ("5.562684646268e-309",
_gc(xasprintf("%.15g", _atan2(1., __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-1., 0.))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-1., -0.))));
EXPECT_STREQ("-1.10714871779409", _gc(xasprintf("%.15g", _atan2(-1., .5))));
EXPECT_STREQ("-2.0344439357957", _gc(xasprintf("%.15g", _atan2(-1., -.5))));
EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", _atan2(-1., 1.))));
EXPECT_STREQ("-2.35619449019234", _gc(xasprintf("%.15g", _atan2(-1., -1.))));
EXPECT_STREQ("-0.588002603547568", _gc(xasprintf("%.15g", _atan2(-1., 1.5))));
EXPECT_STREQ("-2.55359005004223", _gc(xasprintf("%.15g", _atan2(-1., -1.5))));
gc(xasprintf("%.15g", _atan2(1., __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-1., 0.))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-1., -0.))));
EXPECT_STREQ("-1.10714871779409", gc(xasprintf("%.15g", _atan2(-1., .5))));
EXPECT_STREQ("-2.0344439357957", gc(xasprintf("%.15g", _atan2(-1., -.5))));
EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", _atan2(-1., 1.))));
EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", _atan2(-1., -1.))));
EXPECT_STREQ("-0.588002603547568", gc(xasprintf("%.15g", _atan2(-1., 1.5))));
EXPECT_STREQ("-2.55359005004223", gc(xasprintf("%.15g", _atan2(-1., -1.5))));
EXPECT_TRUE(isnan(_atan2(-1., NAN)));
EXPECT_TRUE(isnan(_atan2(-1., -NAN)));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-1., INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-1., INFINITY))));
EXPECT_STREQ("-3.14159265358979",
_gc(xasprintf("%.15g", _atan2(-1., -INFINITY))));
gc(xasprintf("%.15g", _atan2(-1., -INFINITY))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-1., __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(-1., __DBL_MIN__))));
EXPECT_STREQ("-5.562684646268e-309",
_gc(xasprintf("%.15g", _atan2(-1., __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(1.5, 0.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", _atan2(1.5, -0.))));
EXPECT_STREQ("1.24904577239825", _gc(xasprintf("%.15g", _atan2(1.5, .5))));
EXPECT_STREQ("1.89254688119154", _gc(xasprintf("%.15g", _atan2(1.5, -.5))));
EXPECT_STREQ("0.982793723247329", _gc(xasprintf("%.15g", _atan2(1.5, 1.))));
EXPECT_STREQ("2.15879893034246", _gc(xasprintf("%.15g", _atan2(1.5, -1.))));
EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", _atan2(1.5, 1.5))));
EXPECT_STREQ("2.35619449019234", _gc(xasprintf("%.15g", _atan2(1.5, -1.5))));
gc(xasprintf("%.15g", _atan2(-1., __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(1.5, 0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(1.5, -0.))));
EXPECT_STREQ("1.24904577239825", gc(xasprintf("%.15g", _atan2(1.5, .5))));
EXPECT_STREQ("1.89254688119154", gc(xasprintf("%.15g", _atan2(1.5, -.5))));
EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", _atan2(1.5, 1.))));
EXPECT_STREQ("2.15879893034246", gc(xasprintf("%.15g", _atan2(1.5, -1.))));
EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", _atan2(1.5, 1.5))));
EXPECT_STREQ("2.35619449019234", gc(xasprintf("%.15g", _atan2(1.5, -1.5))));
EXPECT_TRUE(isnan(_atan2(1.5, NAN)));
EXPECT_TRUE(isnan(_atan2(1.5, -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(1.5, INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(1.5, INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(1.5, -INFINITY))));
gc(xasprintf("%.15g", _atan2(1.5, -INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(1.5, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(1.5, __DBL_MIN__))));
EXPECT_STREQ("8.34402696940201e-309",
_gc(xasprintf("%.15g", _atan2(1.5, __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-1.5, 0.))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", _atan2(-1.5, -0.))));
EXPECT_STREQ("-1.24904577239825", _gc(xasprintf("%.15g", _atan2(-1.5, .5))));
EXPECT_STREQ("-1.89254688119154", _gc(xasprintf("%.15g", _atan2(-1.5, -.5))));
EXPECT_STREQ("-0.982793723247329", _gc(xasprintf("%.15g", _atan2(-1.5, 1.))));
EXPECT_STREQ("-2.15879893034246", _gc(xasprintf("%.15g", _atan2(-1.5, -1.))));
EXPECT_STREQ("-0.785398163397448",
_gc(xasprintf("%.15g", _atan2(-1.5, 1.5))));
EXPECT_STREQ("-2.35619449019234",
_gc(xasprintf("%.15g", _atan2(-1.5, -1.5))));
gc(xasprintf("%.15g", _atan2(1.5, __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-1.5, 0.))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", _atan2(-1.5, -0.))));
EXPECT_STREQ("-1.24904577239825", gc(xasprintf("%.15g", _atan2(-1.5, .5))));
EXPECT_STREQ("-1.89254688119154", gc(xasprintf("%.15g", _atan2(-1.5, -.5))));
EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", _atan2(-1.5, 1.))));
EXPECT_STREQ("-2.15879893034246", gc(xasprintf("%.15g", _atan2(-1.5, -1.))));
EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", _atan2(-1.5, 1.5))));
EXPECT_STREQ("-2.35619449019234", gc(xasprintf("%.15g", _atan2(-1.5, -1.5))));
EXPECT_TRUE(isnan(_atan2(-1.5, NAN)));
EXPECT_TRUE(isnan(_atan2(-1.5, -NAN)));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-1.5, INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-1.5, INFINITY))));
EXPECT_STREQ("-3.14159265358979",
_gc(xasprintf("%.15g", _atan2(-1.5, -INFINITY))));
gc(xasprintf("%.15g", _atan2(-1.5, -INFINITY))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-1.5, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(-1.5, __DBL_MIN__))));
EXPECT_STREQ("-8.34402696940201e-309",
_gc(xasprintf("%.15g", _atan2(-1.5, __DBL_MAX__))));
gc(xasprintf("%.15g", _atan2(-1.5, __DBL_MAX__))));
EXPECT_TRUE(isnan(_atan2(NAN, 0.)));
EXPECT_TRUE(isnan(_atan2(NAN, -0.)));
EXPECT_TRUE(isnan(_atan2(NAN, .5)));
@ -194,114 +192,111 @@ TEST(atan2, test) {
EXPECT_TRUE(isnan(_atan2(-NAN, -INFINITY)));
EXPECT_TRUE(isnan(_atan2(-NAN, __DBL_MIN__)));
EXPECT_TRUE(isnan(_atan2(-NAN, __DBL_MAX__)));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(INFINITY, 0.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, 0.))));
gc(xasprintf("%.15g", _atan2(INFINITY, -0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(INFINITY, .5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, -0.))));
gc(xasprintf("%.15g", _atan2(INFINITY, -.5))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", _atan2(INFINITY, 1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, .5))));
gc(xasprintf("%.15g", _atan2(INFINITY, -1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, -.5))));
gc(xasprintf("%.15g", _atan2(INFINITY, 1.5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, 1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, -1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, 1.5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, -1.5))));
gc(xasprintf("%.15g", _atan2(INFINITY, -1.5))));
EXPECT_TRUE(isnan(_atan2(INFINITY, NAN)));
EXPECT_TRUE(isnan(_atan2(INFINITY, -NAN)));
EXPECT_STREQ("0.785398163397448",
_gc(xasprintf("%.15g", _atan2(INFINITY, INFINITY))));
gc(xasprintf("%.15g", _atan2(INFINITY, INFINITY))));
EXPECT_STREQ("2.35619449019234",
_gc(xasprintf("%.15g", _atan2(INFINITY, -INFINITY))));
gc(xasprintf("%.15g", _atan2(INFINITY, -INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(INFINITY, __DBL_MIN__))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(INFINITY, __DBL_MAX__))));
gc(xasprintf("%.15g", _atan2(INFINITY, __DBL_MAX__))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, 0.))));
gc(xasprintf("%.15g", _atan2(-INFINITY, 0.))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, -0.))));
gc(xasprintf("%.15g", _atan2(-INFINITY, -0.))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, .5))));
gc(xasprintf("%.15g", _atan2(-INFINITY, .5))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, -.5))));
gc(xasprintf("%.15g", _atan2(-INFINITY, -.5))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, 1.))));
gc(xasprintf("%.15g", _atan2(-INFINITY, 1.))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, -1.))));
gc(xasprintf("%.15g", _atan2(-INFINITY, -1.))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, 1.5))));
gc(xasprintf("%.15g", _atan2(-INFINITY, 1.5))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, -1.5))));
gc(xasprintf("%.15g", _atan2(-INFINITY, -1.5))));
EXPECT_TRUE(isnan(_atan2(-INFINITY, NAN)));
EXPECT_TRUE(isnan(_atan2(-INFINITY, -NAN)));
EXPECT_STREQ("-0.785398163397448",
_gc(xasprintf("%.15g", _atan2(-INFINITY, INFINITY))));
gc(xasprintf("%.15g", _atan2(-INFINITY, INFINITY))));
EXPECT_STREQ("-2.35619449019234",
_gc(xasprintf("%.15g", _atan2(-INFINITY, -INFINITY))));
gc(xasprintf("%.15g", _atan2(-INFINITY, -INFINITY))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(-INFINITY, __DBL_MIN__))));
EXPECT_STREQ("-1.5707963267949",
_gc(xasprintf("%.15g", _atan2(-INFINITY, __DBL_MAX__))));
gc(xasprintf("%.15g", _atan2(-INFINITY, __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 0.))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 0.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -0.))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -0.))));
EXPECT_STREQ("4.4501477170144e-308",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, .5))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, .5))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -.5))));
EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 1.))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 1.))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -1.))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -1.))));
EXPECT_STREQ("1.48338257233813e-308",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 1.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, 1.5))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -1.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -1.5))));
EXPECT_TRUE(isnan(_atan2(__DBL_MIN__, NAN)));
EXPECT_TRUE(isnan(_atan2(__DBL_MIN__, -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(__DBL_MIN__, INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(__DBL_MIN__, INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -INFINITY))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, -INFINITY))));
EXPECT_STREQ("0.785398163397448",
_gc(xasprintf("%.15g", _atan2(__DBL_MIN__, __DBL_MIN__))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(__DBL_MIN__, __DBL_MAX__))));
gc(xasprintf("%.15g", _atan2(__DBL_MIN__, __DBL_MIN__))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(__DBL_MIN__, __DBL_MAX__))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 0.))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 0.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -0.))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -0.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, .5))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, .5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -.5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 1.))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -1.))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -1.))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 1.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, 1.5))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -1.5))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -1.5))));
EXPECT_TRUE(isnan(_atan2(__DBL_MAX__, NAN)));
EXPECT_TRUE(isnan(_atan2(__DBL_MAX__, -NAN)));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _atan2(__DBL_MAX__, INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _atan2(__DBL_MAX__, INFINITY))));
EXPECT_STREQ("3.14159265358979",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -INFINITY))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, -INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, __DBL_MIN__))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, __DBL_MIN__))));
EXPECT_STREQ("0.785398163397448",
_gc(xasprintf("%.15g", _atan2(__DBL_MAX__, __DBL_MAX__))));
gc(xasprintf("%.15g", _atan2(__DBL_MAX__, __DBL_MAX__))));
EXPECT_STREQ("-0",
_gc(xasprintf("%.15g", _atan2(-0.000000000000001, INFINITY))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _atan2(-1, INFINITY))));
gc(xasprintf("%.15g", _atan2(-0.000000000000001, INFINITY))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _atan2(-1, INFINITY))));
EXPECT_STREQ(
"-0", _gc(xasprintf("%.15g", _atan2(-1.7976931348623157e308, INFINITY))));
"-0", gc(xasprintf("%.15g", _atan2(-1.7976931348623157e308, INFINITY))));
EXPECT_STREQ("1.5707963267949",
_gc(xasprintf("%.15g", _atan2(1.4142135623731, 0))));
gc(xasprintf("%.15g", _atan2(1.4142135623731, 0))));
}
BENCH(atan2, bench) {

View file

@ -25,35 +25,35 @@
TEST(atan2l, test) {
volatile double a = -.9816175436063843;
volatile double b = -.1908585813741899;
EXPECT_STREQ("-2.95", _gc(xasprintf("%.2f", atan2f(b, a))));
EXPECT_STREQ("-2.95", _gc(xasprintf("%.2f", atan2(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2f(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2(b, a))));
#ifndef __aarch64__
// TODO: implement quad floating point into printf
EXPECT_STREQ("-2.95", _gc(xasprintf("%.2Lf", atan2l(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2Lf", atan2l(b, a))));
#endif
}
TEST(atan2, testSpecialCases) {
ASSERT_STREQ("NAN", _gc(xdtoa(atan2(NAN, 0))));
ASSERT_STREQ("NAN", _gc(xdtoa(atan2(0, NAN))));
ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +0.))));
ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +1.))));
ASSERT_STREQ("0", _gc(xdtoa(atan2(+0., +2.))));
ASSERT_STREQ("0", _gc(xdtoa(atan2(1, INFINITY))));
ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -0.))));
ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -1.))));
ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(+0., -2.))));
ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-1., -0.))));
ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-1., +0.))));
ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-2., -0.))));
ASSERT_STREQ("-1.570796326794897", _gc(xdtoal(atan2(-2., +0.))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+1., -0.))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+1., +0.))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+2., -0.))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(+2., +0.))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(INFINITY, 1))));
ASSERT_STREQ("1.570796326794897", _gc(xdtoal(atan2(INFINITY, -1))));
ASSERT_STREQ("3.141592653589793", _gc(xdtoal(atan2(1, -INFINITY))));
ASSERT_STREQ("2.356194490192345", _gc(xdtoal(atan2(INFINITY, -INFINITY))));
ASSERT_STREQ(".7853981633974483", _gc(xdtoal(atan2(INFINITY, INFINITY))));
ASSERT_STREQ("NAN", gc(xdtoa(atan2(NAN, 0))));
ASSERT_STREQ("NAN", gc(xdtoa(atan2(0, NAN))));
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +0.))));
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +1.))));
ASSERT_STREQ("0", gc(xdtoa(atan2(+0., +2.))));
ASSERT_STREQ("0", gc(xdtoa(atan2(1, INFINITY))));
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -0.))));
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -1.))));
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(+0., -2.))));
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., -0.))));
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-1., +0.))));
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., -0.))));
ASSERT_STREQ("-1.570796326794897", gc(xdtoal(atan2(-2., +0.))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., -0.))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+1., +0.))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., -0.))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(+2., +0.))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, 1))));
ASSERT_STREQ("1.570796326794897", gc(xdtoal(atan2(INFINITY, -1))));
ASSERT_STREQ("3.141592653589793", gc(xdtoal(atan2(1, -INFINITY))));
ASSERT_STREQ("2.356194490192345", gc(xdtoal(atan2(INFINITY, -INFINITY))));
ASSERT_STREQ(".7853981633974483", gc(xdtoal(atan2(INFINITY, INFINITY))));
}

View file

@ -23,21 +23,21 @@
#include "libc/x/xasprintf.h"
TEST(atan, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", atan(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", atan(-0.))));
EXPECT_STREQ("0.463647609000806", _gc(xasprintf("%.15g", atan(.5))));
EXPECT_STREQ("-0.463647609000806", _gc(xasprintf("%.15g", atan(-.5))));
EXPECT_STREQ("0.785398163397448", _gc(xasprintf("%.15g", atan(1.))));
EXPECT_STREQ("-0.785398163397448", _gc(xasprintf("%.15g", atan(-1.))));
EXPECT_STREQ("0.982793723247329", _gc(xasprintf("%.15g", atan(1.5))));
EXPECT_STREQ("-0.982793723247329", _gc(xasprintf("%.15g", atan(-1.5))));
EXPECT_STREQ("nan", _gc(xasprintf("%.15g", atan(NAN))));
EXPECT_STREQ("-nan", _gc(xasprintf("%.15g", atan(-NAN))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan(INFINITY))));
EXPECT_STREQ("-1.5707963267949", _gc(xasprintf("%.15g", atan(-INFINITY))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", atan(0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", atan(-0.))));
EXPECT_STREQ("0.463647609000806", gc(xasprintf("%.15g", atan(.5))));
EXPECT_STREQ("-0.463647609000806", gc(xasprintf("%.15g", atan(-.5))));
EXPECT_STREQ("0.785398163397448", gc(xasprintf("%.15g", atan(1.))));
EXPECT_STREQ("-0.785398163397448", gc(xasprintf("%.15g", atan(-1.))));
EXPECT_STREQ("0.982793723247329", gc(xasprintf("%.15g", atan(1.5))));
EXPECT_STREQ("-0.982793723247329", gc(xasprintf("%.15g", atan(-1.5))));
EXPECT_STREQ("nan", gc(xasprintf("%.15g", atan(NAN))));
EXPECT_STREQ("-nan", gc(xasprintf("%.15g", atan(-NAN))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(INFINITY))));
EXPECT_STREQ("-1.5707963267949", gc(xasprintf("%.15g", atan(-INFINITY))));
EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", atan(__DBL_MIN__))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", atan(__DBL_MAX__))));
gc(xasprintf("%.15g", atan(__DBL_MIN__))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", atan(__DBL_MAX__))));
}
BENCH(atanl, bench) {

View file

@ -28,36 +28,36 @@ float _atanhf(float) asm("atanhf");
long double _atanhl(long double) asm("atanhl");
TEST(atanh, test) {
EXPECT_STREQ("0", _gc(xdtoa(_atanh(0))));
EXPECT_STREQ("-0", _gc(xdtoa(_atanh(-0.))));
EXPECT_STREQ(".549306144334055", _gc(xdtoa(_atanh(.5))));
EXPECT_STREQ("-.549306144334055", _gc(xdtoa(_atanh(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(_atanh(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoa(_atanh(-1))));
EXPECT_STREQ("0", gc(xdtoa(_atanh(0))));
EXPECT_STREQ("-0", gc(xdtoa(_atanh(-0.))));
EXPECT_STREQ(".549306144334055", gc(xdtoa(_atanh(.5))));
EXPECT_STREQ("-.549306144334055", gc(xdtoa(_atanh(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoa(_atanh(+1))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(_atanh(-1))));
EXPECT_TRUE(isnan(_atanh(+1.1)));
EXPECT_TRUE(isnan(_atanh(-1.1)));
EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", _atanh(-2.1073424255447e-08))));
gc(xasprintf("%.15g", _atanh(-2.1073424255447e-08))));
}
TEST(atanhl, test) {
EXPECT_STREQ("0", _gc(xdtoal(_atanhl(0))));
EXPECT_STREQ("-0", _gc(xdtoal(_atanhl(-0.))));
EXPECT_STREQ(".5493061443340548", _gc(xdtoal(_atanhl(.5))));
EXPECT_STREQ("-.5493061443340548", _gc(xdtoal(_atanhl(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(_atanhl(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoal(_atanhl(-1))));
EXPECT_STREQ("0", gc(xdtoal(_atanhl(0))));
EXPECT_STREQ("-0", gc(xdtoal(_atanhl(-0.))));
EXPECT_STREQ(".5493061443340548", gc(xdtoal(_atanhl(.5))));
EXPECT_STREQ("-.5493061443340548", gc(xdtoal(_atanhl(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoal(_atanhl(+1))));
EXPECT_STREQ("-INFINITY", gc(xdtoal(_atanhl(-1))));
EXPECT_TRUE(isnan(_atanhl(+1.1)));
EXPECT_TRUE(isnan(_atanhl(-1.1)));
}
TEST(atanhf, test) {
EXPECT_STREQ("0", _gc(xdtoaf(_atanhf(0))));
EXPECT_STREQ("-0", _gc(xdtoaf(_atanhf(-0.))));
EXPECT_STREQ(".549306", _gc(xdtoaf(_atanhf(.5))));
EXPECT_STREQ("-.549306", _gc(xdtoaf(_atanhf(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(_atanhf(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoaf(_atanhf(-1))));
EXPECT_STREQ("0", gc(xdtoaf(_atanhf(0))));
EXPECT_STREQ("-0", gc(xdtoaf(_atanhf(-0.))));
EXPECT_STREQ(".549306", gc(xdtoaf(_atanhf(.5))));
EXPECT_STREQ("-.549306", gc(xdtoaf(_atanhf(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(_atanhf(+1))));
EXPECT_STREQ("-INFINITY", gc(xdtoaf(_atanhf(-1))));
EXPECT_TRUE(isnan(_atanhf(+1.1)));
EXPECT_TRUE(isnan(_atanhf(-1.1)));
}

Some files were not shown because too many files have changed in this diff Show more