Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • prec.c

Precision

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 subset of Real (so it should not be included in classes such as Complex or Matrix).

Public Class Methods

included(p1) click to toggle source

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;
{
    switch (TYPE(include)) {
      case T_CLASS:
      case T_MODULE:
       break;
      default:
       Check_Type(include, T_CLASS);
       break;
    }
    rb_define_singleton_method(include, "induced_from", prec_induced_from, 1);
    return module;
}
            

Public Instance Methods

prec(klass) => a_klass click to toggle source

Converts self into an instance of klass. By default, prec invokes

klass.induced_from(num)

and returns its value. So, if klass.induced_from doesn’t return an instance of klass, it will be necessary to reimplement prec.

 
               static VALUE
prec_prec(x, klass)
    VALUE x, klass;
{
    return rb_funcall(klass, prc_if, 1, x);
}
            
prec_f => Float click to toggle source

Returns a Float converted from num. It is equivalent to prec(Float).

 
               static VALUE
prec_prec_f(x)
    VALUE x;
{
    VALUE klass = rb_cFloat;

    return rb_funcall(x, prc_pr, 1, klass);
}
            
prec_i => Integer click to toggle source

Returns an Integer converted from num. It is equivalent to prec(Integer).

 
               static VALUE
prec_prec_i(x)
    VALUE x;
{
    VALUE klass = rb_cInteger;

    return rb_funcall(x, prc_pr, 1, klass);
}
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus