8件ヒット
[1-8件を表示]
(0.023秒)
検索結果
先頭5件
-
Rational
# -(other) -> Rational | Float (63979.0) -
差を計算します。
...差を計算します。
@param other 自身から引く数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r - 1 # => (-1/4)
r - 0.5 # => 0.25
//}... -
Rational
# **(other) -> Rational | Float (9961.0) -
冪(べき)乗を計算します。
...す。other が有理数であっても、計算結果が無理数だった場合は Float
を返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r ** Rational(2, 1) # => (9/16)
r ** 2 # => (9/16)
r ** 2.0 # => 0.5625
r ** Rational(1, 2) # => 0.866025403784439
//}... -
Rational
# / (other) -> Rational | Float (9946.0) -
商を計算します。
...定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionErr... -
Rational
# quo(other) -> Rational | Float (9946.0) -
商を計算します。
...定した場合は、計算結果を Float で返します。
//emlist[例][ruby]{
r = Rational(3, 4)
r / 2 # => (3/8)
r / 2.0 # => 0.375
r / 0.5 # => 1.5
r / Rational(1, 2) # => (3/2)
r / 0 # => ZeroDivisionError
//}
@raise ZeroDivisionErr... -
Rational
# *(other) -> Rational | Float (9943.0) -
積を計算します。
...。
@param other 自身に掛ける数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r * 2 # => (3/2)
r * 4 # => (3/1)
r * 0.5 # => 0.375
r * Rational(1, 2) # => (3/8)
//}... -
Rational
# +(other) -> Rational | Float (9943.0) -
和を計算します。
...和を計算します。
@param other 自身に足す数
other に Float を指定した場合は、計算結果を Float で返しま
す。
//emlist[例][ruby]{
r = Rational(3, 4)
r + Rational(1, 2) # => (5/4)
r + 1 # => (7/4)
r + 0.5 # => 1.25
//}... -
Rational
# to _ f -> Float (9727.0) -
自身の値を最も良く表現する Float に変換します。
...{
Rational(2).to_f # => 2.0
Rational(9, 4).to_f # => 2.25
Rational(-3, 4).to_f # => -0.75
Rational(20, 3).to_f # => 6.666666666666667
Rational(1, 10**1000).to_f # => 0.0
Rational(-1, 10**1000).to_f # => -0.0
Rational(10**1000).to_f # => Infinity
Rational(... -
Rational
# fdiv(other) -> Float (9655.0) -
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
//}...