Code Monkey home page Code Monkey logo

bigfib's Introduction

Big Fibonacci

Calculates Fibonacci numbers with arbitrary precision. Fast doubling is used as Fibonacci alforithm which is explanied by Chun-Min Chang, and Karatsuba algoritm for multiplication inspired by the Vladimir Petrigo implementation for big numbers.

Arbitrary precision is achieved through a custom bigint class (only for positive numbers) with multiplication, addition and subtraction operators overloaded. Also, the std::string conversion operator is overloaded.

Build

Use the Makefile file to build the binary. There are some targets available:

  • release: The default target generates de optimized binary at bin/bigfib.
  • debug: Generates the binary for debugging with gdb.
  • clean: Removes all the compilation files.

Feel free to update the CXX, CXXFLAGS, LIBS and LDFLAGS variables if you need.

CLI usage

Usage: bin/bigfib [OPTIONS]... N...
Calculate the Fibonacci number of the given N terms.

  -q, --quiet          don't print the Fibonacci number
  -s, --simple         don't print summary.
  -h, --help           display this help and exit
  -v, --version        output version information and exit

Tests outputs

Some outputs using the quiet options to avoid the Fibonacci number printing. All tests have been executed on a AMD Ryzen™ 7 5700U:

Term: 512
Chunks: 12
Digits: 107
Calculating time:       0.013195 ms
Casting time:           0.015670 ms
Total time:             0.028865 ms

Term: 4784969
Chunks: 111112
Digits: 1000000
Calculating time:     220.479498 ms
Casting time:           3.840622 ms
Total time:           224.320120 ms

Term: 100000000
Chunks: 2322085
Digits: 20898764
Calculating time:   52460.604902 ms
Casting time:          76.934597 ms
Total time:         52537.539499 ms

License

Licensed under the MIT license.

Share and enjoy!

bigfib's People

Watchers

 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.