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

@ -28,50 +28,50 @@ float _sinf(float) asm("sinf");
long double _sinl(long double) asm("sinl");
TEST(sinl, test) {
EXPECT_STREQ("NAN", _gc(xdtoal(_sinl(NAN))));
EXPECT_STREQ("NAN", gc(xdtoal(_sinl(NAN))));
EXPECT_TRUE(isnan(_sinl(+INFINITY)));
EXPECT_TRUE(isnan(_sinl(-INFINITY)));
EXPECT_STREQ(".479425538604203", _gc(xdtoal(_sinl(.5))));
EXPECT_STREQ("-.479425538604203", _gc(xdtoal(_sinl(-.5))));
EXPECT_STREQ(".8414709794048734", _gc(xdtoal(_sinl(.99999999))));
/* EXPECT_STREQ("-.998836772397", _gc(xdtoal(_sinl(555555555555)))); */
/* EXPECT_STREQ("1", _gc(xdtoal(_sinl(5.319372648326541e+255L)))); */
EXPECT_STREQ(".479425538604203", gc(xdtoal(_sinl(.5))));
EXPECT_STREQ("-.479425538604203", gc(xdtoal(_sinl(-.5))));
EXPECT_STREQ(".8414709794048734", gc(xdtoal(_sinl(.99999999))));
/* EXPECT_STREQ("-.998836772397", gc(xdtoal(_sinl(555555555555)))); */
/* EXPECT_STREQ("1", gc(xdtoal(_sinl(5.319372648326541e+255L)))); */
}
TEST(sin, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", _sin(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _sin(-0.))));
EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15g", _sin(.1))));
EXPECT_STREQ("-0.0998334166468282", _gc(xasprintf("%.15g", _sin(-.1))));
EXPECT_STREQ("0.479425538604203", _gc(xasprintf("%.15g", _sin(.5))));
EXPECT_STREQ("-0.479425538604203", _gc(xasprintf("%.15g", _sin(-.5))));
EXPECT_STREQ("0.841470984807897", _gc(xasprintf("%.15g", _sin(1.))));
EXPECT_STREQ("-0.841470984807897", _gc(xasprintf("%.15g", _sin(-1.))));
EXPECT_STREQ("0.997494986604054", _gc(xasprintf("%.15g", _sin(1.5))));
EXPECT_STREQ("-0.997494986604054", _gc(xasprintf("%.15g", _sin(-1.5))));
EXPECT_STREQ("0.909297426825682", _gc(xasprintf("%.15g", _sin(2.))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", _sin(0.))));
EXPECT_STREQ("-0", gc(xasprintf("%.15g", _sin(-0.))));
EXPECT_STREQ("0.0998334166468282", gc(xasprintf("%.15g", _sin(.1))));
EXPECT_STREQ("-0.0998334166468282", gc(xasprintf("%.15g", _sin(-.1))));
EXPECT_STREQ("0.479425538604203", gc(xasprintf("%.15g", _sin(.5))));
EXPECT_STREQ("-0.479425538604203", gc(xasprintf("%.15g", _sin(-.5))));
EXPECT_STREQ("0.841470984807897", gc(xasprintf("%.15g", _sin(1.))));
EXPECT_STREQ("-0.841470984807897", gc(xasprintf("%.15g", _sin(-1.))));
EXPECT_STREQ("0.997494986604054", gc(xasprintf("%.15g", _sin(1.5))));
EXPECT_STREQ("-0.997494986604054", gc(xasprintf("%.15g", _sin(-1.5))));
EXPECT_STREQ("0.909297426825682", gc(xasprintf("%.15g", _sin(2.))));
EXPECT_TRUE(isnan(_sin(NAN)));
EXPECT_TRUE(isnan(_sin(-NAN)));
EXPECT_TRUE(isnan(_sin(INFINITY)));
EXPECT_TRUE(isnan(_sin(-INFINITY)));
EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", _sin(__DBL_MIN__))));
gc(xasprintf("%.15g", _sin(__DBL_MIN__))));
EXPECT_STREQ("0.00496195478918406",
_gc(xasprintf("%.15g", _sin(__DBL_MAX__))));
gc(xasprintf("%.15g", _sin(__DBL_MAX__))));
EXPECT_STREQ("-0.841470984807897",
_gc(xasprintf("%.15g", _sin(-1.0000000000000002))));
gc(xasprintf("%.15g", _sin(-1.0000000000000002))));
EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", _sin(-2.1073424255447e-08))));
gc(xasprintf("%.15g", _sin(-2.1073424255447e-08))));
}
TEST(sinf, test) {
EXPECT_TRUE(isnan(_sinf(NAN)));
EXPECT_TRUE(isnan(_sinf(+INFINITY)));
EXPECT_TRUE(isnan(_sinf(-INFINITY)));
EXPECT_STREQ("NAN", _gc(xdtoaf(_sinf(NAN))));
EXPECT_STARTSWITH(".479426", _gc(xdtoaf(_sinf(.5f))));
EXPECT_STARTSWITH("-.479426", _gc(xdtoaf(_sinf(-.5f))));
EXPECT_STARTSWITH(".873283", _gc(xdtoaf(_sinf(555))));
EXPECT_STREQ("NAN", gc(xdtoaf(_sinf(NAN))));
EXPECT_STARTSWITH(".479426", gc(xdtoaf(_sinf(.5f))));
EXPECT_STARTSWITH("-.479426", gc(xdtoaf(_sinf(-.5f))));
EXPECT_STARTSWITH(".873283", gc(xdtoaf(_sinf(555))));
}
BENCH(_sin, bench) {