### 25 releases (9 stable)

1.2.4 | Feb 14, 2023 |
---|---|

1.2.2 | Dec 27, 2022 |

1.1.2 | Oct 29, 2022 |

0.11.3 | Sep 9, 2022 |

0.7.0 | Feb 5, 2021 |

#**176** in Math

**189** downloads per month

Used in midi_fundsp

**MIT/Apache**

58KB

961 lines

# Bare Metal Modulo

and `ModNum`

are highly ergonomic modular arithmetic structs intended
for `ModNumC`

use.`no_std`

objects represent a value modulo m. The value and modulo can be of any
primitive integer type. Arithmetic operators include `ModNum`

, `+`

(both unary and binary),
`-`

, `*`

, `/`

, and `pow``(``)`

. Additional capabilities include computing multiplicative inverses
and solving modular equations.`==`

objects likewise represent a value modulo `ModNumC`

, where `M`

is a generic constant of the
`M`

type. Arithmetic operators include `usize`

, `+`

(both unary and binary), `-`

, and `*`

.`==`

This library was originally developed to facilitate bidirectional navigation through fixed-size
arrays at arbitrary starting points. This is facilitated by a double-ended iterator that
traverses the entire ring starting at any desired value. The iterator supports both

and
`ModNum``ModNumC .`

Modular numbers represent the remainder of an integer when divided by the modulo. If we also store the quotient in addition to the remainder, we have a count of the number of times a value had to "wrap around" during the calculation.

For example, if we start with **8 (mod 17)** and add **42**, the result is **16 (mod 17)** with
a wraparound of **2**.

and `WrapCountNum`

objects store this wraparound value
and make it available.`WrapCountNumC`

Furthermore, it is sometimes useful to be able to move back and forth in a range that is offset from zero. To that end,

and `OffsetNum`

are provided.`OffsetNumC`

Note that

, `ModNum`

, `ModNumC`

, `WrapCountNum`

, `WrapCountNumC`

, and `OffsetNum`

are not designed to work with
arbitrary-length integers, as they require their integer type to implement the `OffsetNumC`

trait.`Copy`

# Notes

- See CHANGELOG.md for updates.

#### Dependencies

~465KB