Project

General

Profile

Actions

Bug #10086

closed

[PATCH] Remove exponents calculation from mathn.rb

Added by gogotanaka (Kazuki Tanaka) over 9 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.1.1p76
[ruby-core:63973]

Description

#English

When we override :**, we make it alias as :power! (mathn.rb:L73, L102)

Like this.

alias power! ** unless method_defined? :power!

If user have define :power!, this :power! is called unintentionally.(mathn.rb:L82, L111)

  def ** (other)
    if self < 0 && other.round != other
      Complex(self, 0.0) ** other
    else
      power!(other)
    end
  end

Now that we can do such a exponents calculation without mathn, we don't need exetend :** in mathn.

That's why I remove :** from mathn.rb

#日本語

mathn.rb で :** を上書きする際に元の :**:power! としてaliasを貼っていますが、(mathn.rb:L73, L102)

alias power! ** unless method_defined? :power!

使用者が #power! を定義していた場合、

(mathn.rb:L82, L111)

  def ** (other)
    if self < 0 && other.round != other
      Complex(self, 0.0) ** other
    else
      power!(other)
    end
  end

の部分で意図せず利用者が定義した:power! が呼ばれ可能性があるため、

またそもそもこの種の冪乗演算は mathn を必要とせずとも現在は実現されているため、

:** を mathn から削除致しました.


Files

Remove_Fixnum#power_from_mathn.patch (810 Bytes) Remove_Fixnum#power_from_mathn.patch gogotanaka (Kazuki Tanaka), 07/23/2014 11:58 AM
Remove_Bignum#power_from_mathn.patch (811 Bytes) Remove_Bignum#power_from_mathn.patch gogotanaka (Kazuki Tanaka), 07/23/2014 11:58 AM
Remove_Float#power_from_mathn.patch (496 Bytes) Remove_Float#power_from_mathn.patch gogotanaka (Kazuki Tanaka), 07/23/2014 11:58 AM
Remove_Rational#power_from_mathn.patch (2.08 KB) Remove_Rational#power_from_mathn.patch gogotanaka (Kazuki Tanaka), 07/23/2014 11:58 AM
Fix_comment_at_mathn.patch (430 Bytes) Fix_comment_at_mathn.patch gogotanaka (Kazuki Tanaka), 07/23/2014 11:59 AM
improve_rdoc_mathn_l8.patch (478 Bytes) improve_rdoc_mathn_l8.patch gogotanaka (Kazuki Tanaka), 08/01/2014 08:30 AM
improve_rdoc_mathn_l20.patch (301 Bytes) improve_rdoc_mathn_l20.patch gogotanaka (Kazuki Tanaka), 08/01/2014 08:30 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #13334: Removed deprecated mathn extentions.Closedhsbt (Hiroshi SHIBATA)Actions

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Open to Feedback

**の削除は(alias / quo の変更は不要に見えますが)いいと思います。
最後のパッチで"multiple division"から"multiple"という単語が消されていますが、これはいらないのでしょうか。

Updated by gogotanaka (Kazuki Tanaka) over 9 years ago

@Nobuyoshi Nakada さん

コメントありがとうございます.

alias / quo の変更は不要に見えますが

個人的にaliasを貼る時は(特にoperatorに対して)symbolの方が可読性が高まり好ましいと考えています.

すみませんこの様な個人的な趣向を入れ込むは避けるべきだったでしょうか.

少なくともパッチは分けるべきだったでしょうか.

最後のパッチで"multiple division"から"multiple"という単語が消されていますが、これはいらないのでしょうか。

はい. 文脈から察するに'多様な除法' を意図された言葉だと思いますが、

multiple division という表現は聞いた事がありませんし、多元や多分烈という言葉を連想されやすと思います.

gogo.

Updated by mame (Yusuke Endoh) over 9 years ago

よこやりですが、

If you need
more precise rounding with multiple division or exponentiation
operations, then mathn is the right tool.

という rdoc はそもそも不自然だと思います。

3 / 2 が 1 ではなく Rational(3, 2) になるということを
more precise rounding とは言わないと思います。
rounding はふつう四捨五入とかの丸めを意味しますが、
後者はそもそも rounding してないので。

--
Yusuke Endoh

Updated by gogotanaka (Kazuki Tanaka) over 9 years ago

@Yusuke Endoh さん

よこやりありがとうございます.

はい. 全くもって正しいご指摘だと思います. すみません僕が修正する際に気づくべきでした.

引き合いに出された文全体を

mathn serves to make mathematical operations more precise in Ruby
and to integrate other standard libraries.

にまた、別の部分(mathn.rb:L20)で

mathn features late rounding and lacks truncation of intermediate results:

という表現があったので

mathn keeps value in exact terms.

に変更致します.

gogo.

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

Applied in changeset r47290.


lib/mathn.rb: remove built-in methods

  • lib/mathn.rb (Fixnum#, Bignum#, Float#, Rational#):
    remove as these are now built-in. [ruby-core:63973] [Bug #10086]
Actions #7

Updated by hsbt (Hiroshi SHIBATA) about 7 years ago

  • Related to Feature #13334: Removed deprecated mathn extentions. added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0