[][src]Crate ufo

This crate provides unsigned floats by defining two wrappers - a UF32 and UF64. The type is equivalent to storing a positive number of the underlying type (f32 or f64) and no optimisations have been carried out to use the sign bit to store another bit of the data.

Installation

To use this as a dependency, add it to your Cargo.toml file:

ufo = "0.1"

If you need serialization, enable the serde feature

ufo = { version = "0.1", features = ["serde"] }

There is also a nightly feature that takes advantage of the TryFrom/TryInto traits

Usage

use ufo::Uf32;

fn main() {
    let a = Uf32::try_new(1.0).expect("invalid number");
    let b = Uf32::try_new(2.0).expect("invalid number");
    assert_eq!(a + b, Uf32::try_new(3.0).expect("invalid number"))
}

Structs

InvalidNumberError

An error that represents either a negative or an invalid number.

Uf32

Uf32 represents an unsigned f32. You cannot create a new value directly and have to use the try_new() method or by calling try_into on a f32, where a check is made to ensure that the value is positive.

Traits

TryInto

Polyfill trait that mimics the TryInto trait on stable till it is stabilized.