Project

factorials

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Factorials as C extension.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

 Project Readme

Factorials

Gem Version

Ruby factorials as C extension.

Installation

Add this line to your application's Gemfile:

gem 'factorials'

And then execute:

$ bundle

Or install it yourself as:

$ gem install factorials

Usage

Factorial

10.factorial
# => 3628800

Double Factorial

10.double_factorial
# => 3840

Super Factorial

5.superfactorial
# => 34560

Benchmark

Conditions:

Benchmark.bmbm(7) do |x|
  int = 100_000

  x.report('Factorial (Ruby)') do
    (1..int).inject(:*)
  end

  x.report('Factorial (C)') do
    int.factorial
  end
end

Results:

Rehearsal ----------------------------------------------------
Factorial (Ruby)   4.710000   2.320000   7.030000 (  7.495018)
Factorial (C)      0.000000   0.000000   0.000000 (  0.000156)
------------------------------------------- total: 7.030000sec

                       user     system      total        real
Factorial (Ruby)   4.720000   2.400000   7.120000 (  7.787638)
Factorial (C)      0.000000   0.000000   0.000000 (  0.000131)

TODO

  • Support very long long long integers.

Contributing

  1. Fork it (https://github.com/droptheplot/factorials/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.