Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

1
vendor/approx/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{"Cargo.toml":"78766a0a5bf02b991509fcd5423e2b845f526f28ea6b670f8b77bcbe531ac3d1","LICENSE":"3ddf9be5c28fe27dad143a5dc76eea25222ad1dd68934a047064e56ed2fa40c5","README.md":"9bb194156790227e4fa96af334bb9528924aeb76a5efcb321c5b948a8e9e4b6f","src/abs_diff_eq.rs":"ae93c2d27ed592c16b3903ec42b4ddb51e1adee02cfdf281a3acb1d4d53fbfa2","src/lib.rs":"502f1999b588a0cc8d5575e9d2d847d5ae17f983cf87b72b9fa8be54c5507695","src/macros.rs":"b27db6e4e1d3ca9bfb04a1278bf5842e8c946c5f7c1dace621029f6a0d616e63","src/relative_eq.rs":"564cb4ae72e2cff35259928d1b571577fdbd4438fc3e364061b4192e6ff77251","src/ulps_eq.rs":"cb7e7a323adc59c1589daa8ad6793118fd4a4457e8325892745463561c9756a3","tests/abs_diff_eq.rs":"14b7c71ea16022ddd93641aedaa78d7b17d2af7b7cc142cb04fb54059f5ba5c7","tests/macro_import.rs":"d32a2797301ca1f72aa4f065f2c114a98cb0f9e385cee200caead37e08bc218a","tests/macros.rs":"a20d7e011c451775e0e5c3a0b726860413a6b7c1f250752a70e979353dcc800d","tests/relative_eq.rs":"d5fffe26f0296fd14fe3c9abe29497f0c00290091c2833e0d3bf0c41ce7976b1","tests/ulps_eq.rs":"9fb76de1e244d4884402428c03fa29d09c2f6907b2b789c1d5e32a1cb2831bfb"},"package":"cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"}

38
vendor/approx/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,38 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
name = "approx"
version = "0.5.1"
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>"]
description = "Approximate floating point equality comparisons and assertions."
homepage = "https://github.com/brendanzab/approx"
documentation = "https://docs.rs/approx"
readme = "README.md"
keywords = ["approximate", "assert", "comparison", "equality", "float"]
license = "Apache-2.0"
repository = "https://github.com/brendanzab/approx"
[package.metadata.docs.rs]
features = ["std", "num-complex"]
[lib]
name = "approx"
[dependencies.num-complex]
version = "0.4.0"
optional = true
[dependencies.num-traits]
version = "0.2.0"
default_features = false
[features]
default = ["std"]
std = []

202
vendor/approx/LICENSE vendored Normal file
View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

20
vendor/approx/README.md vendored Normal file
View File

@@ -0,0 +1,20 @@
# approx
[![Build Status][travis_badge]][travis_url]
[![Version][version_badge]][crate_url]
[![Documentation][docs_badge]][docs_url]
[![Downloads][downloads_badge]][crate_url]
[![License][license_badge]][license_url]
[travis_badge]: https://travis-ci.org/brendanzab/approx.svg?branch=master
[docs_badge]: https://docs.rs/approx/badge.svg
[version_badge]: https://img.shields.io/crates/v/approx.svg
[license_badge]: https://img.shields.io/crates/l/approx.svg
[downloads_badge]: https://img.shields.io/crates/d/approx.svg
[travis_url]: https://travis-ci.org/brendanzab/approx
[docs_url]: https://docs.rs/approx
[crate_url]: https://crates.io/crates/approx
[license_url]: https://github.com/brendanzab/approx/blob/master/LICENSE
Approximate floating point equality comparisons and assertions for the Rust Programming Language.

185
vendor/approx/src/abs_diff_eq.rs vendored Normal file
View File

@@ -0,0 +1,185 @@
use core::cell;
#[cfg(feature = "num-complex")]
use num_complex::Complex;
/// Equality that is defined using the absolute difference of two numbers.
pub trait AbsDiffEq<Rhs = Self>: PartialEq<Rhs>
where
Rhs: ?Sized,
{
/// Used for specifying relative comparisons.
type Epsilon;
/// The default tolerance to use when testing values that are close together.
///
/// This is used when no `epsilon` value is supplied to the [`abs_diff_eq!`], [`relative_eq!`],
/// or [`ulps_eq!`] macros.
fn default_epsilon() -> Self::Epsilon;
/// A test for equality that uses the absolute difference to compute the approximate
/// equality of two numbers.
fn abs_diff_eq(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool;
/// The inverse of [`AbsDiffEq::abs_diff_eq`].
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool {
!Self::abs_diff_eq(self, other, epsilon)
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Base implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
macro_rules! impl_unsigned_abs_diff_eq {
($T:ident, $default_epsilon:expr) => {
impl AbsDiffEq for $T {
type Epsilon = $T;
#[inline]
fn default_epsilon() -> $T {
$default_epsilon
}
#[inline]
fn abs_diff_eq(&self, other: &$T, epsilon: $T) -> bool {
(if self > other {
self - other
} else {
other - self
}) <= epsilon
}
}
};
}
impl_unsigned_abs_diff_eq!(u8, 0);
impl_unsigned_abs_diff_eq!(u16, 0);
impl_unsigned_abs_diff_eq!(u32, 0);
impl_unsigned_abs_diff_eq!(u64, 0);
impl_unsigned_abs_diff_eq!(usize, 0);
macro_rules! impl_signed_abs_diff_eq {
($T:ident, $default_epsilon:expr) => {
impl AbsDiffEq for $T {
type Epsilon = $T;
#[inline]
fn default_epsilon() -> $T {
$default_epsilon
}
#[inline]
#[allow(unused_imports)]
fn abs_diff_eq(&self, other: &$T, epsilon: $T) -> bool {
use num_traits::float::FloatCore;
$T::abs(self - other) <= epsilon
}
}
};
}
impl_signed_abs_diff_eq!(i8, 0);
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);
///////////////////////////////////////////////////////////////////////////////////////////////////
// Derived implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
impl<'a, T: AbsDiffEq + ?Sized> AbsDiffEq for &'a T {
type Epsilon = T::Epsilon;
#[inline]
fn default_epsilon() -> T::Epsilon {
T::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &&'a T, epsilon: T::Epsilon) -> bool {
T::abs_diff_eq(*self, *other, epsilon)
}
}
impl<'a, T: AbsDiffEq + ?Sized> AbsDiffEq for &'a mut T {
type Epsilon = T::Epsilon;
#[inline]
fn default_epsilon() -> T::Epsilon {
T::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &&'a mut T, epsilon: T::Epsilon) -> bool {
T::abs_diff_eq(*self, *other, epsilon)
}
}
impl<T: AbsDiffEq + Copy> AbsDiffEq for cell::Cell<T> {
type Epsilon = T::Epsilon;
#[inline]
fn default_epsilon() -> T::Epsilon {
T::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &cell::Cell<T>, epsilon: T::Epsilon) -> bool {
T::abs_diff_eq(&self.get(), &other.get(), epsilon)
}
}
impl<T: AbsDiffEq + ?Sized> AbsDiffEq for cell::RefCell<T> {
type Epsilon = T::Epsilon;
#[inline]
fn default_epsilon() -> T::Epsilon {
T::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &cell::RefCell<T>, epsilon: T::Epsilon) -> bool {
T::abs_diff_eq(&self.borrow(), &other.borrow(), epsilon)
}
}
impl<A, B> AbsDiffEq<[B]> for [A]
where
A: AbsDiffEq<B>,
A::Epsilon: Clone,
{
type Epsilon = A::Epsilon;
#[inline]
fn default_epsilon() -> A::Epsilon {
A::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &[B], epsilon: A::Epsilon) -> bool {
self.len() == other.len()
&& Iterator::zip(self.iter(), other).all(|(x, y)| A::abs_diff_eq(x, y, epsilon.clone()))
}
}
#[cfg(feature = "num-complex")]
impl<T: AbsDiffEq> AbsDiffEq for Complex<T>
where
T::Epsilon: Clone,
{
type Epsilon = T::Epsilon;
#[inline]
fn default_epsilon() -> T::Epsilon {
T::default_epsilon()
}
#[inline]
fn abs_diff_eq(&self, other: &Complex<T>, epsilon: T::Epsilon) -> bool {
T::abs_diff_eq(&self.re, &other.re, epsilon.clone())
&& T::abs_diff_eq(&self.im, &other.im, epsilon)
}
}

388
vendor/approx/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,388 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! A crate that provides facilities for testing the approximate equality of floating-point
//! based types, using either relative difference, or units in the last place (ULPs)
//! comparisons.
//!
//! You can also use the `*_{eq, ne}!` and `assert_*_{eq, ne}!` macros to test for equality using a
//! more positional style:
//!
//! ```rust
//! #[macro_use]
//! extern crate approx;
//!
//! use std::f64;
//!
//! # fn main() {
//! abs_diff_eq!(1.0, 1.0);
//! abs_diff_eq!(1.0, 1.0, epsilon = f64::EPSILON);
//!
//! relative_eq!(1.0, 1.0);
//! relative_eq!(1.0, 1.0, epsilon = f64::EPSILON);
//! relative_eq!(1.0, 1.0, max_relative = 1.0);
//! relative_eq!(1.0, 1.0, epsilon = f64::EPSILON, max_relative = 1.0);
//! relative_eq!(1.0, 1.0, max_relative = 1.0, epsilon = f64::EPSILON);
//!
//! ulps_eq!(1.0, 1.0);
//! ulps_eq!(1.0, 1.0, epsilon = f64::EPSILON);
//! ulps_eq!(1.0, 1.0, max_ulps = 4);
//! ulps_eq!(1.0, 1.0, epsilon = f64::EPSILON, max_ulps = 4);
//! ulps_eq!(1.0, 1.0, max_ulps = 4, epsilon = f64::EPSILON);
//! # }
//! ```
//!
//! # Implementing approximate equality for custom types
//!
//! The `*Eq` traits allow approximate equalities to be implemented on types, based on the
//! fundamental floating point implementations.
//!
//! 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};
//!
//! #[derive(Debug, PartialEq)]
//! struct Complex<T> {
//! x: T,
//! i: T,
//! }
//! # impl<T: AbsDiffEq> AbsDiffEq for Complex<T> where T::Epsilon: Copy {
//! # type Epsilon = T::Epsilon;
//! # fn default_epsilon() -> T::Epsilon { T::default_epsilon() }
//! # fn abs_diff_eq(&self, other: &Self, epsilon: T::Epsilon) -> bool {
//! # T::abs_diff_eq(&self.x, &other.x, epsilon) &&
//! # T::abs_diff_eq(&self.i, &other.i, epsilon)
//! # }
//! # }
//! # impl<T: RelativeEq> RelativeEq for Complex<T> where T::Epsilon: Copy {
//! # fn default_max_relative() -> T::Epsilon { T::default_max_relative() }
//! # fn relative_eq(&self, other: &Self, epsilon: T::Epsilon, max_relative: T::Epsilon)
//! # -> bool {
//! # T::relative_eq(&self.x, &other.x, epsilon, max_relative) &&
//! # T::relative_eq(&self.i, &other.i, epsilon, max_relative)
//! # }
//! # }
//! # impl<T: UlpsEq> UlpsEq for Complex<T> where T::Epsilon: Copy {
//! # fn default_max_ulps() -> u32 { T::default_max_ulps() }
//! # fn ulps_eq(&self, other: &Self, epsilon: T::Epsilon, max_ulps: u32) -> bool {
//! # T::ulps_eq(&self.x, &other.x, epsilon, max_ulps) &&
//! # T::ulps_eq(&self.i, &other.i, epsilon, max_ulps)
//! # }
//! # }
//!
//! # fn main() {
//! let x = Complex { x: 1.2, i: 2.3 };
//!
//! assert_relative_eq!(x, x);
//! assert_ulps_eq!(x, x, max_ulps = 4);
//! # }
//! ```
//!
//! To do this we can implement [`AbsDiffEq`], [`RelativeEq`] and [`UlpsEq`] generically in terms
//! of a type parameter that also implements `AbsDiffEq`, `RelativeEq` and `UlpsEq` respectively.
//! This means that we can make comparisons for either `Complex<f32>` or `Complex<f64>`:
//!
//! ```rust
//! # use approx::{AbsDiffEq, RelativeEq, UlpsEq};
//! # #[derive(Debug, PartialEq)]
//! # struct Complex<T> { x: T, i: T, }
//! #
//! impl<T: AbsDiffEq> AbsDiffEq for Complex<T> where
//! T::Epsilon: Copy,
//! {
//! type Epsilon = T::Epsilon;
//!
//! fn default_epsilon() -> T::Epsilon {
//! T::default_epsilon()
//! }
//!
//! fn abs_diff_eq(&self, other: &Self, epsilon: T::Epsilon) -> bool {
//! T::abs_diff_eq(&self.x, &other.x, epsilon) &&
//! T::abs_diff_eq(&self.i, &other.i, epsilon)
//! }
//! }
//!
//! impl<T: RelativeEq> RelativeEq for Complex<T> where
//! T::Epsilon: Copy,
//! {
//! fn default_max_relative() -> T::Epsilon {
//! T::default_max_relative()
//! }
//!
//! fn relative_eq(&self, other: &Self, epsilon: T::Epsilon, max_relative: T::Epsilon) -> bool {
//! T::relative_eq(&self.x, &other.x, epsilon, max_relative) &&
//! T::relative_eq(&self.i, &other.i, epsilon, max_relative)
//! }
//! }
//!
//! impl<T: UlpsEq> UlpsEq for Complex<T> where
//! T::Epsilon: Copy,
//! {
//! fn default_max_ulps() -> u32 {
//! T::default_max_ulps()
//! }
//!
//! fn ulps_eq(&self, other: &Self, epsilon: T::Epsilon, max_ulps: u32) -> bool {
//! T::ulps_eq(&self.x, &other.x, epsilon, max_ulps) &&
//! T::ulps_eq(&self.i, &other.i, epsilon, max_ulps)
//! }
//! }
//! ```
//!
//! # References
//!
//! Floating point is hard! Thanks goes to these links for helping to make things a _little_
//! easier to understand:
//!
//! - [Comparing Floating Point Numbers, 2012 Edition](
//! https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
//! - [The Floating Point Guide - Comparison](http://floating-point-gui.de/errors/comparison/)
//! - [What Every Computer Scientist Should Know About Floating-Point Arithmetic](
//! https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)
#![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;
mod macros;
pub use abs_diff_eq::AbsDiffEq;
pub use relative_eq::RelativeEq;
pub use ulps_eq::UlpsEq;
/// The requisite parameters for testing for approximate equality using a
/// absolute difference based comparison.
///
/// This is not normally used directly, rather via the
/// `assert_abs_diff_{eq|ne}!` and `abs_diff_{eq|ne}!` macros.
///
/// # Example
///
/// ```rust
/// use std::f64;
/// use approx::AbsDiff;
///
/// AbsDiff::default().eq(&1.0, &1.0);
/// AbsDiff::default().epsilon(f64::EPSILON).eq(&1.0, &1.0);
/// ```
pub struct AbsDiff<A, B = A>
where
A: AbsDiffEq<B> + ?Sized,
B: ?Sized,
{
/// The tolerance to use when testing values that are close together.
pub epsilon: A::Epsilon,
}
impl<A, B> Default for AbsDiff<A, B>
where
A: AbsDiffEq<B> + ?Sized,
B: ?Sized,
{
#[inline]
fn default() -> AbsDiff<A, B> {
AbsDiff {
epsilon: A::default_epsilon(),
}
}
}
impl<A, B> AbsDiff<A, B>
where
A: AbsDiffEq<B> + ?Sized,
B: ?Sized,
{
/// Replace the epsilon value with the one specified.
#[inline]
pub fn epsilon(self, epsilon: A::Epsilon) -> AbsDiff<A, B> {
AbsDiff { epsilon }
}
/// Peform the equality comparison
#[inline]
#[must_use]
pub fn eq(self, lhs: &A, rhs: &B) -> bool {
A::abs_diff_eq(lhs, rhs, self.epsilon)
}
/// Peform the inequality comparison
#[inline]
#[must_use]
pub fn ne(self, lhs: &A, rhs: &B) -> bool {
A::abs_diff_ne(lhs, rhs, self.epsilon)
}
}
/// The requisite parameters for testing for approximate equality using a
/// relative based comparison.
///
/// This is not normally used directly, rather via the
/// `assert_relative_{eq|ne}!` and `relative_{eq|ne}!` macros.
///
/// # Example
///
/// ```rust
/// use std::f64;
/// use approx::Relative;
///
/// Relative::default().eq(&1.0, &1.0);
/// Relative::default().epsilon(f64::EPSILON).eq(&1.0, &1.0);
/// Relative::default().max_relative(1.0).eq(&1.0, &1.0);
/// Relative::default().epsilon(f64::EPSILON).max_relative(1.0).eq(&1.0, &1.0);
/// Relative::default().max_relative(1.0).epsilon(f64::EPSILON).eq(&1.0, &1.0);
/// ```
pub struct Relative<A, B = A>
where
A: RelativeEq<B> + ?Sized,
B: ?Sized,
{
/// The tolerance to use when testing values that are close together.
pub epsilon: A::Epsilon,
/// The relative tolerance for testing values that are far-apart.
pub max_relative: A::Epsilon,
}
impl<A, B> Default for Relative<A, B>
where
A: RelativeEq<B> + ?Sized,
B: ?Sized,
{
#[inline]
fn default() -> Relative<A, B> {
Relative {
epsilon: A::default_epsilon(),
max_relative: A::default_max_relative(),
}
}
}
impl<A, B> Relative<A, B>
where
A: RelativeEq<B> + ?Sized,
B: ?Sized,
{
/// Replace the epsilon value with the one specified.
#[inline]
pub fn epsilon(self, epsilon: A::Epsilon) -> Relative<A, B> {
Relative { epsilon, ..self }
}
/// Replace the maximum relative value with the one specified.
#[inline]
pub fn max_relative(self, max_relative: A::Epsilon) -> Relative<A, B> {
Relative {
max_relative,
..self
}
}
/// Peform the equality comparison
#[inline]
#[must_use]
pub fn eq(self, lhs: &A, rhs: &B) -> bool {
A::relative_eq(lhs, rhs, self.epsilon, self.max_relative)
}
/// Peform the inequality comparison
#[inline]
#[must_use]
pub fn ne(self, lhs: &A, rhs: &B) -> bool {
A::relative_ne(lhs, rhs, self.epsilon, self.max_relative)
}
}
/// The requisite parameters for testing for approximate equality using an ULPs
/// based comparison.
///
/// This is not normally used directly, rather via the `assert_ulps_{eq|ne}!`
/// and `ulps_{eq|ne}!` macros.
///
/// # Example
///
/// ```rust
/// use std::f64;
/// use approx::Ulps;
///
/// Ulps::default().eq(&1.0, &1.0);
/// Ulps::default().epsilon(f64::EPSILON).eq(&1.0, &1.0);
/// Ulps::default().max_ulps(4).eq(&1.0, &1.0);
/// Ulps::default().epsilon(f64::EPSILON).max_ulps(4).eq(&1.0, &1.0);
/// Ulps::default().max_ulps(4).epsilon(f64::EPSILON).eq(&1.0, &1.0);
/// ```
pub struct Ulps<A, B = A>
where
A: UlpsEq<B> + ?Sized,
B: ?Sized,
{
/// The tolerance to use when testing values that are close together.
pub epsilon: A::Epsilon,
/// The ULPs to tolerate when testing values that are far-apart.
pub max_ulps: u32,
}
impl<A, B> Default for Ulps<A, B>
where
A: UlpsEq<B> + ?Sized,
B: ?Sized,
{
#[inline]
fn default() -> Ulps<A, B> {
Ulps {
epsilon: A::default_epsilon(),
max_ulps: A::default_max_ulps(),
}
}
}
impl<A, B> Ulps<A, B>
where
A: UlpsEq<B> + ?Sized,
B: ?Sized,
{
/// Replace the epsilon value with the one specified.
#[inline]
pub fn epsilon(self, epsilon: A::Epsilon) -> Ulps<A, B> {
Ulps { epsilon, ..self }
}
/// Replace the max ulps value with the one specified.
#[inline]
pub fn max_ulps(self, max_ulps: u32) -> Ulps<A, B> {
Ulps { max_ulps, ..self }
}
/// Peform the equality comparison
#[inline]
#[must_use]
pub fn eq(self, lhs: &A, rhs: &B) -> bool {
A::ulps_eq(lhs, rhs, self.epsilon, self.max_ulps)
}
/// Peform the inequality comparison
#[inline]
#[must_use]
pub fn ne(self, lhs: &A, rhs: &B) -> bool {
A::ulps_ne(lhs, rhs, self.epsilon, self.max_ulps)
}
}

185
vendor/approx/src/macros.rs vendored Normal file
View File

@@ -0,0 +1,185 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// Approximate equality of using the absolute difference.
#[macro_export]
macro_rules! abs_diff_eq {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::AbsDiff::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::AbsDiff::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
}
/// Approximate inequality of using the absolute difference.
#[macro_export]
macro_rules! abs_diff_ne {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::AbsDiff::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::AbsDiff::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
}
/// Approximate equality using both the absolute difference and relative based comparisons.
#[macro_export]
macro_rules! relative_eq {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::Relative::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::Relative::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
}
/// Approximate inequality using both the absolute difference and relative based comparisons.
#[macro_export]
macro_rules! relative_ne {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::Relative::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::Relative::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
}
/// Approximate equality using both the absolute difference and ULPs (Units in Last Place).
#[macro_export]
macro_rules! ulps_eq {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::Ulps::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::Ulps::default()$(.$opt($val))*.eq(&$lhs, &$rhs)
};
}
/// Approximate inequality using both the absolute difference and ULPs (Units in Last Place).
#[macro_export]
macro_rules! ulps_ne {
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*) => {
$crate::Ulps::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
($lhs:expr, $rhs:expr $(, $opt:ident = $val:expr)*,) => {
$crate::Ulps::default()$(.$opt($val))*.ne(&$lhs, &$rhs)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __assert_approx {
($eq:ident, $given:expr, $expected:expr) => {{
match (&($given), &($expected)) {
(given, expected) => assert!(
$eq!(*given, *expected),
"assert_{}!({}, {})
left = {:?}
right = {:?}
",
stringify!($eq),
stringify!($given),
stringify!($expected),
given, expected,
),
}
}};
($eq:ident, $given:expr, $expected:expr, $($opt:ident = $val:expr),+) => {{
match (&($given), &($expected)) {
(given, expected) => assert!(
$eq!(*given, *expected, $($opt = $val),+),
"assert_{}!({}, {}, {})
left = {:?}
right = {:?}
",
stringify!($eq),
stringify!($given),
stringify!($expected),
stringify!($($opt = $val),+),
given, expected,
),
}
}};
}
/// An assertion that delegates to [`abs_diff_eq!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_abs_diff_eq {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(abs_diff_eq, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(abs_diff_eq, $given, $expected $(, $opt = $val)*)
};
}
/// An assertion that delegates to [`abs_diff_ne!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_abs_diff_ne {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(abs_diff_ne, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(abs_diff_ne, $given, $expected $(, $opt = $val)*)
};
}
/// An assertion that delegates to [`relative_eq!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_relative_eq {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(relative_eq, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(relative_eq, $given, $expected $(, $opt = $val)*)
};
}
/// An assertion that delegates to [`relative_ne!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_relative_ne {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(relative_ne, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(relative_ne, $given, $expected $(, $opt = $val)*)
};
}
/// An assertion that delegates to [`ulps_eq!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_ulps_eq {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(ulps_eq, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(ulps_eq, $given, $expected $(, $opt = $val)*)
};
}
/// An assertion that delegates to [`ulps_ne!`], and panics with a helpful error on failure.
#[macro_export(local_inner_macros)]
macro_rules! assert_ulps_ne {
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*) => {
__assert_approx!(ulps_ne, $given, $expected $(, $opt = $val)*)
};
($given:expr, $expected:expr $(, $opt:ident = $val:expr)*,) => {
__assert_approx!(ulps_ne, $given, $expected $(, $opt = $val)*)
};
}

191
vendor/approx/src/relative_eq.rs vendored Normal file
View File

@@ -0,0 +1,191 @@
use core::{cell, f32, f64};
#[cfg(feature = "num-complex")]
use num_complex::Complex;
use AbsDiffEq;
/// Equality comparisons between two numbers using both the absolute difference and
/// relative based comparisons.
pub trait RelativeEq<Rhs = Self>: AbsDiffEq<Rhs>
where
Rhs: ?Sized,
{
/// The default relative tolerance for testing values that are far-apart.
///
/// This is used when no `max_relative` value is supplied to the [`relative_eq`] macro.
fn default_max_relative() -> Self::Epsilon;
/// A test for equality that uses a relative comparison if the values are far apart.
fn relative_eq(&self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon)
-> bool;
/// The inverse of [`RelativeEq::relative_eq`].
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool {
!Self::relative_eq(self, other, epsilon, max_relative)
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Base implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation based on: [Comparing Floating Point Numbers, 2012 Edition]
// (https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
macro_rules! impl_relative_eq {
($T:ident, $U:ident) => {
impl RelativeEq for $T {
#[inline]
fn default_max_relative() -> $T {
$T::EPSILON
}
#[inline]
#[allow(unused_imports)]
fn relative_eq(&self, other: &$T, epsilon: $T, max_relative: $T) -> bool {
use num_traits::float::FloatCore;
// Handle same infinities
if self == other {
return true;
}
// Handle remaining infinities
if $T::is_infinite(*self) || $T::is_infinite(*other) {
return false;
}
let abs_diff = $T::abs(self - other);
// For when the numbers are really close together
if abs_diff <= epsilon {
return true;
}
let abs_self = $T::abs(*self);
let abs_other = $T::abs(*other);
let largest = if abs_other > abs_self {
abs_other
} else {
abs_self
};
// Use a relative difference comparison
abs_diff <= largest * max_relative
}
}
};
}
impl_relative_eq!(f32, i32);
impl_relative_eq!(f64, i64);
///////////////////////////////////////////////////////////////////////////////////////////////////
// Derived implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
impl<'a, T: RelativeEq + ?Sized> RelativeEq for &'a T {
#[inline]
fn default_max_relative() -> T::Epsilon {
T::default_max_relative()
}
#[inline]
fn relative_eq(&self, other: &&'a T, epsilon: T::Epsilon, max_relative: T::Epsilon) -> bool {
T::relative_eq(*self, *other, epsilon, max_relative)
}
}
impl<'a, T: RelativeEq + ?Sized> RelativeEq for &'a mut T {
#[inline]
fn default_max_relative() -> T::Epsilon {
T::default_max_relative()
}
#[inline]
fn relative_eq(
&self,
other: &&'a mut T,
epsilon: T::Epsilon,
max_relative: T::Epsilon,
) -> bool {
T::relative_eq(*self, *other, epsilon, max_relative)
}
}
impl<T: RelativeEq + Copy> RelativeEq for cell::Cell<T> {
#[inline]
fn default_max_relative() -> T::Epsilon {
T::default_max_relative()
}
#[inline]
fn relative_eq(
&self,
other: &cell::Cell<T>,
epsilon: T::Epsilon,
max_relative: T::Epsilon,
) -> bool {
T::relative_eq(&self.get(), &other.get(), epsilon, max_relative)
}
}
impl<T: RelativeEq + ?Sized> RelativeEq for cell::RefCell<T> {
#[inline]
fn default_max_relative() -> T::Epsilon {
T::default_max_relative()
}
#[inline]
fn relative_eq(
&self,
other: &cell::RefCell<T>,
epsilon: T::Epsilon,
max_relative: T::Epsilon,
) -> bool {
T::relative_eq(&self.borrow(), &other.borrow(), epsilon, max_relative)
}
}
impl<A, B> RelativeEq<[B]> for [A]
where
A: RelativeEq<B>,
A::Epsilon: Clone,
{
#[inline]
fn default_max_relative() -> A::Epsilon {
A::default_max_relative()
}
#[inline]
fn relative_eq(&self, other: &[B], epsilon: A::Epsilon, max_relative: A::Epsilon) -> bool {
self.len() == other.len()
&& Iterator::zip(self.iter(), other)
.all(|(x, y)| A::relative_eq(x, y, epsilon.clone(), max_relative.clone()))
}
}
#[cfg(feature = "num-complex")]
impl<T: RelativeEq> RelativeEq for Complex<T>
where
T::Epsilon: Clone,
{
#[inline]
fn default_max_relative() -> T::Epsilon {
T::default_max_relative()
}
#[inline]
fn relative_eq(
&self,
other: &Complex<T>,
epsilon: T::Epsilon,
max_relative: T::Epsilon,
) -> bool {
T::relative_eq(&self.re, &other.re, epsilon.clone(), max_relative.clone())
&& T::relative_eq(&self.im, &other.im, epsilon, max_relative)
}
}

158
vendor/approx/src/ulps_eq.rs vendored Normal file
View File

@@ -0,0 +1,158 @@
use core::cell;
#[cfg(feature = "num-complex")]
use num_complex::Complex;
use num_traits::Signed;
use AbsDiffEq;
/// Equality comparisons between two numbers using both the absolute difference and ULPs
/// (Units in Last Place) based comparisons.
pub trait UlpsEq<Rhs = Self>: AbsDiffEq<Rhs>
where
Rhs: ?Sized,
{
/// The default ULPs to tolerate when testing values that are far-apart.
///
/// This is used when no `max_ulps` value is supplied to the [`ulps_eq`] macro.
fn default_max_ulps() -> u32;
/// A test for equality that uses units in the last place (ULP) if the values are far apart.
fn ulps_eq(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool;
/// The inverse of [`UlpsEq::ulps_eq`].
fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
!Self::ulps_eq(self, other, epsilon, max_ulps)
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Base implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation based on: [Comparing Floating Point Numbers, 2012 Edition]
// (https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/)
macro_rules! impl_ulps_eq {
($T:ident, $U:ident) => {
impl UlpsEq for $T {
#[inline]
fn default_max_ulps() -> u32 {
4
}
#[inline]
fn ulps_eq(&self, other: &$T, epsilon: $T, max_ulps: u32) -> bool {
// For when the numbers are really close together
if $T::abs_diff_eq(self, other, epsilon) {
return true;
}
// Trivial negative sign check
if self.signum() != other.signum() {
return false;
}
// ULPS difference comparison
let int_self: $U = self.to_bits();
let int_other: $U = other.to_bits();
// To be replaced with `abs_sub`, if
// https://github.com/rust-lang/rust/issues/62111 lands.
if int_self <= int_other {
int_other - int_self <= max_ulps as $U
} else {
int_self - int_other <= max_ulps as $U
}
}
}
};
}
impl_ulps_eq!(f32, u32);
impl_ulps_eq!(f64, u64);
///////////////////////////////////////////////////////////////////////////////////////////////////
// Derived implementations
///////////////////////////////////////////////////////////////////////////////////////////////////
impl<'a, T: UlpsEq + ?Sized> UlpsEq for &'a T {
#[inline]
fn default_max_ulps() -> u32 {
T::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &&'a T, epsilon: T::Epsilon, max_ulps: u32) -> bool {
T::ulps_eq(*self, *other, epsilon, max_ulps)
}
}
impl<'a, T: UlpsEq + ?Sized> UlpsEq for &'a mut T {
#[inline]
fn default_max_ulps() -> u32 {
T::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &&'a mut T, epsilon: T::Epsilon, max_ulps: u32) -> bool {
T::ulps_eq(*self, *other, epsilon, max_ulps)
}
}
impl<T: UlpsEq + Copy> UlpsEq for cell::Cell<T> {
#[inline]
fn default_max_ulps() -> u32 {
T::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &cell::Cell<T>, epsilon: T::Epsilon, max_ulps: u32) -> bool {
T::ulps_eq(&self.get(), &other.get(), epsilon, max_ulps)
}
}
impl<T: UlpsEq + ?Sized> UlpsEq for cell::RefCell<T> {
#[inline]
fn default_max_ulps() -> u32 {
T::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &cell::RefCell<T>, epsilon: T::Epsilon, max_ulps: u32) -> bool {
T::ulps_eq(&self.borrow(), &other.borrow(), epsilon, max_ulps)
}
}
impl<A, B> UlpsEq<[B]> for [A]
where
A: UlpsEq<B>,
A::Epsilon: Clone,
{
#[inline]
fn default_max_ulps() -> u32 {
A::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &[B], epsilon: A::Epsilon, max_ulps: u32) -> bool {
self.len() == other.len()
&& Iterator::zip(self.iter(), other)
.all(|(x, y)| A::ulps_eq(x, y, epsilon.clone(), max_ulps))
}
}
#[cfg(feature = "num-complex")]
impl<T: UlpsEq> UlpsEq for Complex<T>
where
T::Epsilon: Clone,
{
#[inline]
fn default_max_ulps() -> u32 {
T::default_max_ulps()
}
#[inline]
fn ulps_eq(&self, other: &Complex<T>, epsilon: T::Epsilon, max_ulps: u32) -> bool {
T::ulps_eq(&self.re, &other.re, epsilon.clone(), max_ulps)
&& T::ulps_eq(&self.im, &other.im, epsilon, max_ulps)
}
}

443
vendor/approx/tests/abs_diff_eq.rs vendored Normal file
View File

@@ -0,0 +1,443 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Test cases derived from:
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]
#[macro_use]
extern crate approx;
mod test_f32 {
use core::f32;
#[test]
fn test_basic() {
assert_abs_diff_eq!(1.0f32, 1.0f32);
assert_abs_diff_ne!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_abs_diff_eq!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_abs_diff_ne!(1.0f32, 1.0f32);
}
#[test]
fn test_big() {
assert_abs_diff_eq!(100000000.0f32, 100000001.0f32);
assert_abs_diff_eq!(100000001.0f32, 100000000.0f32);
assert_abs_diff_ne!(10000.0f32, 10001.0f32);
assert_abs_diff_ne!(10001.0f32, 10000.0f32);
}
#[test]
fn test_big_neg() {
assert_abs_diff_eq!(-100000000.0f32, -100000001.0f32);
assert_abs_diff_eq!(-100000001.0f32, -100000000.0f32);
assert_abs_diff_ne!(-10000.0f32, -10001.0f32);
assert_abs_diff_ne!(-10001.0f32, -10000.0f32);
}
#[test]
fn test_mid() {
assert_abs_diff_eq!(1.0000001f32, 1.0000002f32);
assert_abs_diff_eq!(1.0000002f32, 1.0000001f32);
assert_abs_diff_ne!(1.000001f32, 1.000002f32);
assert_abs_diff_ne!(1.000002f32, 1.000001f32);
}
#[test]
fn test_mid_neg() {
assert_abs_diff_eq!(-1.0000001f32, -1.0000002f32);
assert_abs_diff_eq!(-1.0000002f32, -1.0000001f32);
assert_abs_diff_ne!(-1.000001f32, -1.000002f32);
assert_abs_diff_ne!(-1.000002f32, -1.000001f32);
}
#[test]
fn test_small() {
assert_abs_diff_eq!(0.000010001f32, 0.000010002f32);
assert_abs_diff_eq!(0.000010002f32, 0.000010001f32);
assert_abs_diff_ne!(0.000001002f32, 0.0000001001f32);
assert_abs_diff_ne!(0.000001001f32, 0.0000001002f32);
}
#[test]
fn test_small_neg() {
assert_abs_diff_eq!(-0.000010001f32, -0.000010002f32);
assert_abs_diff_eq!(-0.000010002f32, -0.000010001f32);
assert_abs_diff_ne!(-0.000001002f32, -0.0000001001f32);
assert_abs_diff_ne!(-0.000001001f32, -0.0000001002f32);
}
#[test]
fn test_zero() {
assert_abs_diff_eq!(0.0f32, 0.0f32);
assert_abs_diff_eq!(0.0f32, -0.0f32);
assert_abs_diff_eq!(-0.0f32, -0.0f32);
assert_abs_diff_ne!(0.000001f32, 0.0f32);
assert_abs_diff_ne!(0.0f32, 0.000001f32);
assert_abs_diff_ne!(-0.000001f32, 0.0f32);
assert_abs_diff_ne!(0.0f32, -0.000001f32);
}
#[test]
fn test_epsilon() {
assert_abs_diff_eq!(0.0f32, 1e-40f32, epsilon = 1e-40f32);
assert_abs_diff_eq!(1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_abs_diff_eq!(0.0f32, -1e-40f32, epsilon = 1e-40f32);
assert_abs_diff_eq!(-1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_abs_diff_ne!(1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_abs_diff_ne!(0.0f32, 1e-40f32, epsilon = 1e-41f32);
assert_abs_diff_ne!(-1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_abs_diff_ne!(0.0f32, -1e-40f32, epsilon = 1e-41f32);
}
#[test]
fn test_max() {
assert_abs_diff_eq!(f32::MAX, f32::MAX);
assert_abs_diff_ne!(f32::MAX, -f32::MAX);
assert_abs_diff_ne!(-f32::MAX, f32::MAX);
assert_abs_diff_ne!(f32::MAX, f32::MAX / 2.0);
assert_abs_diff_ne!(f32::MAX, -f32::MAX / 2.0);
assert_abs_diff_ne!(-f32::MAX, f32::MAX / 2.0);
}
// NOTE: abs_diff_eq fails as numbers begin to get very large
// #[test]
// fn test_infinity() {
// assert_abs_diff_eq!(f32::INFINITY, f32::INFINITY);
// assert_abs_diff_eq!(f32::NEG_INFINITY, f32::NEG_INFINITY);
// assert_abs_diff_ne!(f32::NEG_INFINITY, f32::INFINITY);
// assert_abs_diff_eq!(f32::INFINITY, f32::MAX);
// assert_abs_diff_eq!(f32::NEG_INFINITY, -f32::MAX);
// }
#[test]
fn test_nan() {
assert_abs_diff_ne!(f32::NAN, f32::NAN);
assert_abs_diff_ne!(f32::NAN, 0.0);
assert_abs_diff_ne!(-0.0, f32::NAN);
assert_abs_diff_ne!(f32::NAN, -0.0);
assert_abs_diff_ne!(0.0, f32::NAN);
assert_abs_diff_ne!(f32::NAN, f32::INFINITY);
assert_abs_diff_ne!(f32::INFINITY, f32::NAN);
assert_abs_diff_ne!(f32::NAN, f32::NEG_INFINITY);
assert_abs_diff_ne!(f32::NEG_INFINITY, f32::NAN);
assert_abs_diff_ne!(f32::NAN, f32::MAX);
assert_abs_diff_ne!(f32::MAX, f32::NAN);
assert_abs_diff_ne!(f32::NAN, -f32::MAX);
assert_abs_diff_ne!(-f32::MAX, f32::NAN);
assert_abs_diff_ne!(f32::NAN, f32::MIN_POSITIVE);
assert_abs_diff_ne!(f32::MIN_POSITIVE, f32::NAN);
assert_abs_diff_ne!(f32::NAN, -f32::MIN_POSITIVE);
assert_abs_diff_ne!(-f32::MIN_POSITIVE, f32::NAN);
}
#[test]
fn test_opposite_signs() {
assert_abs_diff_ne!(1.000000001f32, -1.0f32);
assert_abs_diff_ne!(-1.0f32, 1.000000001f32);
assert_abs_diff_ne!(-1.000000001f32, 1.0f32);
assert_abs_diff_ne!(1.0f32, -1.000000001f32);
assert_abs_diff_eq!(10.0 * f32::MIN_POSITIVE, 10.0 * -f32::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_abs_diff_eq!(f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_abs_diff_eq!(f32::MIN_POSITIVE, -f32::MIN_POSITIVE);
assert_abs_diff_eq!(-f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_abs_diff_eq!(f32::MIN_POSITIVE, 0.0f32);
assert_abs_diff_eq!(0.0f32, f32::MIN_POSITIVE);
assert_abs_diff_eq!(-f32::MIN_POSITIVE, 0.0f32);
assert_abs_diff_eq!(0.0f32, -f32::MIN_POSITIVE);
assert_abs_diff_ne!(0.000001f32, -f32::MIN_POSITIVE);
assert_abs_diff_ne!(0.000001f32, f32::MIN_POSITIVE);
assert_abs_diff_ne!(f32::MIN_POSITIVE, 0.000001f32);
assert_abs_diff_ne!(-f32::MIN_POSITIVE, 0.000001f32);
}
}
#[cfg(test)]
mod test_f64 {
use core::f64;
#[test]
fn test_basic() {
assert_abs_diff_eq!(1.0f64, 1.0f64);
assert_abs_diff_ne!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_abs_diff_eq!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_abs_diff_ne!(1.0f64, 1.0f64);
}
#[test]
fn test_big() {
assert_abs_diff_eq!(10000000000000000.0f64, 10000000000000001.0f64);
assert_abs_diff_eq!(10000000000000001.0f64, 10000000000000000.0f64);
assert_abs_diff_ne!(1000000000000000.0f64, 1000000000000001.0f64);
assert_abs_diff_ne!(1000000000000001.0f64, 1000000000000000.0f64);
}
#[test]
fn test_big_neg() {
assert_abs_diff_eq!(-10000000000000000.0f64, -10000000000000001.0f64);
assert_abs_diff_eq!(-10000000000000001.0f64, -10000000000000000.0f64);
assert_abs_diff_ne!(-1000000000000000.0f64, -1000000000000001.0f64);
assert_abs_diff_ne!(-1000000000000001.0f64, -1000000000000000.0f64);
}
#[test]
fn test_mid() {
assert_abs_diff_eq!(1.0000000000000001f64, 1.0000000000000002f64);
assert_abs_diff_eq!(1.0000000000000002f64, 1.0000000000000001f64);
assert_abs_diff_ne!(1.000000000000001f64, 1.000000000000002f64);
assert_abs_diff_ne!(1.000000000000002f64, 1.000000000000001f64);
}
#[test]
fn test_mid_neg() {
assert_abs_diff_eq!(-1.0000000000000001f64, -1.0000000000000002f64);
assert_abs_diff_eq!(-1.0000000000000002f64, -1.0000000000000001f64);
assert_abs_diff_ne!(-1.000000000000001f64, -1.000000000000002f64);
assert_abs_diff_ne!(-1.000000000000002f64, -1.000000000000001f64);
}
#[test]
fn test_small() {
assert_abs_diff_eq!(0.0000000100000001f64, 0.0000000100000002f64);
assert_abs_diff_eq!(0.0000000100000002f64, 0.0000000100000001f64);
assert_abs_diff_ne!(0.0000000100000001f64, 0.0000000010000002f64);
assert_abs_diff_ne!(0.0000000100000002f64, 0.0000000010000001f64);
}
#[test]
fn test_small_neg() {
assert_abs_diff_eq!(-0.0000000100000001f64, -0.0000000100000002f64);
assert_abs_diff_eq!(-0.0000000100000002f64, -0.0000000100000001f64);
assert_abs_diff_ne!(-0.0000000100000001f64, -0.0000000010000002f64);
assert_abs_diff_ne!(-0.0000000100000002f64, -0.0000000010000001f64);
}
#[test]
fn test_zero() {
assert_abs_diff_eq!(0.0f64, 0.0f64);
assert_abs_diff_eq!(0.0f64, -0.0f64);
assert_abs_diff_eq!(-0.0f64, -0.0f64);
assert_abs_diff_ne!(0.000000000000001f64, 0.0f64);
assert_abs_diff_ne!(0.0f64, 0.000000000000001f64);
assert_abs_diff_ne!(-0.000000000000001f64, 0.0f64);
assert_abs_diff_ne!(0.0f64, -0.000000000000001f64);
}
#[test]
fn test_epsilon() {
assert_abs_diff_eq!(0.0f64, 1e-40f64, epsilon = 1e-40f64);
assert_abs_diff_eq!(1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_abs_diff_eq!(0.0f64, -1e-40f64, epsilon = 1e-40f64);
assert_abs_diff_eq!(-1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_abs_diff_ne!(1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_abs_diff_ne!(0.0f64, 1e-40f64, epsilon = 1e-41f64);
assert_abs_diff_ne!(-1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_abs_diff_ne!(0.0f64, -1e-40f64, epsilon = 1e-41f64);
}
#[test]
fn test_max() {
assert_abs_diff_eq!(f64::MAX, f64::MAX);
assert_abs_diff_ne!(f64::MAX, -f64::MAX);
assert_abs_diff_ne!(-f64::MAX, f64::MAX);
assert_abs_diff_ne!(f64::MAX, f64::MAX / 2.0);
assert_abs_diff_ne!(f64::MAX, -f64::MAX / 2.0);
assert_abs_diff_ne!(-f64::MAX, f64::MAX / 2.0);
}
// NOTE: abs_diff_eq fails as numbers begin to get very large
// #[test]
// fn test_infinity() {
// assert_abs_diff_eq!(f64::INFINITY, f64::INFINITY);
// assert_abs_diff_eq!(f64::NEG_INFINITY, f64::NEG_INFINITY);
// assert_abs_diff_ne!(f64::NEG_INFINITY, f64::INFINITY);
// assert_abs_diff_eq!(f64::INFINITY, f64::MAX);
// assert_abs_diff_eq!(f64::NEG_INFINITY, -f64::MAX);
// }
#[test]
fn test_nan() {
assert_abs_diff_ne!(f64::NAN, f64::NAN);
assert_abs_diff_ne!(f64::NAN, 0.0);
assert_abs_diff_ne!(-0.0, f64::NAN);
assert_abs_diff_ne!(f64::NAN, -0.0);
assert_abs_diff_ne!(0.0, f64::NAN);
assert_abs_diff_ne!(f64::NAN, f64::INFINITY);
assert_abs_diff_ne!(f64::INFINITY, f64::NAN);
assert_abs_diff_ne!(f64::NAN, f64::NEG_INFINITY);
assert_abs_diff_ne!(f64::NEG_INFINITY, f64::NAN);
assert_abs_diff_ne!(f64::NAN, f64::MAX);
assert_abs_diff_ne!(f64::MAX, f64::NAN);
assert_abs_diff_ne!(f64::NAN, -f64::MAX);
assert_abs_diff_ne!(-f64::MAX, f64::NAN);
assert_abs_diff_ne!(f64::NAN, f64::MIN_POSITIVE);
assert_abs_diff_ne!(f64::MIN_POSITIVE, f64::NAN);
assert_abs_diff_ne!(f64::NAN, -f64::MIN_POSITIVE);
assert_abs_diff_ne!(-f64::MIN_POSITIVE, f64::NAN);
}
#[test]
fn test_opposite_signs() {
assert_abs_diff_ne!(1.000000001f64, -1.0f64);
assert_abs_diff_ne!(-1.0f64, 1.000000001f64);
assert_abs_diff_ne!(-1.000000001f64, 1.0f64);
assert_abs_diff_ne!(1.0f64, -1.000000001f64);
assert_abs_diff_eq!(10.0 * f64::MIN_POSITIVE, 10.0 * -f64::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_abs_diff_eq!(f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_abs_diff_eq!(f64::MIN_POSITIVE, -f64::MIN_POSITIVE);
assert_abs_diff_eq!(-f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_abs_diff_eq!(f64::MIN_POSITIVE, 0.0f64);
assert_abs_diff_eq!(0.0f64, f64::MIN_POSITIVE);
assert_abs_diff_eq!(-f64::MIN_POSITIVE, 0.0f64);
assert_abs_diff_eq!(0.0f64, -f64::MIN_POSITIVE);
assert_abs_diff_ne!(0.000000000000001f64, -f64::MIN_POSITIVE);
assert_abs_diff_ne!(0.000000000000001f64, f64::MIN_POSITIVE);
assert_abs_diff_ne!(f64::MIN_POSITIVE, 0.000000000000001f64);
assert_abs_diff_ne!(-f64::MIN_POSITIVE, 0.000000000000001f64);
}
}
mod test_ref {
mod test_f32 {
#[test]
fn test_basic() {
assert_abs_diff_eq!(&1.0f32, &1.0f32);
assert_abs_diff_ne!(&1.0f32, &2.0f32);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_abs_diff_eq!(&1.0f64, &1.0f64);
assert_abs_diff_ne!(&1.0f64, &2.0f64);
}
}
}
mod test_slice {
mod test_f32 {
#[test]
fn test_basic() {
assert_abs_diff_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
assert_abs_diff_ne!([1.0f32, 2.0f32][..], [2.0f32, 1.0f32][..]);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_abs_diff_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
assert_abs_diff_ne!([1.0f64, 2.0f64][..], [2.0f64, 1.0f64][..]);
}
}
}
#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
mod test_f32 {
use super::Complex;
#[test]
fn test_basic() {
assert_abs_diff_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
assert_abs_diff_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_abs_diff_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_abs_diff_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
}
}
mod test_f64 {
use super::Complex;
#[test]
fn test_basic() {
assert_abs_diff_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
assert_abs_diff_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_abs_diff_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_abs_diff_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
}
}
}

18
vendor/approx/tests/macro_import.rs vendored Normal file
View File

@@ -0,0 +1,18 @@
extern crate approx;
mod test_macro_import {
use approx::{
assert_abs_diff_eq, assert_abs_diff_ne, assert_relative_eq, assert_relative_ne,
assert_ulps_eq, assert_ulps_ne,
};
#[test]
fn test() {
assert_abs_diff_eq!(1.0f32, 1.0f32);
assert_abs_diff_ne!(1.0f32, 2.0f32);
assert_relative_eq!(1.0f32, 1.0f32);
assert_relative_ne!(1.0f32, 2.0f32);
assert_ulps_eq!(1.0f32, 1.0f32);
assert_ulps_ne!(1.0f32, 2.0f32);
}
}

105
vendor/approx/tests/macros.rs vendored Normal file
View File

@@ -0,0 +1,105 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Macro instantiation tests
#[macro_use]
extern crate approx;
#[test]
fn test_abs_diff_eq() {
let _: bool = abs_diff_eq!(1.0, 1.0);
let _: bool = abs_diff_eq!(1.0, 1.0, epsilon = 1.0);
}
#[test]
fn test_abs_diff_eq_trailing_commas() {
let _: bool = abs_diff_eq!(1.0, 1.0,);
let _: bool = abs_diff_eq!(1.0, 1.0, epsilon = 1.0,);
}
#[test]
fn test_abs_diff_ne() {
let _: bool = abs_diff_ne!(1.0, 1.0);
let _: bool = abs_diff_ne!(1.0, 1.0, epsilon = 1.0);
}
#[test]
fn test_abs_diff_ne_trailing_commas() {
let _: bool = abs_diff_ne!(1.0, 1.0,);
let _: bool = abs_diff_ne!(1.0, 1.0, epsilon = 1.0,);
}
#[test]
fn test_relative_eq() {
let _: bool = relative_eq!(1.0, 1.0);
let _: bool = relative_eq!(1.0, 1.0, epsilon = 1.0);
let _: bool = relative_eq!(1.0, 1.0, max_relative = 1.0);
let _: bool = relative_eq!(1.0, 1.0, epsilon = 1.0, max_relative = 1.0);
}
#[test]
fn test_relative_eq_trailing_commas() {
let _: bool = relative_eq!(1.0, 1.0,);
let _: bool = relative_eq!(1.0, 1.0, epsilon = 1.0, max_relative = 1.0,);
}
#[test]
fn test_relative_ne() {
let _: bool = relative_ne!(1.0, 1.0);
let _: bool = relative_ne!(1.0, 1.0, epsilon = 1.0);
let _: bool = relative_ne!(1.0, 1.0, max_relative = 1.0);
let _: bool = relative_ne!(1.0, 1.0, epsilon = 1.0, max_relative = 1.0);
}
#[test]
fn test_relative_ne_trailing_commas() {
let _: bool = relative_ne!(1.0, 1.0,);
let _: bool = relative_ne!(1.0, 1.0, epsilon = 1.0, max_relative = 1.0,);
}
#[test]
fn test_ulps_eq() {
let _: bool = ulps_eq!(1.0, 1.0);
let _: bool = ulps_eq!(1.0, 1.0, epsilon = 1.0);
let _: bool = ulps_eq!(1.0, 1.0, max_ulps = 1);
let _: bool = ulps_eq!(1.0, 1.0, epsilon = 1.0, max_ulps = 1);
}
#[test]
fn test_ulps_eq_trailing_commas() {
let _: bool = ulps_eq!(1.0, 1.0,);
let _: bool = ulps_eq!(1.0, 1.0, epsilon = 1.0, max_ulps = 1,);
}
#[test]
fn test_ulps_ne() {
let _: bool = ulps_ne!(1.0, 1.0);
let _: bool = ulps_ne!(1.0, 1.0, epsilon = 1.0);
let _: bool = ulps_ne!(1.0, 1.0, max_ulps = 1);
let _: bool = ulps_ne!(1.0, 1.0, epsilon = 1.0, max_ulps = 1);
}
#[test]
fn test_ulps_ne_trailing_commas() {
let _: bool = ulps_ne!(1.0, 1.0,);
let _: bool = ulps_ne!(1.0, 1.0, epsilon = 1.0, max_ulps = 1,);
}
#[test]
fn test_rvalue_arguments() {
assert_abs_diff_eq!(vec![0.0].as_slice(), vec![0.0].as_slice());
assert_relative_eq!(vec![0.0].as_slice(), vec![0.0].as_slice());
assert_ulps_eq!(vec![0.0].as_slice(), vec![0.0].as_slice());
}

441
vendor/approx/tests/relative_eq.rs vendored Normal file
View File

@@ -0,0 +1,441 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Test cases derived from:
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]
#[macro_use]
extern crate approx;
mod test_f32 {
use core::f32;
#[test]
fn test_basic() {
assert_relative_eq!(1.0f32, 1.0f32);
assert_relative_ne!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_relative_eq!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_relative_ne!(1.0f32, 1.0f32);
}
#[test]
fn test_big() {
assert_relative_eq!(100000000.0f32, 100000001.0f32);
assert_relative_eq!(100000001.0f32, 100000000.0f32);
assert_relative_ne!(10000.0f32, 10001.0f32);
assert_relative_ne!(10001.0f32, 10000.0f32);
}
#[test]
fn test_big_neg() {
assert_relative_eq!(-100000000.0f32, -100000001.0f32);
assert_relative_eq!(-100000001.0f32, -100000000.0f32);
assert_relative_ne!(-10000.0f32, -10001.0f32);
assert_relative_ne!(-10001.0f32, -10000.0f32);
}
#[test]
fn test_mid() {
assert_relative_eq!(1.0000001f32, 1.0000002f32);
assert_relative_eq!(1.0000002f32, 1.0000001f32);
assert_relative_ne!(1.000001f32, 1.000002f32);
assert_relative_ne!(1.000002f32, 1.000001f32);
}
#[test]
fn test_mid_neg() {
assert_relative_eq!(-1.0000001f32, -1.0000002f32);
assert_relative_eq!(-1.0000002f32, -1.0000001f32);
assert_relative_ne!(-1.000001f32, -1.000002f32);
assert_relative_ne!(-1.000002f32, -1.000001f32);
}
#[test]
fn test_small() {
assert_relative_eq!(0.000010001f32, 0.000010002f32);
assert_relative_eq!(0.000010002f32, 0.000010001f32);
assert_relative_ne!(0.000001002f32, 0.0000001001f32);
assert_relative_ne!(0.000001001f32, 0.0000001002f32);
}
#[test]
fn test_small_neg() {
assert_relative_eq!(-0.000010001f32, -0.000010002f32);
assert_relative_eq!(-0.000010002f32, -0.000010001f32);
assert_relative_ne!(-0.000001002f32, -0.0000001001f32);
assert_relative_ne!(-0.000001001f32, -0.0000001002f32);
}
#[test]
fn test_zero() {
assert_relative_eq!(0.0f32, 0.0f32);
assert_relative_eq!(0.0f32, -0.0f32);
assert_relative_eq!(-0.0f32, -0.0f32);
assert_relative_ne!(0.000001f32, 0.0f32);
assert_relative_ne!(0.0f32, 0.000001f32);
assert_relative_ne!(-0.000001f32, 0.0f32);
assert_relative_ne!(0.0f32, -0.000001f32);
}
#[test]
fn test_epsilon() {
assert_relative_eq!(0.0f32, 1e-40f32, epsilon = 1e-40f32);
assert_relative_eq!(1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_relative_eq!(0.0f32, -1e-40f32, epsilon = 1e-40f32);
assert_relative_eq!(-1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_relative_ne!(1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_relative_ne!(0.0f32, 1e-40f32, epsilon = 1e-41f32);
assert_relative_ne!(-1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_relative_ne!(0.0f32, -1e-40f32, epsilon = 1e-41f32);
}
#[test]
fn test_max() {
assert_relative_eq!(f32::MAX, f32::MAX);
assert_relative_ne!(f32::MAX, -f32::MAX);
assert_relative_ne!(-f32::MAX, f32::MAX);
assert_relative_ne!(f32::MAX, f32::MAX / 2.0);
assert_relative_ne!(f32::MAX, -f32::MAX / 2.0);
assert_relative_ne!(-f32::MAX, f32::MAX / 2.0);
}
#[test]
fn test_infinity() {
assert_relative_eq!(f32::INFINITY, f32::INFINITY);
assert_relative_eq!(f32::NEG_INFINITY, f32::NEG_INFINITY);
assert_relative_ne!(f32::NEG_INFINITY, f32::INFINITY);
}
#[test]
fn test_zero_infinity() {
assert_relative_ne!(0f32, f32::INFINITY);
assert_relative_ne!(0f32, f32::NEG_INFINITY);
}
#[test]
fn test_nan() {
assert_relative_ne!(f32::NAN, f32::NAN);
assert_relative_ne!(f32::NAN, 0.0);
assert_relative_ne!(-0.0, f32::NAN);
assert_relative_ne!(f32::NAN, -0.0);
assert_relative_ne!(0.0, f32::NAN);
assert_relative_ne!(f32::NAN, f32::INFINITY);
assert_relative_ne!(f32::INFINITY, f32::NAN);
assert_relative_ne!(f32::NAN, f32::NEG_INFINITY);
assert_relative_ne!(f32::NEG_INFINITY, f32::NAN);
assert_relative_ne!(f32::NAN, f32::MAX);
assert_relative_ne!(f32::MAX, f32::NAN);
assert_relative_ne!(f32::NAN, -f32::MAX);
assert_relative_ne!(-f32::MAX, f32::NAN);
assert_relative_ne!(f32::NAN, f32::MIN_POSITIVE);
assert_relative_ne!(f32::MIN_POSITIVE, f32::NAN);
assert_relative_ne!(f32::NAN, -f32::MIN_POSITIVE);
assert_relative_ne!(-f32::MIN_POSITIVE, f32::NAN);
}
#[test]
fn test_opposite_signs() {
assert_relative_ne!(1.000000001f32, -1.0f32);
assert_relative_ne!(-1.0f32, 1.000000001f32);
assert_relative_ne!(-1.000000001f32, 1.0f32);
assert_relative_ne!(1.0f32, -1.000000001f32);
assert_relative_eq!(10.0 * f32::MIN_POSITIVE, 10.0 * -f32::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_relative_eq!(f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_relative_eq!(f32::MIN_POSITIVE, -f32::MIN_POSITIVE);
assert_relative_eq!(-f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_relative_eq!(f32::MIN_POSITIVE, 0.0f32);
assert_relative_eq!(0.0f32, f32::MIN_POSITIVE);
assert_relative_eq!(-f32::MIN_POSITIVE, 0.0f32);
assert_relative_eq!(0.0f32, -f32::MIN_POSITIVE);
assert_relative_ne!(0.000001f32, -f32::MIN_POSITIVE);
assert_relative_ne!(0.000001f32, f32::MIN_POSITIVE);
assert_relative_ne!(f32::MIN_POSITIVE, 0.000001f32);
assert_relative_ne!(-f32::MIN_POSITIVE, 0.000001f32);
}
}
#[cfg(test)]
mod test_f64 {
use core::f64;
#[test]
fn test_basic() {
assert_relative_eq!(1.0f64, 1.0f64);
assert_relative_ne!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_relative_eq!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_relative_ne!(1.0f64, 1.0f64);
}
#[test]
fn test_big() {
assert_relative_eq!(10000000000000000.0f64, 10000000000000001.0f64);
assert_relative_eq!(10000000000000001.0f64, 10000000000000000.0f64);
assert_relative_ne!(1000000000000000.0f64, 1000000000000001.0f64);
assert_relative_ne!(1000000000000001.0f64, 1000000000000000.0f64);
}
#[test]
fn test_big_neg() {
assert_relative_eq!(-10000000000000000.0f64, -10000000000000001.0f64);
assert_relative_eq!(-10000000000000001.0f64, -10000000000000000.0f64);
assert_relative_ne!(-1000000000000000.0f64, -1000000000000001.0f64);
assert_relative_ne!(-1000000000000001.0f64, -1000000000000000.0f64);
}
#[test]
fn test_mid() {
assert_relative_eq!(1.0000000000000001f64, 1.0000000000000002f64);
assert_relative_eq!(1.0000000000000002f64, 1.0000000000000001f64);
assert_relative_ne!(1.000000000000001f64, 1.000000000000002f64);
assert_relative_ne!(1.000000000000002f64, 1.000000000000001f64);
}
#[test]
fn test_mid_neg() {
assert_relative_eq!(-1.0000000000000001f64, -1.0000000000000002f64);
assert_relative_eq!(-1.0000000000000002f64, -1.0000000000000001f64);
assert_relative_ne!(-1.000000000000001f64, -1.000000000000002f64);
assert_relative_ne!(-1.000000000000002f64, -1.000000000000001f64);
}
#[test]
fn test_small() {
assert_relative_eq!(0.0000000100000001f64, 0.0000000100000002f64);
assert_relative_eq!(0.0000000100000002f64, 0.0000000100000001f64);
assert_relative_ne!(0.0000000100000001f64, 0.0000000010000002f64);
assert_relative_ne!(0.0000000100000002f64, 0.0000000010000001f64);
}
#[test]
fn test_small_neg() {
assert_relative_eq!(-0.0000000100000001f64, -0.0000000100000002f64);
assert_relative_eq!(-0.0000000100000002f64, -0.0000000100000001f64);
assert_relative_ne!(-0.0000000100000001f64, -0.0000000010000002f64);
assert_relative_ne!(-0.0000000100000002f64, -0.0000000010000001f64);
}
#[test]
fn test_zero() {
assert_relative_eq!(0.0f64, 0.0f64);
assert_relative_eq!(0.0f64, -0.0f64);
assert_relative_eq!(-0.0f64, -0.0f64);
assert_relative_ne!(0.000000000000001f64, 0.0f64);
assert_relative_ne!(0.0f64, 0.000000000000001f64);
assert_relative_ne!(-0.000000000000001f64, 0.0f64);
assert_relative_ne!(0.0f64, -0.000000000000001f64);
}
#[test]
fn test_epsilon() {
assert_relative_eq!(0.0f64, 1e-40f64, epsilon = 1e-40f64);
assert_relative_eq!(1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_relative_eq!(0.0f64, -1e-40f64, epsilon = 1e-40f64);
assert_relative_eq!(-1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_relative_ne!(1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_relative_ne!(0.0f64, 1e-40f64, epsilon = 1e-41f64);
assert_relative_ne!(-1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_relative_ne!(0.0f64, -1e-40f64, epsilon = 1e-41f64);
}
#[test]
fn test_max() {
assert_relative_eq!(f64::MAX, f64::MAX);
assert_relative_ne!(f64::MAX, -f64::MAX);
assert_relative_ne!(-f64::MAX, f64::MAX);
assert_relative_ne!(f64::MAX, f64::MAX / 2.0);
assert_relative_ne!(f64::MAX, -f64::MAX / 2.0);
assert_relative_ne!(-f64::MAX, f64::MAX / 2.0);
}
#[test]
fn test_infinity() {
assert_relative_eq!(f64::INFINITY, f64::INFINITY);
assert_relative_eq!(f64::NEG_INFINITY, f64::NEG_INFINITY);
assert_relative_ne!(f64::NEG_INFINITY, f64::INFINITY);
}
#[test]
fn test_nan() {
assert_relative_ne!(f64::NAN, f64::NAN);
assert_relative_ne!(f64::NAN, 0.0);
assert_relative_ne!(-0.0, f64::NAN);
assert_relative_ne!(f64::NAN, -0.0);
assert_relative_ne!(0.0, f64::NAN);
assert_relative_ne!(f64::NAN, f64::INFINITY);
assert_relative_ne!(f64::INFINITY, f64::NAN);
assert_relative_ne!(f64::NAN, f64::NEG_INFINITY);
assert_relative_ne!(f64::NEG_INFINITY, f64::NAN);
assert_relative_ne!(f64::NAN, f64::MAX);
assert_relative_ne!(f64::MAX, f64::NAN);
assert_relative_ne!(f64::NAN, -f64::MAX);
assert_relative_ne!(-f64::MAX, f64::NAN);
assert_relative_ne!(f64::NAN, f64::MIN_POSITIVE);
assert_relative_ne!(f64::MIN_POSITIVE, f64::NAN);
assert_relative_ne!(f64::NAN, -f64::MIN_POSITIVE);
assert_relative_ne!(-f64::MIN_POSITIVE, f64::NAN);
}
#[test]
fn test_opposite_signs() {
assert_relative_ne!(1.000000001f64, -1.0f64);
assert_relative_ne!(-1.0f64, 1.000000001f64);
assert_relative_ne!(-1.000000001f64, 1.0f64);
assert_relative_ne!(1.0f64, -1.000000001f64);
assert_relative_eq!(10.0 * f64::MIN_POSITIVE, 10.0 * -f64::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_relative_eq!(f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_relative_eq!(f64::MIN_POSITIVE, -f64::MIN_POSITIVE);
assert_relative_eq!(-f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_relative_eq!(f64::MIN_POSITIVE, 0.0f64);
assert_relative_eq!(0.0f64, f64::MIN_POSITIVE);
assert_relative_eq!(-f64::MIN_POSITIVE, 0.0f64);
assert_relative_eq!(0.0f64, -f64::MIN_POSITIVE);
assert_relative_ne!(0.000000000000001f64, -f64::MIN_POSITIVE);
assert_relative_ne!(0.000000000000001f64, f64::MIN_POSITIVE);
assert_relative_ne!(f64::MIN_POSITIVE, 0.000000000000001f64);
assert_relative_ne!(-f64::MIN_POSITIVE, 0.000000000000001f64);
}
}
mod test_ref {
mod test_f32 {
#[test]
fn test_basic() {
assert_relative_eq!(&1.0f32, &1.0f32);
assert_relative_ne!(&1.0f32, &2.0f32);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_relative_eq!(&1.0f64, &1.0f64);
assert_relative_ne!(&1.0f64, &2.0f64);
}
}
}
mod test_slice {
mod test_f32 {
#[test]
fn test_basic() {
assert_relative_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
assert_relative_ne!([1.0f32, 2.0f32][..], [2.0f32, 1.0f32][..]);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_relative_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
assert_relative_ne!([1.0f64, 2.0f64][..], [2.0f64, 1.0f64][..]);
}
}
}
#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
mod test_f32 {
use super::Complex;
#[test]
fn test_basic() {
assert_relative_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
assert_relative_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_relative_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_relative_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
}
}
mod test_f64 {
use super::Complex;
#[test]
fn test_basic() {
assert_relative_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
assert_relative_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_relative_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_relative_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
}
}
}

439
vendor/approx/tests/ulps_eq.rs vendored Normal file
View File

@@ -0,0 +1,439 @@
// Copyright 2015 Brendan Zabarauskas
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Test cases derived from:
// https://github.com/Pybonacci/puntoflotante.org/blob/master/content/errors/NearlyEqualsTest.java
#![no_std]
#[macro_use]
extern crate approx;
mod test_f32 {
use core::f32;
#[test]
fn test_basic() {
assert_ulps_eq!(1.0f32, 1.0f32);
assert_ulps_ne!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_ulps_eq!(1.0f32, 2.0f32);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_ulps_ne!(1.0f32, 1.0f32);
}
#[test]
fn test_big() {
assert_ulps_eq!(100000000.0f32, 100000001.0f32);
assert_ulps_eq!(100000001.0f32, 100000000.0f32);
assert_ulps_ne!(10000.0f32, 10001.0f32);
assert_ulps_ne!(10001.0f32, 10000.0f32);
}
#[test]
fn test_big_neg() {
assert_ulps_eq!(-100000000.0f32, -100000001.0f32);
assert_ulps_eq!(-100000001.0f32, -100000000.0f32);
assert_ulps_ne!(-10000.0f32, -10001.0f32);
assert_ulps_ne!(-10001.0f32, -10000.0f32);
}
#[test]
fn test_mid() {
assert_ulps_eq!(1.0000001f32, 1.0000002f32);
assert_ulps_eq!(1.0000002f32, 1.0000001f32);
assert_ulps_ne!(1.000001f32, 1.000002f32);
assert_ulps_ne!(1.000002f32, 1.000001f32);
}
#[test]
fn test_mid_neg() {
assert_ulps_eq!(-1.0000001f32, -1.0000002f32);
assert_ulps_eq!(-1.0000002f32, -1.0000001f32);
assert_ulps_ne!(-1.000001f32, -1.000002f32);
assert_ulps_ne!(-1.000002f32, -1.000001f32);
}
#[test]
fn test_small() {
assert_ulps_eq!(0.000010001f32, 0.000010002f32);
assert_ulps_eq!(0.000010002f32, 0.000010001f32);
assert_ulps_ne!(0.000001002f32, 0.0000001001f32);
assert_ulps_ne!(0.000001001f32, 0.0000001002f32);
}
#[test]
fn test_small_neg() {
assert_ulps_eq!(-0.000010001f32, -0.000010002f32);
assert_ulps_eq!(-0.000010002f32, -0.000010001f32);
assert_ulps_ne!(-0.000001002f32, -0.0000001001f32);
assert_ulps_ne!(-0.000001001f32, -0.0000001002f32);
}
#[test]
fn test_zero() {
assert_ulps_eq!(0.0f32, 0.0f32);
assert_ulps_eq!(0.0f32, -0.0f32);
assert_ulps_eq!(-0.0f32, -0.0f32);
assert_ulps_ne!(0.000001f32, 0.0f32);
assert_ulps_ne!(0.0f32, 0.000001f32);
assert_ulps_ne!(-0.000001f32, 0.0f32);
assert_ulps_ne!(0.0f32, -0.000001f32);
}
#[test]
fn test_epsilon() {
assert_ulps_eq!(0.0f32, 1e-40f32, epsilon = 1e-40f32);
assert_ulps_eq!(1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_ulps_eq!(0.0f32, -1e-40f32, epsilon = 1e-40f32);
assert_ulps_eq!(-1e-40f32, 0.0f32, epsilon = 1e-40f32);
assert_ulps_ne!(1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_ulps_ne!(0.0f32, 1e-40f32, epsilon = 1e-41f32);
assert_ulps_ne!(-1e-40f32, 0.0f32, epsilon = 1e-41f32);
assert_ulps_ne!(0.0f32, -1e-40f32, epsilon = 1e-41f32);
}
#[test]
fn test_max() {
assert_ulps_eq!(f32::MAX, f32::MAX);
assert_ulps_ne!(f32::MAX, -f32::MAX);
assert_ulps_ne!(-f32::MAX, f32::MAX);
assert_ulps_ne!(f32::MAX, f32::MAX / 2.0);
assert_ulps_ne!(f32::MAX, -f32::MAX / 2.0);
assert_ulps_ne!(-f32::MAX, f32::MAX / 2.0);
}
#[test]
fn test_infinity() {
assert_ulps_eq!(f32::INFINITY, f32::INFINITY);
assert_ulps_eq!(f32::NEG_INFINITY, f32::NEG_INFINITY);
assert_ulps_ne!(f32::NEG_INFINITY, f32::INFINITY);
assert_ulps_eq!(f32::INFINITY, f32::MAX);
assert_ulps_eq!(f32::NEG_INFINITY, -f32::MAX);
}
#[test]
fn test_nan() {
assert_ulps_ne!(f32::NAN, f32::NAN);
assert_ulps_ne!(f32::NAN, 0.0);
assert_ulps_ne!(-0.0, f32::NAN);
assert_ulps_ne!(f32::NAN, -0.0);
assert_ulps_ne!(0.0, f32::NAN);
assert_ulps_ne!(f32::NAN, f32::INFINITY);
assert_ulps_ne!(f32::INFINITY, f32::NAN);
assert_ulps_ne!(f32::NAN, f32::NEG_INFINITY);
assert_ulps_ne!(f32::NEG_INFINITY, f32::NAN);
assert_ulps_ne!(f32::NAN, f32::MAX);
assert_ulps_ne!(f32::MAX, f32::NAN);
assert_ulps_ne!(f32::NAN, -f32::MAX);
assert_ulps_ne!(-f32::MAX, f32::NAN);
assert_ulps_ne!(f32::NAN, f32::MIN_POSITIVE);
assert_ulps_ne!(f32::MIN_POSITIVE, f32::NAN);
assert_ulps_ne!(f32::NAN, -f32::MIN_POSITIVE);
assert_ulps_ne!(-f32::MIN_POSITIVE, f32::NAN);
}
#[test]
fn test_opposite_signs() {
assert_ulps_ne!(1.000000001f32, -1.0f32);
assert_ulps_ne!(-1.0f32, 1.000000001f32);
assert_ulps_ne!(-1.000000001f32, 1.0f32);
assert_ulps_ne!(1.0f32, -1.000000001f32);
assert_ulps_eq!(10.0 * f32::MIN_POSITIVE, 10.0 * -f32::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_ulps_eq!(f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_ulps_eq!(f32::MIN_POSITIVE, -f32::MIN_POSITIVE);
assert_ulps_eq!(-f32::MIN_POSITIVE, f32::MIN_POSITIVE);
assert_ulps_eq!(f32::MIN_POSITIVE, 0.0f32);
assert_ulps_eq!(0.0f32, f32::MIN_POSITIVE);
assert_ulps_eq!(-f32::MIN_POSITIVE, 0.0f32);
assert_ulps_eq!(0.0f32, -f32::MIN_POSITIVE);
assert_ulps_ne!(0.000001f32, -f32::MIN_POSITIVE);
assert_ulps_ne!(0.000001f32, f32::MIN_POSITIVE);
assert_ulps_ne!(f32::MIN_POSITIVE, 0.000001f32);
assert_ulps_ne!(-f32::MIN_POSITIVE, 0.000001f32);
}
}
#[cfg(test)]
mod test_f64 {
use core::f64;
#[test]
fn test_basic() {
assert_ulps_eq!(1.0f64, 1.0f64);
assert_ulps_ne!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_ulps_eq!(1.0f64, 2.0f64);
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_ulps_ne!(1.0f64, 1.0f64);
}
#[test]
fn test_big() {
assert_ulps_eq!(10000000000000000.0f64, 10000000000000001.0f64);
assert_ulps_eq!(10000000000000001.0f64, 10000000000000000.0f64);
assert_ulps_ne!(1000000000000000.0f64, 1000000000000001.0f64);
assert_ulps_ne!(1000000000000001.0f64, 1000000000000000.0f64);
}
#[test]
fn test_big_neg() {
assert_ulps_eq!(-10000000000000000.0f64, -10000000000000001.0f64);
assert_ulps_eq!(-10000000000000001.0f64, -10000000000000000.0f64);
assert_ulps_ne!(-1000000000000000.0f64, -1000000000000001.0f64);
assert_ulps_ne!(-1000000000000001.0f64, -1000000000000000.0f64);
}
#[test]
fn test_mid() {
assert_ulps_eq!(1.0000000000000001f64, 1.0000000000000002f64);
assert_ulps_eq!(1.0000000000000002f64, 1.0000000000000001f64);
assert_ulps_ne!(1.000000000000001f64, 1.0000000000000022f64);
assert_ulps_ne!(1.0000000000000022f64, 1.000000000000001f64);
}
#[test]
fn test_mid_neg() {
assert_ulps_eq!(-1.0000000000000001f64, -1.0000000000000002f64);
assert_ulps_eq!(-1.0000000000000002f64, -1.0000000000000001f64);
assert_ulps_ne!(-1.000000000000001f64, -1.0000000000000022f64);
assert_ulps_ne!(-1.0000000000000022f64, -1.000000000000001f64);
}
#[test]
fn test_small() {
assert_ulps_eq!(0.0000000100000001f64, 0.0000000100000002f64);
assert_ulps_eq!(0.0000000100000002f64, 0.0000000100000001f64);
assert_ulps_ne!(0.0000000100000001f64, 0.0000000010000002f64);
assert_ulps_ne!(0.0000000100000002f64, 0.0000000010000001f64);
}
#[test]
fn test_small_neg() {
assert_ulps_eq!(-0.0000000100000001f64, -0.0000000100000002f64);
assert_ulps_eq!(-0.0000000100000002f64, -0.0000000100000001f64);
assert_ulps_ne!(-0.0000000100000001f64, -0.0000000010000002f64);
assert_ulps_ne!(-0.0000000100000002f64, -0.0000000010000001f64);
}
#[test]
fn test_zero() {
assert_ulps_eq!(0.0f64, 0.0f64);
assert_ulps_eq!(0.0f64, -0.0f64);
assert_ulps_eq!(-0.0f64, -0.0f64);
assert_ulps_ne!(0.000000000000001f64, 0.0f64);
assert_ulps_ne!(0.0f64, 0.000000000000001f64);
assert_ulps_ne!(-0.000000000000001f64, 0.0f64);
assert_ulps_ne!(0.0f64, -0.000000000000001f64);
}
#[test]
fn test_epsilon() {
assert_ulps_eq!(0.0f64, 1e-40f64, epsilon = 1e-40f64);
assert_ulps_eq!(1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_ulps_eq!(0.0f64, -1e-40f64, epsilon = 1e-40f64);
assert_ulps_eq!(-1e-40f64, 0.0f64, epsilon = 1e-40f64);
assert_ulps_ne!(1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_ulps_ne!(0.0f64, 1e-40f64, epsilon = 1e-41f64);
assert_ulps_ne!(-1e-40f64, 0.0f64, epsilon = 1e-41f64);
assert_ulps_ne!(0.0f64, -1e-40f64, epsilon = 1e-41f64);
}
#[test]
fn test_max() {
assert_ulps_eq!(f64::MAX, f64::MAX);
assert_ulps_ne!(f64::MAX, -f64::MAX);
assert_ulps_ne!(-f64::MAX, f64::MAX);
assert_ulps_ne!(f64::MAX, f64::MAX / 2.0);
assert_ulps_ne!(f64::MAX, -f64::MAX / 2.0);
assert_ulps_ne!(-f64::MAX, f64::MAX / 2.0);
}
#[test]
fn test_infinity() {
assert_ulps_eq!(f64::INFINITY, f64::INFINITY);
assert_ulps_eq!(f64::NEG_INFINITY, f64::NEG_INFINITY);
assert_ulps_ne!(f64::NEG_INFINITY, f64::INFINITY);
assert_ulps_eq!(f64::INFINITY, f64::MAX);
assert_ulps_eq!(f64::NEG_INFINITY, -f64::MAX);
}
#[test]
fn test_nan() {
assert_ulps_ne!(f64::NAN, f64::NAN);
assert_ulps_ne!(f64::NAN, 0.0);
assert_ulps_ne!(-0.0, f64::NAN);
assert_ulps_ne!(f64::NAN, -0.0);
assert_ulps_ne!(0.0, f64::NAN);
assert_ulps_ne!(f64::NAN, f64::INFINITY);
assert_ulps_ne!(f64::INFINITY, f64::NAN);
assert_ulps_ne!(f64::NAN, f64::NEG_INFINITY);
assert_ulps_ne!(f64::NEG_INFINITY, f64::NAN);
assert_ulps_ne!(f64::NAN, f64::MAX);
assert_ulps_ne!(f64::MAX, f64::NAN);
assert_ulps_ne!(f64::NAN, -f64::MAX);
assert_ulps_ne!(-f64::MAX, f64::NAN);
assert_ulps_ne!(f64::NAN, f64::MIN_POSITIVE);
assert_ulps_ne!(f64::MIN_POSITIVE, f64::NAN);
assert_ulps_ne!(f64::NAN, -f64::MIN_POSITIVE);
assert_ulps_ne!(-f64::MIN_POSITIVE, f64::NAN);
}
#[test]
fn test_opposite_signs() {
assert_ulps_ne!(1.000000001f64, -1.0f64);
assert_ulps_ne!(-1.0f64, 1.000000001f64);
assert_ulps_ne!(-1.000000001f64, 1.0f64);
assert_ulps_ne!(1.0f64, -1.000000001f64);
assert_ulps_eq!(10.0 * f64::MIN_POSITIVE, 10.0 * -f64::MIN_POSITIVE);
}
#[test]
fn test_close_to_zero() {
assert_ulps_eq!(f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_ulps_eq!(f64::MIN_POSITIVE, -f64::MIN_POSITIVE);
assert_ulps_eq!(-f64::MIN_POSITIVE, f64::MIN_POSITIVE);
assert_ulps_eq!(f64::MIN_POSITIVE, 0.0f64);
assert_ulps_eq!(0.0f64, f64::MIN_POSITIVE);
assert_ulps_eq!(-f64::MIN_POSITIVE, 0.0f64);
assert_ulps_eq!(0.0f64, -f64::MIN_POSITIVE);
assert_ulps_ne!(0.000000000000001f64, -f64::MIN_POSITIVE);
assert_ulps_ne!(0.000000000000001f64, f64::MIN_POSITIVE);
assert_ulps_ne!(f64::MIN_POSITIVE, 0.000000000000001f64);
assert_ulps_ne!(-f64::MIN_POSITIVE, 0.000000000000001f64);
}
}
mod test_ref {
mod test_f32 {
#[test]
fn test_basic() {
assert_ulps_eq!(&1.0f32, &1.0f32);
assert_ulps_ne!(&1.0f32, &2.0f32);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_ulps_eq!(&1.0f64, &1.0f64);
assert_ulps_ne!(&1.0f64, &2.0f64);
}
}
}
mod test_slice {
mod test_f32 {
#[test]
fn test_basic() {
assert_ulps_eq!([1.0f32, 2.0f32][..], [1.0f32, 2.0f32][..]);
assert_ulps_ne!([1.0f32, 2.0f32][..], [2.0f32, 1.0f32][..]);
}
}
mod test_f64 {
#[test]
fn test_basic() {
assert_ulps_eq!([1.0f64, 2.0f64][..], [1.0f64, 2.0f64][..]);
assert_ulps_ne!([1.0f64, 2.0f64][..], [2.0f64, 1.0f64][..]);
}
}
}
#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
pub use self::num_complex::Complex;
mod test_f32 {
use super::Complex;
#[test]
fn test_basic() {
assert_ulps_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
assert_ulps_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_ulps_eq!(Complex::new(1.0f32, 2.0f32), Complex::new(2.0f32, 1.0f32));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_ulps_ne!(Complex::new(1.0f32, 2.0f32), Complex::new(1.0f32, 2.0f32));
}
}
mod test_f64 {
use super::Complex;
#[test]
fn test_basic() {
assert_ulps_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
assert_ulps_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_eq() {
assert_ulps_eq!(Complex::new(1.0f64, 2.0f64), Complex::new(2.0f64, 1.0f64));
}
#[test]
#[should_panic]
fn test_basic_panic_ne() {
assert_ulps_ne!(Complex::new(1.0f64, 2.0f64), Complex::new(1.0f64, 2.0f64));
}
}
}