[#6143] — Christophe Poucet <christophe.poucet@...>

Hello,

17 messages 2005/10/04
[#6147] Re: patch.tgz — nobu.nokada@... 2005/10/04

Hi,

[#6199] Kernel rdoc HTML file not being created when rdoc is run on 1.8.3 — James Britt <ruby@...>

When 1.8.3 came out, I grabbed the source and ran rdoc on it. After

9 messages 2005/10/08

[#6251] RubyGems, upstream releases and idempotence of packaging — Mauricio Fern疣dez <mfp@...>

[sorry for the very late reply; I left this message in +postponed and forgot

14 messages 2005/10/12

[#6282] Wilderness: Need Code to invoke ELTS_SHARED response — "Charles E. Thornton" <ruby-core@...>

Testing the My Object Dump and I am trying to cause creation

13 messages 2005/10/14
[#6283] Re: Wilderness: Need Code to invoke ELTS_SHARED response — Mauricio Fern疣dez <mfp@...> 2005/10/14

On Fri, Oct 14, 2005 at 05:04:59PM +0900, Charles E. Thornton wrote:

[#6288] Re: Wilderness: Need Code to invoke ELTS_SHARED response — "Charles E. Thornton" <ruby-core@...> 2005/10/14

Mauricio Fern疣dez wrote:

[#6365] Time for built-in Rational and Complex classes? — Gavin Sinclair <gsinclair@...>

There has been some support for, but no comment on, RCR #260 ("Make

12 messages 2005/10/24
[#6366] Re: Time for built-in Rational and Complex classes? — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/24

On Mon, 24 Oct 2005, Gavin Sinclair wrote:

[#6405] Re: [PATCH] Pathname.exists?() — "Berger, Daniel" <Daniel.Berger@...>

12 messages 2005/10/25
[#6406] Re: [PATCH] Pathname.exists?() — TRANS <transfire@...> 2005/10/25

On 10/25/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:

[#6408] Re: [PATCH] Pathname.exists?() — Gavin Sinclair <gsinclair@...> 2005/10/25

On 10/26/05, TRANS <transfire@gmail.com> wrote:

[#6442] Wilderness: I Have formatted README.EXT into an HTML Document — "Charles E. Thornton" <ruby-core@...>

I have taken README.EXT (English Version Only) and have reformatted

14 messages 2005/10/27

[#6469] csv.rb a start on refactoring. — Hugh Sasse <hgs@...>

For a database application I found using CSV to be rather slow.

50 messages 2005/10/28
[#6470] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/28

[#6471] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/28

On Oct 28, 2005, at 8:53 AM, Ara.T.Howard wrote:

[#6474] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/28

On Fri, 28 Oct 2005, James Edward Gray II wrote:

[#6484] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 9:58 AM, Ara.T.Howard wrote:

[#6485] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sat, 29 Oct 2005, James Edward Gray II wrote:

[#6486] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 8:25 PM, Ara.T.Howard wrote:

[#6487] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sat, 29 Oct 2005, James Edward Gray II wrote:

[#6491] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 8:43 PM, Ara.T.Howard wrote:

[#6493] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 10:06 PM, James Edward Gray II wrote:

[#6496] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sun, 30 Oct 2005, James Edward Gray II wrote:

[#6502] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/30

On Oct 29, 2005, at 12:11 PM, Ara.T.Howard wrote:

[#6505] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/30

On Mon, 31 Oct 2005, James Edward Gray II wrote:

[#6511] Planning FasterCSV (was Re: csv.rb a start on refactoring.) — James Edward Gray II <james@...> 2005/10/30

I've decided to create a FasterCSV library, based on the code we

[#6516] Re: Planning FasterCSV (was Re: csv.rb a start on refactoring.) — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/31

On Mon, 31 Oct 2005, James Edward Gray II wrote:

[#6518] Re: Planning FasterCSV (was Re: csv.rb a start on refactoring.) — "NAKAMURA, Hiroshi" <nakahiro@...> 2005/10/31

-----BEGIN PGP SIGNED MESSAGE-----

Re: Integer#** weirdness

From: Peter Vanbroekhoven <calamitates@...>
Date: 2005-10-19 10:19:12 UTC
List: ruby-core #6329
On Wed, 19 Oct 2005, Mark Hubbart wrote:

> Note that the error is generated in rational.rb. Rational.rb does the
> comparison so that it can trap negative exponents and give a rational
> result:
>
> irb> [2 ** -1, 2 ** -2]
>    ==>[Rational(1, 2), Rational(1, 4)]
>
> Try not requiring rational.rb, and your code works perfectly. So this
> is actually a problem with the rational library. It appears that it
> does the comparison to gain speed when rational division isn't needed.
>
> A possible fix to this: change the Integer#rpower method definition in
> rational.rb from
>
>  def rpower (other)
>    if other >= 0
>      self.power!(other)
>    else
>      Rational.new!(self,1)**other
>    end
>  end
>
> to:
>
>  def rpower (other)
>    me, you = other.coerce(self)
>    return me**you unless me == self
>    if other >= 0
>      self.power!(other)
>    else
>      Rational.new!(self,1)**other
>    end
>  end
>
> This seems to fix your problem, while still letting Rational do its
> rational thing:
>
> p 2 ** SomeNumberLikeThing.new(2)
> p 2 ** SomeNumberLikeThing.new(-3)
> p 2 ** -3
>
> #<SomeNumberLikeThing:0x1c2e14 @value=4>
> #<SomeNumberLikeThing:0x1c2e14 @value=Rational(1, 8)>
> Rational(1, 8)
>
> There seems to be a very small performance hit for this:
>
> mark@eMac% ruby -rbenchmark -rrational
> -e'Benchmark.bm(10){|x|x.report("modified"){100000.times{|n|2**(-n)}}}'
>                user     system      total        real
> modified   23.220000   0.400000  23.620000 ( 27.584483)
> mark@eMac% ruby -rbenchmark -rrational
> -e'Benchmark.bm(10){|x|x.report("original"){100000.times{|n|2**(-n)}}}'
>                user     system      total        real
> original   22.400000   0.400000  22.800000 ( 26.598195)
>
>
> ... but these benchmarks are not necessarily conclusive.  I may be
> missing something big there.

I was aware where the error was generated (even looked at the code), but I 
didn't realize that it was not supposed to be loaded without being 
required explicitly. Actually I'm not requiring it, Rubygems is (it 
requires time.rb, which indirectly requires rational.rb). But turning off 
Rubygems is not an option, so it would be nice if rational.rb was changed 
per your suggestion above.

Another possibility is to change Rational#rpower to this:

   def rpower (other)
     if other.is_a?(Integer) && other < 0
       Rational.new!(self,1)**other
     else
       self.power!(other)
     end
   end

It takes a slightly smaller performance penalty than your proposal, but it 
makes things a lot faster when the exponent is not an integer.

[peterv@alya] ruby -rbenchmark -rrational 
-e'Benchmark.bm(10){|x|x.report("original"){100000.times{|n|2**(-n)}}}'
                 user     system      total        real
original   13.590000   0.090000  13.680000 ( 13.683114)
[peterv@alya] ruby -rbenchmark -rrational 
-e'Benchmark.bm(10){|x|x.report("modified"){100000.times{|n|2**(-n)}}}'
                 user     system      total        real
modified   13.870000   0.070000  13.940000 ( 13.952034)

[peterv@alya] ruby -rbenchmark -rrational 
-e'Benchmark.bm(10){|x|x.report("original_float"){100000.times{|n|2**(-n+0.1)}}}'
                 user     system      total        real
original_float  1.250000   0.000000   1.250000 (  1.249663)
[peterv@alya] ruby -rbenchmark -rrational 
-e'Benchmark.bm(10){|x|x.report("modified_float"){100000.times{|n|2**(-n+0.1)}}}'
                 user     system      total        real
modified_float  0.410000   0.000000   0.410000 (  0.408085)

Thanks for helping to sort this out.

Peter

In This Thread