[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby Exponents

Tony Dermont

7/2/2008 8:33:00 AM

Hi,

I'm trying to calculate using exponential operator **. However, I get a
crash with the following message

wrong argument type Float (expected Fixnum)

The values I am using are 0.713 ** 0.5555555 => THIS CRASHES

But when I try this on a ruby command prompt, it works fine. Is there a
way I can calculate using a float number as an exponent?

Thanks.

Tony
--
Posted via http://www.ruby-....

4 Answers

Stefano Crocco

7/2/2008 8:38:00 AM

0

On Wednesday 02 July 2008, Tony Dermont wrote:
> Hi,
>
> I'm trying to calculate using exponential operator **. However, I get a
> crash with the following message
>
> wrong argument type Float (expected Fixnum)
>
> The values I am using are 0.713 ** 0.5555555 => THIS CRASHES
>
> But when I try this on a ruby command prompt, it works fine. Is there a
> way I can calculate using a float number as an exponent?
>
> Thanks.
>
> Tony

Are you sure the error is due to that computation? It works perfectly for me,
either in irb, passing it to ruby -e or putting it in a script.

Stefano


kranthi reddy

7/2/2008 9:54:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Yeah even I dont any errors either through the ruby script or IRB ..can you
paste the error you get when you use the script
kranthi.

On Wed, Jul 2, 2008 at 2:08 PM, Stefano Crocco <stefano.crocco@alice.it>
wrote:

> On Wednesday 02 July 2008, Tony Dermont wrote:
> > Hi,
> >
> > I'm trying to calculate using exponential operator **. However, I get a
> > crash with the following message
> >
> > wrong argument type Float (expected Fixnum)
> >
> > The values I am using are 0.713 ** 0.5555555 => THIS CRASHES
> >
> > But when I try this on a ruby command prompt, it works fine. Is there a
> > way I can calculate using a float number as an exponent?
> >
> > Thanks.
> >
> > Tony
>
> Are you sure the error is due to that computation? It works perfectly for
> me,
> either in irb, passing it to ruby -e or putting it in a script.
>
> Stefano
>
>
>

M. Edward (Ed) Borasky

7/2/2008 1:28:00 PM

0

Tony Dermont wrote:
> Hi,
>
> I'm trying to calculate using exponential operator **. However, I get a
> crash with the following message
>
> wrong argument type Float (expected Fixnum)
>
> The values I am using are 0.713 ** 0.5555555 => THIS CRASHES
>
> But when I try this on a ruby command prompt, it works fine. Is there a
> way I can calculate using a float number as an exponent?
>
> Thanks.
>
> Tony

znmeb@DreamScape ~ $ echo 'puts 0.713 ** 0.5555555' > script.rb
znmeb@DreamScape ~ $ ruby script.rb
0.828672792977234
znmeb@DreamScape ~ $ ruby -e ' puts 0.713 ** 0.5555555'
0.828672792977234
znmeb@DreamScape ~ $ irb
irb(main):001:0> 0.713 ** 0.5555555
=> 0.828672792977234
irb(main):002:0> quit
znmeb@DreamScape ~ $ ruby --version
ruby 1.8.6 (2008-06-20 patchlevel 230) [x86_64-linux]
znmeb@DreamScape ~ $

So there's nothing wrong with your code. What version of Ruby do you
have? Maybe it needs to be upgraded or re-installed.

Tony Dermont

7/2/2008 4:53:00 PM

0

Thanks for all the replies. I just can't figure it out. I placed the
same set code in just a ruby file and it runs fine, but when I have it
inside a rails model it crashed with this crash message on my browser.
If I put in an integer value for the exponent, it does not crash.

app/models/trade.rb:137:in `**'
app/models/trade.rb:137:in `calculate_cagr'
app/views/adminportfolio/ajax_disport.rhtml:96:in
`_run_erb_47app47views47adminportfolio47ajax_disport46rhtml'
app/views/adminportfolio/ajax_disport.rhtml:69:in `each'
app/views/adminportfolio/ajax_disport.rhtml:69:in
`_run_erb_47app47views47adminportfolio47ajax_disport46rhtml'
app/views/adminportfolio/ajax_disport.rhtml:67:in
`_run_erb_47app47views47adminportfolio47ajax_disport46rhtml'

This might be a rails issue, but if anyone can help me out I'd truly
truly appreciate it.

Tony
--
Posted via http://www.ruby-....