Giter Site home page Giter Site logo

fixed-bigint-rs's Introduction

Fixed BigInt

crate documentation minimum rustc 1.51 build status Coverage Status

Unsigned BigInt implementation, backed by a fixed-size array.

Important: Requires at least Rust 1.51 stable, as it uses min_const_generics

FixedUInt<u8,4>,FixedUInt<u16,2> or FixedUInt<u32,1> all create a 32-bit unsigned integer, that behaves mostly the same as builtin u32. FixedUInt<u32, 64> creates a 2048-bit value, that uses native 32-bit math. If running on 8-bit CPU, FixedUInt<u8, 2048> would work the same, just very much slower.

The crate is written for no_std and no_alloc environments with option for panic-free operation, i.e. embedded MCUs. At least for now, focus is on correctness first and then generated code size, performance comes last. The aim is not to bring in 64-bit math dependencies on 32-bit CPU, to save code space.

The arithmetic operands ( +, -, .add() ) panic on overflow, just like native integer types. Panic-free alternatives like overlowing_add and wrapping_add are supported.

In addition to basic arithmetic, two main traits are implemented: num_traits::PrimInt and num_integer::Integer.

TODO list:

  • Implement experimental unchecked_math operands, unchecked_mul, unchecked_div etc.
  • Probably needs its own error structs instead of reusing core::fmt::Error and core::num::ParseIntError
  • Decimal string to/from conversion, currently only binary and hex strings are supported.
  • Comprehensive testing fixture, fully validate all ops up to 32-bit against native types
  • Some test code relies on 64-bit ToPrimitive/FromPrimitive conversions, clean this up
  • Lots of test code can be written cleaner
  • Maybe implement signed version as well.

Note: This crate is mostly written as an exercise for learning the Rust type system and understanding how well it works on microcontrollers, its fitness for any particular purpose or quality has precisely zero guarantees.

Contributing

See CONTRIBUTING.md for details.

License

Apache 2.0; see LICENSE for details.

Disclaimer

This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

fixed-bigint-rs's People

Contributors

kaidokert avatar

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.