diff --git a/Cargo.lock b/Cargo.lock index 386e266cae..b9ae70624b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,15 @@ version = "0.1.0" dependencies = [ "cbindgen 0.5.0", "platform 0.1.0", - "resource 0.1.0", +] + +[[package]] +name = "float" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.0", + "fenv 0.1.0", + "platform 0.1.0", ] [[package]] @@ -264,6 +272,7 @@ dependencies = [ "errno 0.1.0", "fcntl 0.1.0", "fenv 0.1.0", + "float 0.1.0", "grp 0.1.0", "mman 0.1.0", "platform 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index d4594535b1..55d8d5e913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ ctype = { path = "src/ctype" } errno = { path = "src/errno" } fcntl = { path = "src/fcntl" } fenv = { path = "src/fenv" } +float = { path = "src/float" } grp = { path = "src/grp" } semaphore = { path = "src/semaphore" } mman = { path = "src/mman" } diff --git a/include/bits/float.h b/include/bits/float.h new file mode 100644 index 0000000000..c62ae491dc --- /dev/null +++ b/include/bits/float.h @@ -0,0 +1,6 @@ +#ifndef _BITS_FLOAT_H +#define _BITS_FLOAT_H + +#define FLT_ROUNDS (flt_rounds()) + +#endif diff --git a/src/float/Cargo.toml b/src/float/Cargo.toml new file mode 100644 index 0000000000..3ae7acb3fe --- /dev/null +++ b/src/float/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "float" +version = "0.1.0" +authors = ["Dan Robertson "] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } +fenv = { path = "../fenv" } diff --git a/src/float/build.rs b/src/float/build.rs new file mode 100644 index 0000000000..e9b224fd13 --- /dev/null +++ b/src/float/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/float.h"); +} diff --git a/src/float/cbindgen.toml b/src/float/cbindgen.toml new file mode 100644 index 0000000000..bbb97a8139 --- /dev/null +++ b/src/float/cbindgen.toml @@ -0,0 +1,6 @@ +sys_includes = ["sys/types.h", "bits/float.h"] +include_guard = "_FLOAT_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/float/src/lib.rs b/src/float/src/lib.rs new file mode 100644 index 0000000000..e594fdba78 --- /dev/null +++ b/src/float/src/lib.rs @@ -0,0 +1,19 @@ +//! float.h implementation for Redox, following +//! http://pubs.opengroup.org/onlinepubs/7908799/xsh/float.h.html + +#![no_std] + +extern crate fenv; +extern crate platform; + +use platform::types::*; +use fenv::{fegetround, FE_TONEAREST}; + +pub const FLT_RADIX: c_int = 2; + +pub unsafe extern "C" fn flt_rounds() -> c_int { + match fegetround() { + FE_TONEAREST => 1, + _ => -1, + } +}