summaryrefslogtreecommitdiff
path: root/prec.c
diff options
context:
space:
mode:
authordave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-30 16:38:32 +0000
committerdave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-30 16:38:32 +0000
commit349f4e7db766e618d606768d5ead8cbc9f4ef74f (patch)
tree37c299cb289d0563962400250d7f7b9a30a0986c /prec.c
parent5e6d81e717879424edc46cda993799d8de7aa635 (diff)
Add RDoc for kernel functions, and tidy up
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'prec.c')
-rw-r--r--prec.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/prec.c b/prec.c
index 8f28648..b7a6d5b 100644
--- a/prec.c
+++ b/prec.c
@@ -16,6 +16,21 @@ VALUE rb_mPrecision;
static ID prc_pr, prc_if;
+
+/*
+ * call-seq:
+ * num.prec(klass) => a_klass
+ *
+ * Converts _self_ into an instance of _klass_. By default,
+ * +prec+ invokes
+ *
+ * klass.induced_from(num)
+ *
+ * and returns its value. So, if <code>klass.induced_from</code>
+ * doesn't return an instance of _klass_, it will be necessary
+ * to reimplement +prec+.
+ */
+
static VALUE
prec_prec(x, klass)
VALUE x, klass;
@@ -23,6 +38,14 @@ prec_prec(x, klass)
return rb_funcall(klass, prc_if, 1, x);
}
+/*
+ * call-seq:
+ * num.prec_i => Integer
+ *
+ * Returns an +Integer+ converted from _num_. It is equivalent
+ * to <code>prec(Integer)</code>.
+ */
+
static VALUE
prec_prec_i(x)
VALUE x;
@@ -32,6 +55,14 @@ prec_prec_i(x)
return rb_funcall(x, prc_pr, 1, klass);
}
+/*
+ * call-seq:
+ * num.prec_f => Integer
+ *
+ * Returns an +Float+ converted from _num_. It is equivalent
+ * to <code>prec(Float)</code>.
+ */
+
static VALUE
prec_prec_f(x)
VALUE x;
@@ -41,6 +72,19 @@ prec_prec_f(x)
return rb_funcall(x, prc_pr, 1, klass);
}
+/*
+ * call-seq:
+ * Mod.induced_from(number) => a_mod
+ *
+ * Creates an instance of mod from. This method is overridden
+ * by concrete +Numeric+ classes, so that (for example)
+ *
+ * Fixnum.induced_from(9.9) #=> 9
+ *
+ * Note that a use of +prec+ in a redefinition may cause
+ * an infinite loop.
+ */
+
static VALUE
prec_induced_from(module, x)
VALUE module, x;
@@ -50,6 +94,15 @@ prec_induced_from(module, x)
return Qnil; /* not reached */
}
+/*
+ * call_seq:
+ * included
+ *
+ * When the +Precision+ module is mixed-in to a class, this +included+
+ * method is used to add our default +induced_from+ implementation
+ * to the host class.
+ */
+
static VALUE
prec_included(module, include)
VALUE module, include;
@@ -66,6 +119,13 @@ prec_included(module, include)
return module;
}
+/*
+ * Precision is a mixin for concrete numeric classes with
+ * precision. Here, `precision' means the fineness of approximation
+ * of a real number, so, this module should not be included into
+ * anything which is not a ubset of Real (so it should not be
+ * included in classes such as +Complex+ or +Matrix+).
+*/
void
Init_Precision()