ライブラリ
- ビルトイン (62)
-
bigdecimal
/ math (11) - cmath (18)
- mathn (8)
クラス
- Integer (7)
検索結果
先頭5件
-
Math
. # sqrt(x) -> Float (39155.0) -
x の非負の平方根(principal square root)を返します。
...に発生します。
@raise Math::DomainError x に範囲外の実数を指定した場合に発生します。
@raise RangeError xに実数以外の数値を指定した場合に発生します。
//emlist[例][ruby]{
0.upto(10) {|x|
p [x, Math.sqrt(x), Math.sqrt(x)**2]
}
# => [0, 0.0, 0.0]
#......1.0, 1.0]
# [2, 1.4142135623731, 2.0]
# [3, 1.73205080756888, 3.0]
# [4, 2.0, 4.0]
# [5, 2.23606797749979, 5.0]
# [6, 2.44948974278318, 6.0]
# [7, 2.64575131106459, 7.0]
# [8, 2.82842712474619, 8.0]
# [9, 3.0, 9.0]
# [10, 3.16227766016838, 10.0]
//}
@see Integer.sqrt, Math.#cbrt... -
Math
. # sqrt(a) -> Numeric (39107.0) -
@todo
...@todo
a の正の平方根を返します。
a が Complex の時は、Complex を返します。
a が負の時は、a を正にして、その平方根を Complex の虚数部に入れて返します。
それ以外は、Math.rsqrt の結果を返します。... -
Math
. # rsqrt(a) -> Numeric (27100.0) -
@todo
@todo
複素数を考慮しないので、負の数や Complex をあたえないでください。
a が Float の時は、Float を返します。
それ以外の時、平方根が有理数であれば、Rational または Integer を返します。
無理数であれば、Float を返します。 -
CMath
. # sqrt(z) -> Float | Complex (21119.0) -
z の平方根を返します。
...z の平方根を返します。
@param z 数値
@raise TypeError z に数値以外を指定した場合に発生します。
//emlist[例][ruby]{
require "cmath"
CMath.sqrt(-1) # => (0+1.0i)
CMath.sqrt(1)# => 1.0
CMath.sqrt(Complex(0, 8))# => (2.0+2.0i)
//}... -
BigMath
. # sqrt(x , prec) -> BigDecimal (21113.0) -
x の平方根を prec で指定した精度で計算します。
...Error x に 0 以下、もしくは NaN が指定された場合に発生します。
@raise ArgumentError prec に 0 未満が指定された場合に発生します。
//emlist[][ruby]{
require "bigdecimal/math"
puts BigMath::sqrt(BigDecimal('2'), 10) #=> 0.1414213562373095048666666667e1
//}... -
Math
. # cbrt(x) -> Float (21024.0) -
x の立方根(cubic root)を返します。
...す。
@raise RangeError xに実数以外の数値を指定した場合に発生します。
//emlist[例][ruby]{
-9.upto(9) {|x|
p [x, Math.cbrt(x), Math.cbrt(x)**3]
}
# => [-9, -2.0800838230519, -9.0]
# [-8, -2.0, -8.0]
# [-7, -1.91293118277239, -7.0]
# [-6, -1.81712059283214, -6.0]
#.......0, -1.0]
# [0, 0.0, 0.0]
# [1, 1.0, 1.0]
# [2, 1.25992104989487, 2.0]
# [3, 1.44224957030741, 3.0]
# [4, 1.5874010519682, 4.0]
# [5, 1.7099759466767, 5.0]
# [6, 1.81712059283214, 6.0]
# [7, 1.91293118277239, 7.0]
# [8, 2.0, 8.0]
# [9, 2.0800838230519, 9.0]
//}
@see Math.#sqrt... -
Math
. # hypot(x , y) -> Float (21022.0) -
sqrt(x*x + y*y) を返します。
...
sqrt(x*x + y*y) を返します。
この値は x, y を直交する 2 辺とする直角三角形の斜辺(hypotenuse)の長さです。
@param x 実数
@param y 実数
@raise TypeError 引数のどちらかに数値以外を指定した場合に発生します。
@raise RangeError 引数......のどちらかに実数以外の数値を指定した場合に発生します。
//emlist[例][ruby]{
Math.hypot(3, 4) #=> 5.0
//}... -
Math
. # acosh(x) -> Float (21018.0) -
x の逆双曲線余弦関数(area hyperbolic cosine)の値を返します。
...olic cosine)の値を返します。
=== 定義
acosh(x) = log(x + sqrt(x * x - 1)) [x >= 1]
@param x x >= 1 の範囲の実数
@raise TypeError x に数値以外を指定した場合に発生します。
@raise Math::DomainError x に範囲外の実数を指定した場合に発生しま......す。
@raise RangeError x に実数以外の数値を指定した場合に発生します。
@see Math.#cosh... -
Math
. # asinh(x) -> Float (21012.0) -
x の逆双曲線正弦関数(area hyperbolic sine)の値を返します。
...ea hyperbolic sine)の値を返します。
=== 定義
asinh(x) = log(x + sqrt(x * x + 1))
@param x 実数
@raise TypeError x に数値以外を指定した場合に発生します。
@raise RangeError x に実数以外の数値を指定した場合に発生します。
@see Math.#sinh... -
Integer
. sqrt(n) -> Integer (18191.0) -
非負整数 n の整数の平方根を返します。すなわち n の平方根以下の 最大の非負整数を返します。
...れます。
@raise Math::DomainError n が負の整数の時に発生します。
//emlist[][ruby]{
Integer.sqrt(0) # => 0
Integer.sqrt(1) # => 1
Integer.sqrt(24) # => 4
Integer.sqrt(25) # => 5
Integer.sqrt(10**400) == 10**200 # => true
//}
Math.sqrt(n).floor と同等......ですが、後者は浮動小数点数の精度の限界によって
真の値とは違う結果になることがあります。
//emlist[][ruby]{
Integer.sqrt(10**46) #=> 100000000000000000000000
Math.sqrt(10**46).floor #=> 99999999999999991611392 (!)
//}
@see Math.#sqrt... -
CMath
. # sqrt!(x) -> Float (9163.0) -
実数 x の平方根を返します。Math.#sqrt のエイリアスです。
...実数 x の平方根を返します。Math.#sqrt のエイリアスです。
@param x 正の実数
@raise Math::DomainError x が負の数である場合に発生します。
@raise TypeError x に数値以外を指定した場合に発生します。
@raise RangeError x に実数以外の数......値を指定した場合に発生します。
//emlist[例][ruby]{
require "cmath"
CMath.sqrt!(4.0) # => 2.0
CMath.sqrt!(9.0) # => 3.0
//}
@see Math.#sqrt... -
mathn (6042.0)
-
Rational と Complex をよりシームレスに利用できるようにするライブラリです。数値ライブラリの挙動をグローバルに変更します。
...なお、このライブラリはRuby 2.2から非推奨(deprecated)になり、Ruby 2.5で削除されました。
引き続き利用するには mathn gem をインストールしてください。
* 整数の除算が割り切れない場合、 Rational オブジェクトを返すようにな......ので、 mathn を利用しない場合には範囲エラー例外を発生していたような演算が Complex オブジェクトを返す場合もあります。
例:
Complex(0,-1)**2 #=> Complex(-1,0)
Math.sqrt(-1) #=> NaN
require 'mathn'
Complex(0,-1)**2 #=> -1
Math.sqrt(-1)......の mathn が require
される可能性を留意して書いて下されば親切だと思います。
整数同士で整除を意図するならば / メソッド ではなく div メソッド を用いると良いでしょう。
* 1174
=== Prime
クラス Prime はRuby 1.8までは mathn で... -
bigdecimal
/ math (6012.0) -
BigDecimalを使った数学的な機能を提供します。
...す。
* sqrt(x, prec)
* sin (x, prec)
* cos (x, prec)
* atan(x, prec)
* PI (prec)
* E (prec)
引数:
: x
計算対象の BigDecimal オブジェクト。
: prec
計算結果の精度。
//emlist[例][ruby]{
require "bigdecimal"
require "bigdecimal/math"
include BigMath
a = Big...