種類
- インスタンスメソッド (143)
- 文書 (17)
- クラス (11)
- ライブラリ (11)
- モジュール関数 (11)
ライブラリ
- ビルトイン (121)
- bigdecimal (22)
- matrix (22)
クラス
モジュール
- Kernel (11)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - Float (11)
-
NEWS for Ruby 2
. 6 . 0 (6) - Numeric (11)
- bigdecimal (11)
- coerce (11)
-
elements
_ to _ f (22) - hex (11)
- oct (11)
- split (11)
-
to
_ i (11)
検索結果
先頭5件
-
Numeric
# coerce(other) -> [Numeric] (9330.0) -
自身と other が同じクラスになるよう、自身か other を変換し [other, self] という配列にして返します。
...自身と other が同じクラスになるよう、自身か other を変換し [other, self] という配列にして返します。
デフォルトでは self と other を Float に変換して [other, self] という配列にして返します。
Numeric のサブクラスは、このメソ......erce のソースです。other が自身の知らない数値クラスであった場合、
super を呼んでいることに注意して下さい。
//emlist[例][ruby]{
# lib/rational.rb より
def coerce(other)
if other.kind_of?(Float)
return other, self.to_f
elsif other.kind_of?(Inte......ger)
return Rational.new!(other, 1), self
else
super
end
end
//}
数値クラスの算術演算子は通常自分と演算できないクラスをオペランドとして受け
取ると coerce を使って自分とオペランドを変換した上で演算を行います。
以下は R... -
String
# hex -> Integer (6112.0) -
文字列に 16 進数で数値が表現されていると解釈して整数に変換します。 接頭辞 "0x", "0X" とアンダースコアは無視されます。 文字列が [_0-9a-fA-F] 以外の文字を含むときはその文字以降を無視します。
...self が空文字列のときは 0 を返します。
//emlist[例][ruby]{
p "10".hex # => 16
p "ff".hex # => 255
p "0x10".hex # => 16
p "-0x10".hex # => -16
p "xyz".hex # => 0
p "10z".hex # => 16
p "1_0".hex # => 16
p "".hex # => 0
//}
@see String#oct, String#to_i, String#to_f......,
Kernel.#Integer, Kernel.#Float
このメソッドの逆に数値を文字列に変換するには
Kernel.#sprintf, String#%,
Integer#to_s
などを使ってください。... -
Numeric (6088.0)
-
数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。
...値を表す抽象クラスです。Integer や Float などの数値クラス
は Numeric のサブクラスとして実装されています。
演算や比較を行うメソッド(+, -, *, /, <=>)は Numeric のサブクラスで定義されま
す。Numeric で定義されているメソッド......て定義されるものがほとんどです。
つまり Numeric で定義されているメソッドは、Numeric のサブクラスとして新たに数値クラスを定義した時に、
演算メソッド(+, -, *, /, %, <=>, coerce)だけを定義すれば、数値クラスのそのほかの......- - -
times | - o - - - - -
to_c | o - - - - - o
to_f | - - o o......times | - o - - -
to_c | o - - - o
to_f | - o o o o
Numeric Integer Float Rational Complex
-... -
bigdecimal (6054.0)
-
bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。
...ecimal は浮動小数点数演算ライブラリです。
任意の精度で 10 進表現された浮動小数点数を扱えます。
//emlist[][ruby]{
require 'bigdecimal'
a = BigDecimal("0.123456789123456789")
b = BigDecimal("123456.78912345678", 40)
print a + b # => 0.123456912580245903456789e......1
//}
//emlist[][ruby]{
require "bigdecimal"
File::open("digits.txt", "r") do |file|
s = BigDecimal("0")
while line = file.gets
s = s + BigDecimal(line)
end
puts s # => 0.3e0
end
File::open("digits.txt", "r") do |file|
s = 0
while line = file.gets
s = s + line.to_f
end
put......、
//emlist[][ruby]{
require "bigdecimal/math"
//}
とすることで、sin や cos といった関数が使用できるようになります。
使用方法など、詳細は bigdecimal/math を参照して下さい。 その他、Float との相互変換などの
メソッドが bigdecimal/util... -
NEWS for Ruby 2
. 6 . 0 (6030.0) -
NEWS for Ruby 2.6.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 2.6.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......。 11258
* Kernel
* 別名
* Object#then が Object#yield_self の別名として追加されました。 14594
* 新規オプション
* Kernel.#Complex, Kernel.#Float, Kernel.#Integer,
Kernel.#Rational にエラー処理方法を指定する :exception オプショ......locate
* BigDecimal.ver
* 全ての BigDecimal オブジェクトが frozen になりました。 13984
* Kernel.#BigDecimal() が文字列を Kernel.#Float() のように
パースするようになりました。
* String#to_d がレシーバの文字列を String#to_f の... -
BigDecimal
# split -> [Integer , String , Integer , Integer] (3318.0) -
BigDecimal 値を 0.xxxxxxx*10**n と表現したときに、 符号 (NaNのときは 0、それ以外は+1か-1になります)、 仮数部分の文字列("xxxxxxx")と、基数(10)、更に指数 n を配列で返します。
...BigDecimal 値を 0.xxxxxxx*10**n と表現したときに、
符号 (NaNのときは 0、それ以外は+1か-1になります)、
仮数部分の文字列("xxxxxxx")と、基数(10)、更に指数 n を配列で返します。
//emlist[][ruby]{
require "bigdecimal"
a = BigDecimal("3.14159265")
f......, x, y, z = a.split
//}
とすると、f = 1、x = "314159265"、y = 10、z = 1 になります。
従って、以下のようにする事で Float に変換することができます。
//emlist[][ruby]{
s = "0."+x
b = f*(s.to_f)*(y**z)
//}
@see BigDecimal#to_f... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (3264.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
.../$defout>)) [obsolete]
: ((<組み込み変数/$deferr>)) [obsolete]
: ((<組み込み変数/$stdout>)) [change]
: ((<組み込み変数/$stderr>)) [change]
: ((<組み込み変数/$stdin>)) [change]
$stdout, $stderr は、$defout, $deferr の別名になり
$defout, $deferr は ((<obsolete>))......<File::Constants>)) モジュールに定義されました。
: ((<File/File.lchmod>)) [new]
: ((<File/File.lchown>)) [new]
追加
=== File::Stat
: ((<File::Stat#rdev_major|File::Stat/rdev_major>)) [new]
: ((<File::Stat#rdev_minor|File::Stat/rdev_minor>)) [new]
追加
=== Float
:......dule#append_feature の後に呼ばれるhook
: ((<Module#method_removed|Module/method_removed>)) [new]
: ((<Module#method_undefined|Module/method_undefined>)) [new]
追加
=== NameError
: ((<NameError#name|NameError/name>)) [new]
追加
=== NilClass
: ((<NilClass#to_f|Ni... -
String
# oct -> Integer (112.0) -
文字列を 8 進文字列であると解釈して、整数に変換します。
...ると解釈して、整数に変換します。
//emlist[例][ruby]{
p "10".oct # => 8
p "010".oct # => 8
p "8".oct # => 0
//}
oct は文字列の接頭辞 ("0", "0b", "0B", "0x", "0X") に応じて
8 進以外の変換も行います。
//emlist[例][ruby]{
p "0b10".oct # => 2
p "10".oct......。
//emlist[例][ruby]{
p "-010".oct # => -8
p "-0x10".oct # => -16
p "-0b10".oct # => -2
p "1_0_1x".oct # => 65
//}
@see String#hex, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float
逆に、数値を文字列に変換するにはKernel.#sprintf,
String#%, Integer#to_s... -
String
# to _ i(base = 10) -> Integer (112.0) -
文字列を 10 進数表現された整数であると解釈して、整数に変換します。
...//emlist[例][ruby]{
p " 10".to_i # => 10
p "+10".to_i # => 10
p "-10".to_i # => -10
p "010".to_i # => 10
p "-010".to_i # => -10
//}
整数とみなせない文字があればそこまでを変換対象とします。
変換対象が空文字列であれば 0 を返します。
//em......ram base 進数を指定する整数。0 か、2〜36 の整数。
@return 整数
このメソッドの逆に数値を文字列に変換するには、
Kernel.#sprintf, String#%, Integer#to_s
を使用します。
String#hex, String#oct, String#to_f,
Kernel.#Integer, Kernel.#Float
も参...