christoffetzer / abs

Simple abs function to demonstrate integer overflows and how to test for integer overflows.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

abs

This crate contains three incorrect implementations of the 'abs' function. I use these variants to introduce unit and random testing. I chose 'abs' since it looks so trival but it contains an integer overflow.

This crate also contains two (hopefully) correct implementations of 'abs': abs and sat_abs. They should demonstrate ways on how one could address the integer overflow in the 'abs' function.

Installation

To add sort to your crate, just add the following dependency.

[dependencies.abs]
git = "https://github.com/christoffetzer/abs"

The abs crate depends on two external crates:

Test

Test the code by pulling it with cargo or git and execute:

cargo test

Documentation

Build the documentation by running

cargo doc

About

Simple abs function to demonstrate integer overflows and how to test for integer overflows.


Languages

Language:Rust 100.0%