333件ヒット
[201-300件を表示]
(0.152秒)
別のキーワード
ライブラリ
- ビルトイン (309)
-
bigdecimal
/ util (12) -
json
/ add / rational (12)
キーワード
- * (12)
- ** (12)
- + (12)
- - (12)
- -@ (9)
-
/ (12) - <=> (12)
- == (12)
- abs (9)
- ceil (12)
- coerce (12)
- denominator (12)
- fdiv (12)
- floor (12)
- inspect (12)
- magnitude (9)
- negative? (9)
- numerator (12)
- positive? (9)
- quo (12)
- rationalize (12)
- round (12)
-
to
_ d (12) -
to
_ f (12) -
to
_ i (12) -
to
_ json (12) -
to
_ r (12) -
to
_ s (12) - truncate (12)
検索結果
先頭5件
-
Rational
# to _ i -> Integer (3114.0) -
小数点以下を切り捨てて値を整数に変換します。
...ます。
@param precision 計算結果の精度
@raise TypeError precision に整数以外のものを指定すると発生します。
//emlist[例][ruby]{
Rational(2, 3).to_i # => 0
Rational(3).to_i # => 3
Rational(300.6).to_i # => 300
Rational(98, 71).to_i # => 1
Rational(-31, 2).to_i......}
precision を指定した場合は指定した桁数で切り捨てた整数か
Rational を返します。
//emlist[例][ruby]{
Rational('-123.456').truncate(+1) # => (-617/5)
Rational('-123.456').truncate(+1).to_f # => -123.4
Rational('-123.456').truncate(0) # => -123
Rational('-......123.456').truncate(-1) # => -120
//}
@see Rational#ceil, Rational#floor... -
Rational
# <=>(other) -> -1 | 0 | 1 | nil (3108.0) -
self と other を比較して、self が大きい時に 1、等しい時に 0、小さい時に -1 を返します。比較できない場合はnilを返します。
...ther を比較して、self が大きい時に 1、等しい時に 0、小さい時に
-1 を返します。比較できない場合はnilを返します。
@param other 自身と比較する数値
@return -1 か 0 か 1 か nil を返します。
//emlist[例][ruby]{
Rational(2, 3) <=> Rat......ional(2, 3) # => 0
Rational(5) <=> 5 # => 0
Rational(2, 3) <=> Rational(1,3) # => 1
Rational(1, 3) <=> 1 # => -1
Rational(1, 3) <=> 0.3 # => 1
Rational(1, 3) <=> nil # => nil
//}... -
Rational
# ==(other) -> bool (3108.0) -
数値として等しいか判定します。
...@param other 自身と比較する数値
@return self と other が等しい場合 true を返します。
そうでなければ false を返します。
//emlist[例][ruby]{
Rational(2, 3) == Rational(2, 3) # => true
Rational(5) == 5 # => true
Rational(0)......== 0.0 # => true
Rational('1/3') == 0.33 # => false
Rational('1/2') == '1/2' # => false
//}... -
Rational
# abs -> Rational (3108.0) -
自身の絶対値を返します。
...自身の絶対値を返します。
//emlist[例][ruby]{
Rational(1, 2).abs # => (1/2)
Rational(-1, 2).abs # => (1/2)
//}... -
Rational
# fdiv(other) -> Float (3108.0) -
self を other で割った商を Float で返します。 other に虚数を指定することは出来ません。
...self を other で割った商を Float で返します。
other に虚数を指定することは出来ません。
@param other 自身を割る数
//emlist[例][ruby]{
Rational(2, 3).fdiv(1) # => 0.6666666666666666
Rational(2, 3).fdiv(0.5) # => 1.3333333333333333
Rational(2).fdiv(3) # =>......0.6666666666666666
Rational(1).fdiv(Complex(1, 0)) # => 1.0
Rational(1).fdiv(Complex(0, 1)) # => RangeError
//}... -
Rational
# inspect -> String (3108.0) -
自身を人間が読みやすい形の文字列表現にして返します。
...に10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
//emlist[例][ruby]{
Rational(5, 8).inspect # => "(5/8)"
Rational(2).inspect # => "(2/1)"
Rational(-8, 6).inspect # => "(-4/3)"
Rational(0.5).inspect # => "(1/2)"
//}
@see Rational#to_s... -
Rational
# magnitude -> Rational (3108.0) -
自身の絶対値を返します。
...自身の絶対値を返します。
//emlist[例][ruby]{
Rational(1, 2).abs # => (1/2)
Rational(-1, 2).abs # => (1/2)
//}... -
Rational
# to _ json(*args) -> String (3108.0) -
自身を JSON 形式の文字列に変換して返します。
...から JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 使用しません。
//emlist[例][ruby]{
require 'json/add/rational'
Rational(1, 3).to_json # => "{\"json_class\":\"Rational\",\"n\":1,\"d\":3}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_......:Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json
に渡されます。
//emlist[例][ruby]{
require 'json/add/rational'
Rational(1, 3).to_json # => "{\"json_class\":\"Rational\",\......"n\":1,\"d\":3}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Rational
# to _ s -> String (3108.0) -
自身を人間が読みやすい形の文字列表現にして返します。
..."-17/7" のように10進数の表記を返します。
@return 有理数の表記にした文字列を返します。
//emlist[例][ruby]{
Rational(3, 4).to_s # => "3/4"
Rational(8).to_s # => "8/1"
Rational(-8, 6).to_s # => "-4/3"
Rational(0.5).to_s # => "1/2"
//}
@see Rational#inspect... -
Rational
# negative? -> bool (3008.0) -
self が 0 未満の場合に true を返します。そうでない場合に false を返します。
...self が 0 未満の場合に true を返します。そうでない場合に false を返します。
//emlist[例][ruby]{
Rational(1, 2).negative? # => false
Rational(-1, 2).negative? # => true
//}
@see Rational#positive?...