ライブラリ
- ビルトイン (203)
- bigdecimal (66)
キーワード
-
NEWS for Ruby 2
. 4 . 0 (8) -
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 7 . 0 (5) - Numeric (11)
-
ROUND
_ CEILING (11) - bigdecimal (11)
-
bit
_ length (17) - ceildiv (2)
- floor (33)
- limit (11)
- mode (22)
- round (41)
-
to
_ i (22) - truncate (33)
検索結果
先頭5件
-
Rational
# truncate(precision = 0) -> Rational | Integer (108.0) -
小数点以下を切り捨てて値を整数に変換します。
...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... -
BigDecimal
. limit(n = nil) -> Integer (107.0) -
生成されるBigDecimalオブジェクトの最大桁数をn桁に制限します。 n を指定しない、または n が nil の場合は、現状の最大桁数が返ります。
...指定された丸め処理が
実行されます。ただし、インスタンスメソッド (BigDecimal#truncate /
BigDecimal#round / BigDecimal#ceil / BigDecimal#floor /
BigDecimal#add/ BigDecimal#sub / BigDecimal#mult /
BigDecimal#div) の桁数制限は limit より優先されます。
//eml... -
Bignum
# bit _ length -> Integer (107.0) -
self を表すのに必要なビット数を返します。
...ま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果
(-2**10000-1).bit_length # => 10001
(-2**10000).bit_length # => 10000
(-2**10000+1).bit... -
Fixnum
# bit _ length -> Integer (107.0) -
self を表すのに必要なビット数を返します。
...ま
す。2**n の場合は n+1 になります。self にそのようなビットがない(0 や
-1 である)場合は 0 を返します。
例: ceil(log2(int < 0 ? -int : int+1)) と同じ結果
(-2**12-1).bit_length # => 13
(-2**12).bit_length # => 12
(-2**12+1).bit_length... -
Float
# floor -> Integer (107.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...自身と等しいかより小さな整数のうち最大のものを返します。
//emlist[例][ruby]{
1.2.floor # => 1
2.0.floor # => 2
(-1.2).floor # => -2
(-2.0).floor # => -2
//}
@see Numeric#ceil, Numeric#round, Float#truncate... -
Float
# round(ndigits = 0) -> Integer | Float (107.0) -
自身ともっとも近い整数もしくは実数を返します。
...3.141592653589793
t.round(3) # => 3.142
t.round(0) # => 3
t.round(1) # => 3.1
t = t**10 # => 93648.04747608298
t.round(-0) # => 93648
t.round(-1) # => 93650
t.round(-2) # => 93600
t.round(-3) # => 94000
t.round(-100) # => 0
//}
@see Float#ceil, Float#floor, Float#truncate... -
Numeric
# floor -> Integer (107.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...自身と等しいかより小さな整数のうち最大のものを返します。
//emlist[例][ruby]{
1.floor #=> 1
1.2.floor #=> 1
(-1.2).floor #=> -2
(-1.5).floor #=> -2
//}
@see Numeric#ceil, Numeric#round, Numeric#truncate... -
Numeric
# round -> Integer (107.0) -
自身ともっとも近い整数を返します。
...0.5, -0.5 はそれぞれ 1,-1 に切り上げされます。いわゆる四捨五入ですが、偶数丸めではありません。
//emlist[例][ruby]{
1.round #=> 1
1.2.round #=> 1
(-1.2).round #=> -1
(-1.5).round #=> -2
//}
@see Numeric#ceil, Numeric#floor, Numeric#truncate... -
Numeric
# truncate -> Integer (107.0) -
0 から 自身までの整数で、自身にもっとも近い整数を返します。
...0 から 自身までの整数で、自身にもっとも近い整数を返します。
//emlist[例][ruby]{
1.truncate #=> 1
1.2.truncate #=> 1
(-1.2).truncate #=> -1
(-1.5).truncate #=> -1
//}
@see Numeric#ceil, Numeric#floor, Numeric#round... -
Rational
# floor(precision = 0) -> Integer | Rational (107.0) -
自身と等しいかより小さな整数のうち最大のものを返します。
...onal を返します。
//emlist[例][ruby]{
Rational('-123.456').floor(+1) # => (-247/2)
Rational('-123.456').floor(+1).to_f # => -123.5
Rational('-123.456').floor(0) # => -124
Rational('-123.456').floor(-1) # => -130
//}
@see Rational#ceil, Rational#round, Rational#truncate... -
Rational
# round(precision = 0) -> Integer | Rational (107.0) -
自身ともっとも近い整数を返します。
...y]{
Rational('-123.456').round(+1) # => (-247/2)
Rational('-123.456').round(+1).to_f # => -123.5
Rational('-123.456').round(0) # => -123
Rational('-123.456').round(-1) # => -120
Rational('-123.456').round(-2) # => -100
//}
@see Rational#ceil, Rational#floor, Rational#truncate... -
NEWS for Ruby 2
. 5 . 0 (72.0) -
NEWS for Ruby 2.5.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...う。 13405
* Integer
* Integer#round, Integer#floor, Integer#ceil, Integer#truncate は常に Integer を返すようになりました
13420
* Integer#pow を追加 12508 11003
* Integer#allbits?, Integer#anybits?, Integer#nobits? を追加 12753
* Integer.sqrt を追加... -
NEWS for Ruby 2
. 7 . 0 (24.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...エンコーディングを設定する
IO#set_encoding_by_bomメソッドが追加されました。 15210
* Integer
* 変更されたメソッド
* Integer#[] がRangeを受け付けるようになりました。 8842
//emlist[][ruby]{
0b01001101[2, 4] #=> 0b0011
0b01001100[......* 新規メソッド
* Symbol#start_with?とSymbol#end_with?が追加されました。 16348
* Time
* 新規メソッド
* Time#ceilが追加されました。 15772
* Time#floorが追加されました。 15653
* 変更されたメソッド
* Time#inspectがTime#......yの上流リポジトリはSubversionからGitに変わりました。
* https://git.ruby-lang.org/ruby.git
* RUBY_REVISIONのクラスはIntegerからStringに変わりました。
* RUBY_DESCRIPTIONはSubversionのリビジョンの代わりにGitのリビジョンが
入るよ... -
bigdecimal (12.0)
-
bigdecimal は浮動小数点数演算ライブラリです。 任意の精度で 10 進表現された浮動小数点数を扱えます。
...math"
a = BigMath.E(10)
p c = "0.123456789" * a # => "0.1234567890.123456789"
//}
これは、String#* の内部で、BigDecimal が暗黙的に Integer に変換された結果です。
===[a:internal_structure] 内部構造
BigDecimal内部で浮動小数点は構造体(Real)で表現されま......ます。
//emlist[][ruby]{
require "bigdecimal"
p BigDecimal("2").div(3, 12).to_s(10) # 2.0 / 3.0
# => 0.6666666666 67e0
//}
: truncate, round, ceil, floor
これらのメソッドは小数点からの相対位置を指定して桁数を決定します。
//emlist[][ruby]{
require "bigdecimal...