Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Work in progress...

  • Loading branch information...
commit bc225337536cec24e1e45d9ea5831e077d3f80cb 1 parent e48c8be
authored December 11, 2011 alevchuk committed December 11, 2011

Showing 1 changed file with 21 additions and 0 deletions. Show diff stats Hide diff stats

  1. 21  numeric.c
21  numeric.c
@@ -414,6 +414,26 @@ num_remainder(VALUE x, VALUE y)
414 414
 
415 415
 /*
416 416
  *  call-seq:
  417
+ *     float.signif(numeric)  ->  float
  418
+ *
  419
+ *  Returns a float rounded to the nearest <code>numeric</code>
  420
+ *  siginficant figures.
  421
+ *
  422
+ *     (11.11).signif(1)   # => 10
  423
+ *     (22.22).signif(2)   # => 22
  424
+ *     (3.333).signif(2)   # => 3.3
  425
+ *     (4.4).signif(3)     # => 4.4
  426
+ *     (5.55).signif(2)    # => 5.6
  427
+ */
  428
+
  429
+static VALUE
  430
+flo_signif(VALUE x, VALUE y)
  431
+{
  432
+    return 1; //rb_funcall('"Float(%#{', x, '/', 1, y);
  433
+}
  434
+
  435
+/*
  436
+ *  call-seq:
417 437
  *     num.divmod(numeric)  ->  array
418 438
  *
419 439
  *  Returns an array containing the quotient and modulus obtained by
@@ -3694,6 +3714,7 @@ Init_Numeric(void)
3694 3714
     rb_define_method(rb_cFloat, "ceil", flo_ceil, 0);
3695 3715
     rb_define_method(rb_cFloat, "round", flo_round, -1);
3696 3716
     rb_define_method(rb_cFloat, "truncate", flo_truncate, 0);
  3717
+    rb_define_method(rb_cFloat, "signif", flo_signif, 1);
3697 3718
 
3698 3719
     rb_define_method(rb_cFloat, "nan?",      flo_is_nan_p, 0);
3699 3720
     rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);

0 notes on commit bc22533

Please sign in to comment.
Something went wrong with that request. Please try again.