missing-math 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ module MissingMath
2
+
3
+ def prime?
4
+ throw "Not an Integer" if !self.is_i?
5
+ begin
6
+ last = Math.sqrt(self).floor
7
+ i = 2
8
+ while i <= last
9
+ if self % i == 0
10
+ return false
11
+ end
12
+ i += 1
13
+ end
14
+ return true
15
+ rescue
16
+ false
17
+ end
18
+ end
19
+
20
+ def factorial
21
+ throw "Not an Integer" if !self.is_i?
22
+ self.downto(1).reduce(:*)
23
+ end
24
+
25
+ def factors(include_one=true)
26
+ throw "Not an Integer" if !self.is_i?
27
+ last = self
28
+ i = include_one ? 1 : 2
29
+ a = []
30
+ while i < last
31
+ if self % i == 0
32
+ last = self / i
33
+ a << i
34
+ a << last
35
+ end
36
+ i += 1
37
+ end
38
+ return a.sort
39
+ end
40
+
41
+ end
42
+
43
+
44
+ require 'missing_math/integer'
45
+ require 'missing_math/float'
46
+ require 'missing_math/fixnum'
@@ -0,0 +1,7 @@
1
+ class Fixnum
2
+
3
+ def is_i?
4
+ super
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ class Float
2
+
3
+ def is_i?
4
+ false
5
+ end
6
+
7
+ end
@@ -0,0 +1,8 @@
1
+ class Integer
2
+ include MissingMath
3
+
4
+ def is_i?
5
+ return true
6
+ end
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ module MissingMath
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: missing-math
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Clayton Liggitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A library of missing math functions.
15
+ email: mail@enorganik.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/missing_math/fixnum.rb
21
+ - lib/missing_math/float.rb
22
+ - lib/missing_math/integer.rb
23
+ - lib/missing_math/version.rb
24
+ - lib/missing_math.rb
25
+ homepage: https://github.com/arktisklada/missing-math
26
+ licenses:
27
+ - MIT
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.23
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Missing Math!
50
+ test_files: []