fibonacci 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,6 +80,26 @@ rb_matrix_mul(VALUE ary1, VALUE ary2)
80
80
  return tmp_ary;
81
81
  }
82
82
 
83
+ /* call-seq:
84
+ * fib.matrix(n)
85
+ *
86
+ * Returns a 2x2 matrix(2-dimensional array).
87
+ *
88
+ * fib.matrix(10)
89
+ * #=> [[89, 55], [55, 34]]
90
+ *
91
+ * fib.matrix(100)
92
+ * #=> [[573147844013817084101, 354224848179261915075], [354224848179261915075,218922995834555169026]]
93
+ *
94
+ * arr = fib.matrix(15)
95
+ * #=> [[987, 610], [610, 377]]
96
+ *
97
+ * arr[0][1] or arr[1][0] is the value of nth term
98
+ *
99
+ * Refer to http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form
100
+ *
101
+ */
102
+
83
103
  static VALUE
84
104
  rb_matrix_form(VALUE self, VALUE n)
85
105
  {
@@ -144,6 +164,25 @@ rb_matrix_form(VALUE self, VALUE n)
144
164
  return res_ary;
145
165
  }
146
166
 
167
+ /* call-seq:
168
+ * fib[n]
169
+ *
170
+ * Returns a Fixnum or Bignum.
171
+ *
172
+ * fib[100]
173
+ * #=> 354224848179261915075
174
+ *
175
+ * fib[10]
176
+ * #=> 55
177
+ *
178
+ * fib[200]
179
+ * #=> 280571172992510140037611932413038677189525
180
+ *
181
+ * The value of nth term is calculated iteratively.
182
+ *
183
+ * Refer to http://en.wikipedia.org/wiki/Fibonacci_number#First_identity
184
+ */
185
+
147
186
  static VALUE
148
187
  rb_iterative_val(VALUE self, VALUE n)
149
188
  {
@@ -187,6 +226,26 @@ rb_iterative_val(VALUE self, VALUE n)
187
226
  return fib_n;
188
227
  }
189
228
 
229
+ /* call-seq:
230
+ * fib.terms(n)
231
+ *
232
+ * Returns a array with the first n terms of the series
233
+ *
234
+ * fib.terms(5)
235
+ * #=> [0, 1, 1, 2, 3]
236
+ *
237
+ * fib.terms(10)
238
+ * #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
239
+ *
240
+ * fib.terms(15)
241
+ * #=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
242
+ *
243
+ * fib.terms(0)
244
+ * #=> []
245
+ *
246
+ * Refer to http://en.wikipedia.org/wiki/Fibonacci_number#First_identity
247
+ */
248
+
190
249
  static VALUE
191
250
  terms(VALUE self, VALUE n)
192
251
  {
@@ -223,6 +282,19 @@ terms(VALUE self, VALUE n)
223
282
  return ary;
224
283
  }
225
284
 
285
+ /* call-seq:
286
+ * fib.print(n)
287
+ *
288
+ * Prints the first n terms of the series.
289
+ *
290
+ * fib.print(1)
291
+ * #=> 0
292
+ *
293
+ * fib.print(2)
294
+ * #=> 0
295
+ * 1
296
+ */
297
+
226
298
  static VALUE
227
299
  print(VALUE self, VALUE n)
228
300
  {
@@ -230,7 +302,6 @@ print(VALUE self, VALUE n)
230
302
  VALUE fib_n_1 = ONE;
231
303
  VALUE fib_n_2 = ZERO;
232
304
  VALUE fib_n = ZERO;
233
-
234
305
  if(TYPE(n) != T_FIXNUM)
235
306
  {
236
307
  rb_raise(rb_eArgError, "Invalid argument for type Fixnum");
@@ -265,6 +336,20 @@ index_of(VALUE self, VALUE val)
265
336
  return Qnil;
266
337
  }
267
338
 
339
+ /* call-seq:
340
+ * fib.num_digits(n)
341
+ *
342
+ * Returns the number of digits in the nth term of the series
343
+ *
344
+ * fib.num_digits(10)
345
+ * #=> 2
346
+ *
347
+ * fib.num_digits(100)
348
+ * #=> 21
349
+ *
350
+ * Refer to http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding
351
+ */
352
+
268
353
  static VALUE
269
354
  num_digits(VALUE self, VALUE n)
270
355
  {
@@ -1 +1 @@
1
- VERSION = "0.1.4"
1
+ VERSION = "0.1.5"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fibonacci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-13 00:00:00.000000000 Z
12
+ date: 2011-12-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A Ruby gem for exploring Fibonacci series
15
15
  email:
@@ -48,3 +48,4 @@ signing_key:
48
48
  specification_version: 3
49
49
  summary: Fibonacci
50
50
  test_files: []
51
+ has_rdoc: