From ruby-math-admin@netlab.co.jp Thu Apr 27 12:22:31 2000 Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by blade.nagaokaut.ac.jp (8.8.8/8.8.8/Debian/GNU) with ESMTP id MAA01587 for ; Thu, 27 Apr 2000 12:22:31 +0900 Resent-From: ruby-math-admin@netlab.co.jp Received: from hoyogw.netlab.co.jp by voscc.nagaokaut.ac.jp id MAA91840; Thu, 27 Apr 2000 12:18:28 +0900 (JST) Received: from hoyogw.netlab.co.jp (matz@localhost [127.0.0.1]) by hoyogw.netlab.co.jp (8.9.3+3.2W/3.7W/1.3) with SMTP id MAA14578 for ; Thu, 27 Apr 2000 12:18:26 +0900 Date: Fri, 21 Jan 2000 11:38:59 +0900 From: rubikitch Reply-To: ruby-math@netlab.co.jp Subject: [ruby-math:00090] math functions Sender: Takashi Nishimoto To: ruby-math@netlab.co.jp Message-Id: <20000121113859M.takashi@localhost> X-ML-Name: ruby-math X-Mail-Count: 00090 X-MLServer: fml [fml 2.2]; post only (only members can post) X-ML-Info: If you have a question, send a mail with the body "# help" (without quotes) to the address ruby-math-ctl@netlab.co.jp; help= X-Mailer: Mew version 1.93 on Emacs 20.3 / Mule 4.0 (HANANOEN) X-Dispatcher: imput version 980905(IM100) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Precedence: bulk Resent-To: poffice@blade.nagaokaut.ac.jp Resent-Date: Thu, 27 Apr 2000 12:18:26 +0900 Resent-Message-Id: <200004271218.FMLAAA14570.ruby-math@netlab.co.jp> るびきちです。 初等数学関数(sin, cos, ...)についてなんだけど、 やっぱり「内部で」 number.sin って感じで呼出せると便利だなと思った。 Math::sin number はあくまで number.sin の「インターフェース」で あったらなぁって考えてみた。 (include して使用することもあるから、 sin(x) のように引数があったら x.sin を呼出して、なかったら self.sin を呼出すようにする) number が属するクラスの instance method として定義することで、 そのクラスにおける初等関数がきれいに定義できるんじゃないかな?? 実際数だけでなく自動微分型や区間型にも sin などが定義されている。 現状のままだといちいち def Math::sin(x) case x when Float, Fixnum, Bignum 数学関数の sin when Autodiff 自動微分型の sin when Interval 区間型の sin else 例外発生 end end end って感じになって、新たに型を作ったときの修正が困難(>_<) で、この方法を使うと、 module Math alias sin_ sin #元々の定義を別名で保存 module_function :sin_ def sin(x=nil) if x then x.sin else self.sin end end module_function :sin end for klass in [Fixnum,Bignum,Float] eval <