Project

General

Profile

Bug #12339

result of 123456789 ** -2 in doc

Added by znz (Kazuhiro NISHIYAMA) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-05-02 trunk 54882) [x86_64-darwin14]
[ruby-dev:49606]

Description

https://github.com/ruby/ruby/blob/c353ec0c9e8e941f49910a51f7dc10cf3d3cdd17/numeric.c#L3647
Integer#** の rdoc で

 *    123456789 ** -2     #=> 6.5610001194102e-17

となっていますが、実際に試してみると (1/15241578750190521) になります。
どちらが正しいのでしょうか?

%  ruby -ve 'p 123456789 ** -2'
ruby 2.4.0dev (2016-05-02 trunk 54882) [x86_64-darwin14]
(1/15241578750190521)

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to znz (Kazuhiro NISHIYAMA)
  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

1.9でRationalが組み込みになって動作が変わったはずです。

#2

Updated by Anonymous almost 4 years ago

  • Status changed from Assigned to Closed

Applied in changeset r54898.


Update result of 123456789 ** -2

  • numeric.c: [DOC] Update result of 123456789 ** -2. [ruby-dev:49606] [Bug #12339]

Updated by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONTNEED

該当する部分は r54831 で Fixnum/Bignum メソッドの統合時に書き加えられていて、ruby_2_3 以前のブランチの rdoc 用コメントには存在しませんでした。また 1 ** -2 の例は正しく (1/2) の表記になっていました。

Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago

  • Backport changed from 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONTNEED to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED

Bignum#** からのマージなので、ruby_2_3 以前のブランチでは rb_big_pow にあります。

Updated by nagachika (Tomoyuki Chikanaga) almost 4 years ago

なるほどその通りでした。指摘ありがとうございます。

Updated by nagachika (Tomoyuki Chikanaga) almost 4 years ago

  • Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE

ruby_2_3 r54922 merged revision(s) 54898.

Updated by usa (Usaku NAKAMURA) almost 4 years ago

  • Backport changed from 2.1: REQUIRED, 2.2: REQUIRED, 2.3: DONE to 2.1: REQUIRED, 2.2: DONE, 2.3: DONE

ruby_2_2 r55350 merged revision(s) 54898.

Also available in: Atom PDF