Skip to content

Commit

Permalink
Merge pull request #23 from aurelj/no_std
Browse files Browse the repository at this point in the history
add support for no_std
  • Loading branch information
mikedilger authored Apr 28, 2020
2 parents 0d2be6d + 23d17d8 commit 4b47ee2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ doctest = true
doc = true

[features]
default = [ "num-traits" ]
default = [ "num-traits", "std" ]
std = []

[dependencies]
num-traits = { version = "0.2", default-features = false, optional = true }
5 changes: 4 additions & 1 deletion src/eq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2014-2018 Optimal Computing (NZ) Ltd.
// Licensed under the MIT license. See LICENSE for details.

use std::{f32,f64};
use core::{f32, f64};
#[cfg(feature = "num-traits")]
#[allow(unused_imports)]
use num_traits::float::FloatCore;
use super::Ulps;

/// A trait for approximate equality comparisons.
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,15 @@
//!
//! [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature="num-traits")]
extern crate num_traits;

#[macro_use]
mod macros;

#[cfg(feature = "std")]
pub fn trials() {
println!("are they approximately equal?: {:?}",
approx_eq!(f32, 1.0, 1.0000001));
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro_rules! saturating_abs_i32 {
if $val.is_negative() {
match $val.checked_neg() {
Some(v) => v,
None => std::i32::MAX
None => core::i32::MAX
}
} else {
$val
Expand All @@ -38,7 +38,7 @@ macro_rules! saturating_abs_i64 {
if $val.is_negative() {
match $val.checked_neg() {
Some(v) => v,
None => std::i64::MAX
None => core::i64::MAX
}
} else {
$val
Expand Down
4 changes: 2 additions & 2 deletions src/ratio.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2014-2018 Optimal Computing (NZ) Ltd.
// Licensed under the MIT license. See LICENSE for details.

use std::cmp::PartialOrd;
use std::ops::{Sub,Div,Neg};
use core::cmp::PartialOrd;
use core::ops::{Sub, Div, Neg};
use num_traits::Zero;

/// ApproxEqRatio is a trait for approximate equality comparisons bounding the ratio
Expand Down

0 comments on commit 4b47ee2

Please sign in to comment.