Ruby Exponents

T

Tony Dermont

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
 
S

Stefano Crocco

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
 
K

kranthi reddy

[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.
 
M

M. Edward (Ed) Borasky

Tony said:
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.
 
T

Tony Dermont

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top