Coder Social home page Coder Social logo

big's Introduction

big

Rust Big number operation library. 一个大数运算依赖库


TODO

  1. 支持大整数位运算及四则运算。

例子

`

let mut src = utils::big::parse::ParseInt("011011101111".to_string(), 2);
let mut dst = utils::big::parse::ParseInt("01010".to_string(), 2);

//解析
//正数
src = utils::big::parse::ParseInt("011011101111".to_string(), 2);
src = utils::big::parse::ParseInt("1775".to_string(), 10);
src = utils::big::int::BigInt::NewInt(1775);
//负数
src = utils::big::parse::ParseInt("111011101111".to_string(), 2);
src = utils::big::parse::ParseInt("-1775".to_string(), 10);
src = utils::big::int::BigInt::NewInt(-1775);
println!("格式化 {}", src.Format(10));
println!("格式化 {}", src.Format(2));



src = utils::big::parse::ParseInt("0111111111".to_string(), 2);
src.Lsh(9);
println!("左移 {}", src.Format(2));


src.Rsh(1);
println!("右移 {}", src.Format(2));


src.Not();
println!("取反 {}", src.Format(2));

let mut dstBigInt = utils::big::parse::ParseInt("011".to_string(), 2);
src.Xor(&dstBigInt);
println!("异或 {}", src.Format(2));


src = utils::big::parse::ParseInt("-10".to_string(), 10);
dst = utils::big::parse::ParseInt("-11".to_string(), 10);
println!("对比 {}", src.Cmp(&dst));

src = utils::big::parse::ParseInt("-10".to_string(), 10);
dst = utils::big::parse::ParseInt("-1".to_string(), 10);
src.Add(&dst);
println!("加法 {}", src.Format(10));

src = utils::big::parse::ParseInt("18".to_string(), 10);
dst = utils::big::parse::ParseInt("10".to_string(), 10);
src.Sub(&dst);
println!("减法 {}", src.Format(10));


src = utils::big::int::BigInt::NewInt(9998);
dst = utils::big::int::BigInt::NewInt(9907);
src.Mul(&dst);
println!("乘法 {}", src.Format(10));


src = utils::big::parse::ParseInt("9997".to_string(), 10);
dst = utils::big::parse::ParseInt("10".to_string(), 10);
src.Div(&dst);
println!("除法 {}", src.Format(10));


src = utils::big::int::BigInt::NewInt(99999999999999997);
dst = utils::big::int::BigInt::NewInt(10);
src.Mod(&dst);
println!("取模 {}", src.Format(10));


src = utils::big::parse::ParseInt("-1775".to_string(), 10);
dst = utils::big::int::BigInt::NewInt(10);
src.Mod(&dst);
println!("取模 {}", src.Format(10));

`

big's People

Contributors

prestontao avatar

Watchers

 avatar  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.