Giter Site home page Giter Site logo

bounds's Introduction

Bounds

Build Status crates.io

documentation

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 (overflow / underflow), 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.

Macro

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

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

Example

use bounds::*;

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.