2018-07-13 18:36:29 -04:00
2018-07-12 20:19:42 -05:00
2018-07-12 20:19:42 -05:00
2018-07-13 18:36:29 -04:00
2018-07-13 18:36:29 -04:00
2018-07-12 00:44:28 -05:00
2018-07-12 15:50:06 -05:00
2018-07-12 20:19:42 -05:00
2018-07-12 00:44:28 -05:00
2018-07-12 00:44:28 -05:00
2018-07-12 20:19:42 -05:00

libm

A port of MUSL's libm to Rust.

Goals

The short term goal of this library is to enable math support (e.g. sin, atan2) for the wasm32-unknown-unknown target. The longer term goal is to enable math support in the core crate.

Testing

The test suite of this crate can only be run on x86_64 Linux systems.

$ # The test suite depends on the `cross` tool so install it if you don't have it
$ cargo install cross

$ # and the `cross` tool requires docker to be running
$ systemctl start docker

$ # execute the test suite for the x86_64 target
$ TARGET=x86_64-unknown-linux-gnu bash ci/script.sh

$ # execute the test suite for the ARMv7 target
$ TARGET=armv7-unknown-linux-gnueabihf bash ci/script.sh

Contributing

  • Pick your favorite math function from the issue tracker.
  • Look for the C implementation of the function in the MUSL source code.
  • Copy paste the C code into a Rust file in the src/math directory and adjust src/math/mod.rs accordingly. Also, uncomment the corresponding trait method in src/lib.rs.
  • Run cargo watch check and fix the compiler errors.
  • Tweak the bottom of test-generator/src/main.rs to add your function to the test suite.
  • If you can, run the test suite locally. If you can't, no problem! Your PR will be tested automatically.
  • Send us a pull request!
  • 🎉

Check PR #2 for an example.

Notes

  • Only use relative imports within the math directory / module, e.g. use self::fabs::fabs or use super::isnanf. Absolute imports from core are OK, e.g. use core::u64.

  • To reinterpret a float as an integer use the to_bits method. The MUSL code uses the GET_FLOAT_WORD macro, or a union, to do this operation.

  • To reinterpret an integer as a float use the f32::from_bits constructor. The MUSL code uses the SET_FLOAT_WORD macro, or a union, to do this operation.

  • Rust code panics on arithmetic overflows when not optimized. You may need to use the Wrapping newtype to avoid this problem.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Description
No description provided
Readme 793 KiB
Languages
Rust 98.5%
Dockerfile 1.2%
Shell 0.3%