[#33561] open-uri problem — rubikitch@...
るびきちです。
[#33567] rational, complex and nuby — Tadayoshi Funaba <tadf@...>
ruby に rational と complex を組みこもうと試していて nuby という派生物
なかだです。
> 若干古い1.8.6がベースでしょうか。
なかだです。
> 2002/01/25版にその後の修正を手で追加した状態? ChangeLogをみたら、
なかだです。
> ちょっと見たところ、Enumerable#stable_sort_byがsortを使っている
原です。
[#33580] Re: cgi.rb再構築案 — "Makoto Kuwata" <kwa@...>
桑田といいます。
まつもと ゆきひろです
なかだです。
[#33611] Solaris で timeout.rb が Segmentation fault する。 — shiiya@...
はじめまして。椎屋と申します。
なかだです。
椎屋です。反応ありがとうございます。
なかだです。
さとうふみやす @ OSS テクノロジです。
In article <87r6foys1z.wl%fumiyas@osstech.jp>,
At Fri, 8 Feb 2008 14:00:35 +0900,
In article <87prv8yovi.wl%fumiyas@osstech.jp>,
とみたです。
In article <20080219182203.2559fc3e.tommy@tmtm.org>,
[#33621] EUC-KR <-> UTF-8 transition table — "Park Ji-In" <tisphie@...>
朴 芝印です。
成瀬です。
At 05:00 08/02/07, NARUSE, Yui wrote:
朴 芝印です。
[#33628] encdet.rb — Tanaka Akira <akr@...>
前から考えていたのですが、ファイル先頭の magic comment や
まつもと ゆきひろです
In article <E1JN0fO-00084M-Dg@x61.netlab.jp>,
須藤です。
In article <20080214.203702.439940124859613817.kou@cozmixng.org>,
須藤です。
In article <20080215.210932.373570872046057306.kou@cozmixng.org>,
須藤です。
In article <20080219.210130.275954098091635027.kou@cozmixng.org>,
[#33646] require/load/autoload の encoding オプション — Hidetoshi NAGAI <nagai@...>
永井@知能.九工大です.
まつもと ゆきひろです
永井@知能.九工大です.
[#33662] rational, complex and mathn — Tadayoshi Funaba <tadf@...>
rational は floor、truncate、ceil、round を定義していません。Numeric
他にも問題、課題はあると思います。すぐに解決できるものと、そうでないも
ひとつ書き忘れました。
まつもと ゆきひろです
> 原さんのrationalは導入予定がありますので、この機会にもう一度
原です。
> 前にふなばさんと個人的なメールのやりとりで、結局また私がrationalをまと
原です。
> > それなりに速くはなるし、単純なところでそれなりに満足していますが、一度、
nurat 0.0.2 を出しました (ついでに nucomp も)。
仕様を確認していきたいと思います。
まつもと ゆきひろです
原です。
> > new!はRubyで実装しているためにだけ必要なので、Cで実装するな
原です。
> Rational::Unify が定義されているときは、Rational.new(1,1) で Integer
> Rational() は、1つか2つの引数をとる。
> 実際的に重要な機能が Rational() という名前で固定されるのはクラスの定義
もうあまり手を入れないでおこうと思ったのです、つい手を入れてしまいまし
原です。
ちょっと実験してみました。原さんの rational は、かけ算割り算が速いので、
で、考えていたんですが、目的は、最速の rational を作ることではなくて、
原です。
成瀬です。
まつもと ゆきひろです
> はい。Complexについても1.9の間に組み込んでよいと思います。
まつもと ゆきひろです
nurat を組みこんでみました。最低限必要な修正だけになっていると思います。
rational と complex を 1.9 に組みこむ作業をしました。
異議がなければ、若干の手直しの後、次週末にでも trunk にコミットしよう
> 異議がなければ、若干の手直しの後、次週末にでも trunk にコミットしよう
まつもと ゆきひろです
[#33674] erb.rb の仕様について — "Makoto Kuwata" <kwa@...>
桑田といいます。
[#33676] Suggestion: Proc#curry — "Yusuke ENDOH" <mame@...>
遠藤と申します。
[#33679] bigdecimal — Tadayoshi Funaba <tadf@...>
bigdecimal/math.rb の BigMath は、利用者が include してつかうことを前
Integer や Float に比べると、BigDicimal() は、1 や 1.1 を受けつけない、
斎藤と申します。
> 仮にBigDecimal(1.1)を、(二進小数として)受け付けると、「BigDecimalでは、
まつもと ゆきひろです
[#33699] trunk: インストールファイルのアクセス権 — pegacorn <subscriber.jp@...>
trunk で、インストールファイルのアクセス権が適切に設定されないものが
[#33712] Array の product の戻り値 — "Hideo Konami" <konami@...>
小波です。
[#33726] Re: [ruby-cvs:22680] Ruby:r15443 (trunk): * bootstraptest/runner.rb, bootstraptest/test_method.rb, enc/depend, — "U.Nakamura" <usa@...>
こんにちは、なかむら(う)です。
成瀬です。
In article <47B26518.60309@airemix.com>,
Tanaka Akira wrote:
こんにちは、なかむら(う)です。
成瀬です。
[#33825] Ruby M17N 会議の議事録 — "NARUSE, Yui" <naruse@...>
成瀬です。
[#33837] spec of Rational — Shin-ichiro HARA <sinara@...>
原です。
[#33838] 文字列処理の高速化 ? — Martin Duerst <duerst@...>
ただの一例ですが、先週の金曜日に松本さんに見せたときに
[#33843] IO.copy_stream — Tanaka Akira <akr@...>
IO.copy_stream をつけるのはどうでしょうか。
[#33889] Re: [ ruby-Bugs-17454 ] irb crash while iterating over all objects — Urabe Shyouhei <shyouhei@...>
卜部です。ちょっとお知恵を拝借したく。
ミスって送信ボタン押しちゃった
こんにちは、なかむら(う)です。
なかだです。
Nobuyoshi Nakada さんは書きました:
豊福です。
まつもと ゆきひろです
豊福です。
まつもと ゆきひろです
豊福です。
まつもと ゆきひろです
豊福です。
[#33894] character encodings differ: US-ASCII and dummy encoding — Kazuhiro NISHIYAMA <zn@...>
西山和広です。
まつもと ゆきひろです
[#33916] UTF_16LE.dummy? returns false — sheepman <sheepman@...>
こんにちは sheepman です。
[#33926] --host=i586-mingw32msvc — Kouhei Sutou <kou@...>
須藤です。
[#33937] patch for ruby_1_8_6/lib/rexml/element.rb@12852 — oshida@...
押田です。
[#33943] warning about space before argument parentheses — Nobuyoshi Nakada <nobu@...>
なかだです。
[ruby-dev:33662] rational, complex and mathn
rational は floor、truncate、ceil、round を定義していません。Numeric
のまま提供しています。しかし、Numeric のものは、浮動小数点数に変換して
しまうためまともな結果が得られるとは限りません。[ruby-dev:32201]
現状、floor のかわりに to_i をつかって問題がないのは、to_i の定義が
floor になっているからです。Float#to_i の定義から、Numeric の to_i は
truncate であるべきだと思います。
Complex(1,2).numerator がエラーになります。rational を読んでいるとエラー
になりません。
$ ruby19 -r complex -e 'Complex(1,2).numerator'
/usr/local/ruby19/lib/ruby/1.9.0/complex.rb:345:in `denominator': undefined method `denominator' for 1:Fixnum (NoMethodError)
from /usr/local/ruby19/lib/ruby/1.9.0/complex.rb:352:in `numerator'
from -e:1:in `<main>'
Complex#quo が機能しません。普通に整数割りしてしまいます。
$ ruby19 -r complex -e 'p Complex(1,2).quo(2)'
Complex(0, 1)
$ ruby19 -r complex -r rational -e 'p Complex(1,2).quo(2)'
Complex(0, 1)
complex では、不要に思えるメソッドが放置してあります。>、>=、<、<=、
between?、floor、ceil、round、truncate など。1.8 では、step、<=> も。
あと、% は意味があるのでしょうか。
mathn で、Rational#inspect を書き換えているが、さすがに余計なお世話の
ような気もします。どうしてもしたければ、そういうことは、irb などアプリ
ケーション側でやればいいような気がします。
以下修正案。floor、ceil、truncate、round は原さんの rational からパク
りました。
Index: lib/rational.rb
===================================================================
--- lib/rational.rb (revision 15409)
+++ lib/rational.rb (working copy)
@@ -238,6 +238,10 @@
end
end
+ def div(other)
+ (self / other).floor
+ end
+
#
# Returns the remainder when this value is divided by +other+.
#
@@ -249,7 +253,7 @@
# r % 0.26 # -> 0.19
#
def % (other)
- value = (self / other).to_i
+ value = (self / other).floor
return self - other * value
end
@@ -261,7 +265,7 @@
# r.divmod Rational(1,2) # -> [3, Rational(1,4)]
#
def divmod(other)
- value = (self / other).to_i
+ value = (self / other).floor
return value, self - other * value
end
@@ -270,7 +274,7 @@
#
def abs
if @numerator > 0
- Rational.new!(@numerator, @denominator)
+ self
else
Rational.new!(-@numerator, @denominator)
end
@@ -345,10 +349,37 @@
# Rational(-7,4) == -1.75 # -> true
# Rational(-7,4).to_i == (-1.75).to_i # false
#
- def to_i
- Integer(@numerator.div(@denominator))
+
+ def floor()
+ @numerator.div(@denominator)
end
+ def ceil()
+ -((-@numerator).div(@denominator))
+ end
+
+ def truncate()
+ if @numerator < 0
+ return -((-@numerator).div(@denominator))
+ end
+ @numerator.div(@denominator)
+ end
+
+ alias_method :to_i, :truncate
+
+ def round()
+ if @numerator < 0
+ num = -@numerator
+ num = num * 2 + @denominator
+ den = @denominator * 2
+ -(num.div(den))
+ else
+ num = @numerator * 2 + @denominator
+ den = @denominator * 2
+ num.div(den)
+ end
+ end
+
#
# Converts the rational to a Float.
#
@@ -476,10 +507,11 @@
class Fixnum
alias quof quo
- undef quo
- # If Rational is defined, returns a Rational number instead of a Fixnum.
+ remove_method :quo
+
+ # If Rational is defined, returns a Rational number instead of a Float.
def quo(other)
- Rational.new!(self,1) / other
+ Rational.new!(self, 1) / other
end
alias rdiv quo
@@ -488,26 +520,18 @@
if other >= 0
self.power!(other)
else
- Rational.new!(self,1)**other
+ Rational.new!(self, 1)**other
end
end
-
- unless defined? 1.power!
- alias power! **
- alias ** rpower
- end
end
class Bignum
- unless defined? Complex
- alias power! **
- end
+ alias quof quo
+ remove_method :quo
- alias quof quo
- undef quo
- # If Rational is defined, returns a Rational number instead of a Bignum.
+ # If Rational is defined, returns a Rational number instead of a Float.
def quo(other)
- Rational.new!(self,1) / other
+ Rational.new!(self, 1) / other
end
alias rdiv quo
@@ -519,8 +543,15 @@
Rational.new!(self, 1)**other
end
end
+end
- unless defined? Complex
+unless defined? 1.power!
+ class Fixnum
+ alias power! **
alias ** rpower
end
+ class Bignum
+ alias power! **
+ alias ** rpower
+ end
end
Index: lib/mathn.rb
===================================================================
--- lib/mathn.rb (revision 15409)
+++ lib/mathn.rb (working copy)
@@ -121,11 +121,6 @@
class Rational
Unify = true
- remove_method :inspect
- def inspect
- format "%s/%s", numerator.inspect, denominator.inspect
- end
-
alias power! **
def ** (other)
Index: lib/complex.rb
===================================================================
--- lib/complex.rb (revision 15409)
+++ lib/complex.rb (working copy)
@@ -104,6 +104,10 @@
@RCS_ID='-$Id: complex.rb,v 1.3 1998/07/08 10:05:28 keiju Exp keiju $-'
undef step
+ undef <, <=, <=>, >, >=
+ undef between?
+ undef divmod, modulo
+ undef floor, truncate, ceil, round
def scalar?
false
@@ -199,6 +203,10 @@
x/y
end
end
+
+ def quo(other)
+ Complex(@real.quo(1), @image.quo(1)) / other
+ end
#
# Raise this complex number to the given (real or complex) power.
@@ -248,6 +256,8 @@
#
# Remainder after division by a real or complex number.
#
+
+=begin
def % (other)
if other.kind_of?(Complex)
Complex(@real % other.real, @image % other.image)
@@ -258,7 +268,8 @@
x % y
end
end
-
+=end
+
#--
# def divmod(other)
# if other.kind_of?(Complex)
@@ -312,8 +323,6 @@
end
alias conj conjugate
- undef <=>
-
#
# Test for numerical equality (<tt>a == a + 0<i>i</i></tt>).
#
@@ -410,9 +419,35 @@
end
+class Integer
+ unless defined?(1.numerator) # temporal
+ def numerator() self end
+ def denominator() 1 end
+ def gcd(other)
+ min = self.abs
+ max = other.abs
+ while min > 0
+ tmp = min
+ min = max % min
+ max = tmp
+ end
+ max
+ end
+ def lcm(other)
+ if self.zero? or other.zero?
+ 0
+ else
+ (self.div(self.gcd(other)) * other).abs
+ end
+ end
+
+ end
+
+end
+
module Math
alias sqrt! sqrt
alias exp! exp