るりまサーチ

最速Rubyリファレンスマニュアル検索!
24件ヒット [1-24件を表示] (0.012秒)
トップページ > クエリ:numeric[x] > クエリ:Complex[x] > 種類:クラス[x]

別のキーワード

  1. numeric step
  2. _builtin numeric
  3. numeric polar
  4. numeric modulo
  5. numeric coerce

ライブラリ

検索結果

Complex (38097.0)

複素数を扱うクラスです。

...

Complex
オブジェクトを作成するには、Kernel.#Complex
Complex
.rect、Complex.polar、Numeric#to_c、
String#to_c のいずれかを使用します。

//emlist[Complex オブジェクトの作り方][ruby]{
Complex
(1) # => (1+0i)
Complex
(2, 3) # => (2+3i)
Complex
.po...
...lar(2, 3) # => (-1.9799849932008908+0.2822400161197344i)
Complex
(0.3) # => (0.3+0i)
Complex
('0.3-0.5i') # => (0.3-0.5i)
Complex
('2/3+3/4i') # => ((2/3)+(3/4)*i)
Complex
('1@2') # => (-0.4161468365471424+0.9092974268256817i)
3.to_c # => (3+0i)
0.3.to_c # => (...
...# => ((2/3)+(3/4)*i)
'1@2'.to_c # => (-0.4161468365471424+0.9092974268256817i)
//}

Complex
オブジェクトは有理数の形式も実数の形式も扱う事ができます。

//emlist[例][ruby]{
Complex
(1, 1) / 2 # => ((1/2)+(1/2)*i)
Complex
(1, 1) / 2.0 # => (0.5+0.5i)
//}...

Numeric (6263.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...スです。Integer や Float などの数値クラス
Numeric のサブクラスとして実装されています。

演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッドは、サブクラスで...
...ラスを参照してください。


=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Numeric
Integer Fixnum Bignum Float Rational Complex
----------------------------------------------------------------------------------------...
...}

また、任意桁の切上げ、切捨て、四捨五入を行うメソッドは以下のように
定義できます。

//emlist[][ruby]{
class
Numeric
def roundup(d=0)
x = 10**d
if self > 0
self.quo(x).ceil * x
else
self.quo(x).floor * x
end
end

def rounddow...
...のクラスを参照してください。


=> ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin15]
Numeric
Integer Float Rational Complex
--------------------------------------------------------------------------------
%...