diff --git a/Cargo.lock b/Cargo.lock index 23d4c6e1aa..bf133296d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,6 +164,14 @@ name = "itoa" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lazy_static" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libc" version = "0.2.42" @@ -378,6 +386,11 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "spin" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "standalone-quote" version = "0.5.0" @@ -403,6 +416,7 @@ dependencies = [ "cbindgen 0.5.2", "errno 0.1.0", "fcntl 0.1.0", + "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "platform 0.1.0", "ralloc 1.0.0", "string 0.1.0", @@ -660,6 +674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" +"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" "checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" @@ -676,6 +691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" "checksum serde_json 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "84b8035cabe9b35878adec8ac5fe03d5f6bc97ff6edd7ccb96b44c1276ba390e" +"checksum spin 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14db77c5b914df6d6173dda9a3b3f5937bd802934fa5edaf934df06a3491e56f" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" diff --git a/Makefile b/Makefile index 39d1183a56..2efbec4023 100644 --- a/Makefile +++ b/Makefile @@ -73,4 +73,4 @@ $(BUILD)/openlibm: openlibm touch $@ $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm - make CC=$(CC) CFLAGS=-fno-stack-protector -C $< libopenlibm.a + make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/target/include" -C $< libopenlibm.a diff --git a/include/bits/float.h b/include/bits/float.h index c62ae491dc..01e393eade 100644 --- a/include/bits/float.h +++ b/include/bits/float.h @@ -3,4 +3,51 @@ #define FLT_ROUNDS (flt_rounds()) +// Shamelessly copy pasted from musl: + +#define FLT_RADIX 2 + +#define FLT_TRUE_MIN 1.40129846432481707092e-45F +#define FLT_MIN 1.17549435082228750797e-38F +#define FLT_MAX 3.40282346638528859812e+38F +#define FLT_EPSILON 1.1920928955078125e-07F + +#define FLT_MANT_DIG 24 +#define FLT_MIN_EXP (-125) +#define FLT_MAX_EXP 128 +#define FLT_HAS_SUBNORM 1 + +#define FLT_DIG 6 +#define FLT_DECIMAL_DIG 9 +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_10_EXP 38 + +#define DBL_TRUE_MIN 4.94065645841246544177e-324 +#define DBL_MIN 2.22507385850720138309e-308 +#define DBL_MAX 1.79769313486231570815e+308 +#define DBL_EPSILON 2.22044604925031308085e-16 + +#define DBL_MANT_DIG 53 +#define DBL_MIN_EXP (-1021) +#define DBL_MAX_EXP 1024 +#define DBL_HAS_SUBNORM 1 + +#define DBL_DIG 15 +#define DBL_DECIMAL_DIG 17 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_10_EXP 308 + +#define LDBL_HAS_SUBNORM 1 +#define LDBL_DECIMAL_DIG DECIMAL_DIG + +// TODO: Support more architectures than x86_64 here: +#define LDBL_TRUE_MIN 3.6451995318824746025e-4951L +#define LDBL_MIN 3.3621031431120935063e-4932L +#define LDBL_MAX 1.1897314953572317650e+4932L +#define LDBL_EPSILON 1.0842021724855044340e-19L + +#define LDBL_MANT_DIG 64 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MAX_EXP 16384 + #endif diff --git a/include/limits.h b/include/limits.h index e69de29bb2..c85b58fa1d 100644 --- a/include/limits.h +++ b/include/limits.h @@ -0,0 +1,25 @@ +#define MB_LEN_MAX 4 // unicode + +#define CHAR_BIT __CHAR_BIT__ +#define CHAR_MAX __CHAR_MAX__ +#define CHAR_MIN 0 +#define INT_MAX __INT_MAX__ +#define INT_MIN (-INT_MAX - 1) +#define LLONG_MAX __LONG_LONG_MAX__ +#define LLONG_MIN (-LLONG_MAX - 1) +#define LONG_BIT __LONG_BIT__ +#define LONG_MAX __LONG_MAX__ +#define LONG_MIN (-LONG_MAX - 1) +#define SCHAR_MAX __SCHAR_MAX__ +#define SCHAR_MIN (-SCHAR_MAX - 1) +#define SHRT_MAX __SHRT_MAX__ +#define SHRT_MIN (-SHRT_MAX - 1) + +// TODO: These might not be accurate on all platforms +#define SSIZE_MAX ((1 << 64 - 1) - 1) +#define UCHAR_MAX 255 +#define UINT_MAX ((1 << 32) - 1) +#define ULLONG_MAX ((1 << 64) - 1) +#define ULONG_MAX ((1 << 64) - 1) +#define USHRT_MAX ((1 << 16) - 1) +#define WORD_BIT 32