assert-within

Crates.ioassert-within
lib.rsassert-within
version0.1.4
created_at2025-04-17 01:00:17.014554+00
updated_at2025-12-19 00:17:06.880305+00
descriptionMacro for testing that (generic) floating point numbers are within some tolerance
homepage
repositoryhttps://github.com/cbeck88/assert-within
max_upload_size
id1637107
size9,357
Chris Beck (cbeck88)

documentation

README

assert-within

Crates.io Crates.io License License

API Docs

A macro assert_within! for tests involving floating point numbers.

assert_within!(+0.001, val, target, "Value was not within additive 0.001: {more} {context}");
assert_within!(~0.05, val, target, "Value was not within 5% of target: {additional} {information:?}");

Features

  • Pass arguments by reference or value
  • Sigils (+, ~) indicate additive or relative error
  • Traps NaN in any of the arguments
  • Errors cause both the stringified expressions and their values to be displayed
  • Arbitrary additional format args
  • Generic over num_traits::FloatCore
  • no_std compatible

License

MIT or Apache 2.0 at your option.

Commit count: 1

cargo fmt