### 8 stable releases

1.6.0 | May 10, 2024 |
---|---|

1.5.0 | Apr 13, 2023 |

1.4.0 | Feb 4, 2023 |

1.3.0 | Apr 18, 2020 |

1.1.0 | Oct 10, 2017 |

#**207** in Math

**BSD-2-Clause**

31KB

244 lines

# Infinitable (Rust)

Infinitable is a simple library for introducing the notion of "infinity" and "negative infinity" to numeric types, such as integers, that do not have infinite values.

A representation of infinity is useful for graph algorithms such as Dijkstra's algorithm, as well as for representing a graph with an adjacency matrix.

## Usage

Simply install the

crate, available on Crates.io.`infinitable`

`use` `infinitable``::`Infinitable`;`
`fn` `main``(``)`` ``{`
`let` finite `=` `Infinitable``::`Finite`(``5``)``;`
`let` infinity `=` `Infinitable``::`Infinity`;`
`let` negative_infinity `=` `Infinitable``::`NegativeInfinity`;`
`assert!``(`finite `<` infinity`)``;`
`assert!``(`finite `>` negative_infinity`)``;`
`}`

## Tests

Tests are in the

directory. Simply run `tests`

.`cargo`` test`

## Note About Floating-Point Numbers

The infinite values provided by Infinitable are different from the existing infinite values in floating-point numeric types. Therefore, simply using

or `Finite`

to convert from a floating-point value to an `Infinitable ::`from

`Infinitable`

may lead to unintuitive results:`use` `infinitable``::`Infinitable`;`
`fn` `main``(``)`` ``{`
`let` infinitable_infinity `=` `Infinitable``::`Infinity`;`
`let` fp_infinity `=` `Infinitable``::`Finite`(``f64``::``INFINITY``)``;`
`assert!``(`infinitable_infinity `>` fp_infinity`)``;`
`}`

The library provides the

and `from_f32`

functions to convert from floating-point values while taking into account infinite values and NaN:`from_f64`

`use` `infinitable``::`Infinitable`;`
`fn` `main``(``)`` ``{`
`let` infinitable_infinity `=` `Infinitable``::`Infinity`;`
`let` fp_infinity `=` `infinitable``::`from_f64`(``f64``::``INFINITY``)``.``unwrap``(``)``;`
`assert!``(`infinitable_infinity `==` fp_infinity`)``;`
`}`

## License

Infinitable is available under the 2-clause BSD license. Refer to

for details.`LICENSE``.`txt

#### Dependencies

~155KB