#floating-point #bounds #zero #digital-signature


A library to interact with bounded and unbounded ranges

7 releases (breaking)

Uses old Rust 2015

0.6.2 Nov 10, 2019
0.5.0 Jan 27, 2018
0.4.0 Jan 27, 2018
0.3.0 Jan 27, 2018
0.1.0 Nov 11, 2017

#1299 in Cryptography

28 downloads per month


966 lines


Build Status crates.io


A library to interact with bounded and unbounded ranges Bounds contains a lower/upper bound which are one of [unbounded, inclusive, exclusive]. It also supports zero-sized bounds (an exact value).

You can use the four basic arithmetic operations on these ranges. (add, subtract, multiply, divide)

Implementation Details

This library adheres to "real" math, and does not respect integer math, or floating point precision issues. It was designed to be used with BigRational, but is generic so it can be used with others. If this is used with types that can overflow, round, accumulate errors, etc. no guarantees are made.

The lower bound MUST always be lower than the upper bound. There are occasional internal checks when running in debug mode, but it's up to the caller to ensure all bounds are valid when they are created.

This library will never cause a divide by 0 (division returns a None in this case), and will not panic if the input is valid and the generic type used also doesn't panic.


Rust's built in bounds don't allow the lower bound to be exclusive, so a macro is provided for easier use. The prefix ~ is used to make a bound exclusive. It is inclusive by default

bound!(,); // unbounded
bound!(~0, 3); // > 0 and <= 3
bound!(3,); // >= 3
bound!(-3); // exactly -3


use bounds::*;

assert!(bounds!(2, 4).intersects(&bounds!(1, 3)));
    bounds!(6) / bounds!(2,),