Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Rust edition 2021 and update dependencies #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.5.1"
authors = ["Brendan Zabarauskas <[email protected]>"]
license = "Apache-2.0"
description = "Approximate floating point equality comparisons and assertions."
edition = "2021"

documentation = "https://docs.rs/approx"
homepage = "https://github.com/brendanzab/approx"
Expand All @@ -29,5 +30,5 @@ default = ["std"]
std = []

[dependencies]
num-traits = { version = "0.2.0", default_features = false }
num-complex = { version = "0.4.0", optional = true }
num-traits = { version = "0.2.19", default-features = false }
num-complex = { version = "0.4.6", optional = true }
4 changes: 2 additions & 2 deletions src/abs_diff_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl_signed_abs_diff_eq!(i16, 0);
impl_signed_abs_diff_eq!(i32, 0);
impl_signed_abs_diff_eq!(i64, 0);
impl_signed_abs_diff_eq!(isize, 0);
impl_signed_abs_diff_eq!(f32, core::f32::EPSILON);
impl_signed_abs_diff_eq!(f64, core::f64::EPSILON);
impl_signed_abs_diff_eq!(f32, f32::EPSILON);
impl_signed_abs_diff_eq!(f64, f64::EPSILON);

///////////////////////////////////////////////////////////////////////////////////////////////////
// Derived implementations
Expand Down
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
//! more positional style:
//!
//! ```rust
//! #[macro_use]
//! extern crate approx;
//!
//! use std::f64;
//! use approx::{abs_diff_eq, relative_eq, ulps_eq};
//!
//! # fn main() {
//! abs_diff_eq!(1.0, 1.0);
Expand Down Expand Up @@ -51,9 +49,7 @@
//! For example, we might want to be able to do approximate assertions on a complex number type:
//!
//! ```rust
//! #[macro_use]
//! extern crate approx;
//! # use approx::{AbsDiffEq, RelativeEq, UlpsEq};
//! # use approx::{AbsDiffEq, RelativeEq, UlpsEq, assert_relative_eq, assert_ulps_eq};
//!
//! #[derive(Debug, PartialEq)]
//! struct Complex<T> {
Expand Down Expand Up @@ -157,10 +153,6 @@
#![no_std]
#![allow(clippy::transmute_float_to_int)]

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

mod abs_diff_eq;
mod relative_eq;
mod ulps_eq;
Expand Down
3 changes: 2 additions & 1 deletion src/relative_eq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use core::{cell, f32, f64};
#[cfg(feature = "num-complex")]
use num_complex::Complex;
use AbsDiffEq;

use crate::AbsDiffEq;

/// Equality comparisons between two numbers using both the absolute difference and
/// relative based comparisons.
Expand Down
2 changes: 1 addition & 1 deletion src/ulps_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::cell;
use num_complex::Complex;
use num_traits::Signed;

use AbsDiffEq;
use crate::AbsDiffEq;

/// Equality comparisons between two numbers using both the absolute difference and ULPs
/// (Units in Last Place) based comparisons.
Expand Down
18 changes: 13 additions & 5 deletions tests/abs_diff_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]

#[macro_use]
extern crate approx;

mod test_f32 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};
use core::f32;

#[test]
Expand Down Expand Up @@ -189,6 +187,7 @@ mod test_f32 {

#[cfg(test)]
mod test_f64 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};
use core::f64;

#[test]
Expand Down Expand Up @@ -358,6 +357,8 @@ mod test_f64 {

mod test_ref {
mod test_f32 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
assert_abs_diff_eq!(&1.0f32, &1.0f32);
Expand All @@ -366,6 +367,8 @@ mod test_ref {
}

mod test_f64 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
assert_abs_diff_eq!(&1.0f64, &1.0f64);
Expand All @@ -376,6 +379,8 @@ mod test_ref {

mod test_slice {
mod test_f32 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
assert_abs_diff_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
Expand All @@ -384,6 +389,8 @@ mod test_slice {
}

mod test_f64 {
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
assert_abs_diff_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
Expand All @@ -394,11 +401,11 @@ mod test_slice {

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
pub use num_complex::Complex;

mod test_f32 {
use super::Complex;
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
Expand All @@ -421,6 +428,7 @@ mod test_complex {

mod test_f64 {
use super::Complex;
use approx::{assert_abs_diff_eq, assert_abs_diff_ne};

#[test]
fn test_basic() {
Expand Down
2 changes: 0 additions & 2 deletions tests/macro_import.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate approx;

mod test_macro_import {
use approx::{
assert_abs_diff_eq, assert_abs_diff_ne, assert_relative_eq, assert_relative_ne,
Expand Down
6 changes: 4 additions & 2 deletions tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

//! Macro instantiation tests

#[macro_use]
extern crate approx;
use approx::{
abs_diff_eq, abs_diff_ne, assert_abs_diff_eq, assert_relative_eq, assert_ulps_eq, relative_eq,
relative_ne, ulps_eq, ulps_ne,
};

#[test]
fn test_abs_diff_eq() {
Expand Down
18 changes: 13 additions & 5 deletions tests/relative_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]

#[macro_use]
extern crate approx;

mod test_f32 {
use approx::{assert_relative_eq, assert_relative_ne};
use core::f32;

#[test]
Expand Down Expand Up @@ -191,6 +189,7 @@ mod test_f32 {

#[cfg(test)]
mod test_f64 {
use approx::{assert_relative_eq, assert_relative_ne};
use core::f64;

#[test]
Expand Down Expand Up @@ -356,6 +355,8 @@ mod test_f64 {

mod test_ref {
mod test_f32 {
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
assert_relative_eq!(&1.0f32, &1.0f32);
Expand All @@ -364,6 +365,8 @@ mod test_ref {
}

mod test_f64 {
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
assert_relative_eq!(&1.0f64, &1.0f64);
Expand All @@ -374,6 +377,8 @@ mod test_ref {

mod test_slice {
mod test_f32 {
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
assert_relative_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
Expand All @@ -382,6 +387,8 @@ mod test_slice {
}

mod test_f64 {
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
assert_relative_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
Expand All @@ -392,11 +399,11 @@ mod test_slice {

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
pub use num_complex::Complex;

mod test_f32 {
use super::Complex;
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
Expand All @@ -419,6 +426,7 @@ mod test_complex {

mod test_f64 {
use super::Complex;
use approx::{assert_relative_eq, assert_relative_ne};

#[test]
fn test_basic() {
Expand Down
18 changes: 13 additions & 5 deletions tests/ulps_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]

#[macro_use]
extern crate approx;

mod test_f32 {
use approx::{assert_ulps_eq, assert_ulps_ne};
use core::f32;

#[test]
Expand Down Expand Up @@ -187,6 +185,7 @@ mod test_f32 {

#[cfg(test)]
mod test_f64 {
use approx::{assert_ulps_eq, assert_ulps_ne};
use core::f64;

#[test]
Expand Down Expand Up @@ -354,6 +353,8 @@ mod test_f64 {

mod test_ref {
mod test_f32 {
use approx::{assert_ulps_eq, assert_ulps_ne};

#[test]
fn test_basic() {
assert_ulps_eq!(&1.0f32, &1.0f32);
Expand All @@ -362,6 +363,8 @@ mod test_ref {
}

mod test_f64 {
use approx::{assert_ulps_eq, assert_ulps_ne};

#[test]
fn test_basic() {
assert_ulps_eq!(&1.0f64, &1.0f64);
Expand All @@ -372,6 +375,8 @@ mod test_ref {

mod test_slice {
mod test_f32 {
use approx::{assert_ulps_eq, assert_ulps_ne};

#[test]
fn test_basic() {
assert_ulps_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
Expand All @@ -382,6 +387,8 @@ mod test_slice {
mod test_f64 {
#[test]
fn test_basic() {
use approx::{assert_ulps_eq, assert_ulps_ne};

assert_ulps_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
assert_ulps_ne!([1.0f64, 2.0f64][..], [2.0f64, 1.0f64][..]);
}
Expand All @@ -390,11 +397,11 @@ mod test_slice {

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
pub use num_complex::Complex;

mod test_f32 {
use super::Complex;
use approx::{assert_ulps_eq, assert_ulps_ne};

#[test]
fn test_basic() {
Expand All @@ -417,6 +424,7 @@ mod test_complex {

mod test_f64 {
use super::Complex;
use approx::{assert_ulps_eq, assert_ulps_ne};

#[test]
fn test_basic() {
Expand Down