Ruby/Справочник/Precision

Материал из Викиучебника — открытых книг для открытого мира

Примесь Precision[править]

Precision - примесь для конкретных числовых классов с точностью приближения; иными словами, с определённой длиной дробной части данного числа. Примесь не может быть подмешана в классы, не унаследованные от Real (поэтому он не должен быть включен в классах вроде Complex или Matrix).


Методы класса

included

Методы объекта

prec_f, prec_i, prec

Precision::included[править]


 Precision::included(p1)

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.

Precision#prec[править]


 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 klass.induced_from doesn't return an instance of klass, it will be necessary to reimplement prec.

Precision#prec_f[править]


 num.prec_f  =>  Float

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

Precision#prec_i[править]


 num.prec_i  =>  Integer

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