22件ヒット
[1-22件を表示]
(0.213秒)
検索結果
-
Numeric (44316.0)
-
数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。
...を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。
演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは......- - - -
times | - o - - - - -
to_c | o - - - - - o
to_f | - - o......//emlist[例][ruby]{
if n > 0 then
n.ceil
else
n.floor
end
//}
また、任意桁の切上げ、切捨て、四捨五入を行うメソッドは以下のように
定義できます。
//emlist[][ruby]{
class Numeric
def roundup(d=0)
x = 10**d
if self > 0
self.quo(x).ceil * x......o - - -
to_c | o - - - o
to_f | - o o o o
Numeric Integer Float Rational Complex
--------------------... -
Numeric
# to _ c -> Complex (42147.0) -
自身を複素数 (Complex) に変換します。Complex(self, 0) を返します。
...を複素数 (Complex) に変換します。Complex(self, 0) を返します。
//emlist[例][ruby]{
1.to_c # => (1+0i)
-1.to_c # => (-1+0i)
1.0.to_c # => (1.0+0i)
Rational(1, 2).to_c # => ((1/2)+0i)
//}
Numeric のサブクラスは、このメソッドを適...