GithubHelp home page GithubHelp logo

solnone / fibonacci Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 50 KB

Fibonacci number

License: MIT License

Makefile 2.94% M4 1.39% Shell 26.36% Gnuplot 1.69% C 53.32% C++ 1.14% Java 2.76% Julia 3.64% JavaScript 2.47% Perl 1.99% Python 2.30%

fibonacci's Introduction

fibonacci

Fibonacci number

fibonacci(0) = 0,
fibonacci(1) = 1,
and fibonacci(n) = fibonacci(n-1) + fibonacci(n-2),  per n > 1

Build & Run Fibonacci 64, 128, 256 bits without other libraries

$ cc -Wall -Wextra -g -O3 -march=native -o src/fib src/fib.c src/fibonacci.c src/fibonacci_io.c
$ echo 180 | src/fib
$ src/fib -s 91 -e 93 -b 64
$ src/fib -s 181 -e 186 -b 128
$ src/fib -s 367 -e 370 -b 256

Required libraries

Ubuntu | Debian

$ sudo apt-get install git build-essential
$ sudo apt-get install pkg-config gnuplot
$ sudo apt-get install libgmp-dev libglib2.0-dev
$ sudo apt-get install aspell clang-format cppcheck
$ sudo apt-get install autotools-dev autoconf automake libtool

MacOS with Homebrew

$ xcode-select --install
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ brew install pkg-config gnuplot
$ brew install gmp glib
$ brew install aspell clang-format cppcheck
$ brew install autoconf automake libtool

autoconf

$ autoreconf -ivf

Build & Run Fibonacci with GMP library

$ cc -Wall -Wextra -g -O3 -march=native -o src/fib_doubling_mixing src/fib_doubling_mixing.c src/fibonacci.c src/fibonacci_gmp.c src/fibonacci_io.c -lgmp
$ echo 2000 | src/fib_doubling_mixing

Configure and Make

$ CPPFLAGS="-Wall -Wextra -g -O3 -march=native" ./configure && make

Run

$ echo 1000 | src/fib_doubling_gmp
$ echo 1000 | src/fib_iterative_gmp
$ src/main 183 187

Tests

$ make check

Scripts

$ # python
$ echo 99 | tests/fibonacci.py
$ # perl
$ echo 99 | tests/fibonacci.pl
$ # javascript
$ echo 99 | tests/fibonacci.js
$ # julia
$ echo 99 | tests/fibonacci.jl

Java

$ javac tests/Fibonacci.java
$ echo 99 | java -cp tests Fibonacci

Using AddressSanitizer

$ CC=clang CXX=clang++ CFLAGS="-Wall -Wextra -fsanitize=address -O1 -fno-omit-frame-pointer -g" CXXFLAGS=$CFLAGS ./configure

Clang-Format

$ clang-format -style=file -i src/*.[ch] src/*.cpp

Cppcheck

$ cppcheck --enable=all --inline-suppr --inconclusive --suppress=missingIncludeSystem --verbose src/*.[ch] src/*.cpp

Valgrind

$ valgrind --tool=memcheck --leak-check=full --error-exitcode=1 -s src/main 99

Install Git Hooks

$ scripts/install-git-hooks

Plot

$ make plot

References

2020 年春季 Linux 核心設計課程作業 —— fibdrv - HackMD

Efficient implementations of Fibonacci function with interesting results - Domains / Numerics - JuliaLang

Fast Fibonacci algorithms - Project Nayuki

The Fastest Way to Compute the Nth Fibonacci Number: The Doubling Method - Linus's Blog

AddressSanitizer

int128.h - chenshuo/recipes - GitHub

c - how to print __uint128_t number using gcc? - Stack Overflow

Libraries

The GNU Multiple Precision Arithmetic Library (gmp)

GLib

fibonacci's People

Contributors

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