[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Inconsistent Behavior Converting String to Integer/Float

Daniel Harple

2/25/2006 3:08:00 PM

$ruby-yarv -v
ruby 2.0.0 (Base: Ruby 1.9.0 2006-02-14) [powerpc-darwin8.5.0]
YARVCore 0.4.0 Rev: 466 (2006-02-22) [opts: ]

$ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

# Correct behavior
num = "+3"
Float(num) # -> 3.0
Integer(num) # -> 3

# Strange behavior
num = "3e2"
Float(num) # -> 300.0
Integer(num) # -> ArgumentError

Why is an ArgumentError raised in the second example?

OT: ruby-talk seems to be rejecting my email. I sent this twice, and
both times it did not make it to the list.

-- Daniel

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


26 Answers

ts

2/25/2006 3:17:00 PM

0

>>>>> "D" == Daniel Harple <dharple@generalconsumption.org> writes:

D> $ruby-yarv -v
D> ruby 2.0.0 (Base: Ruby 1.9.0 2006-02-14) [powerpc-darwin8.5.0]
D> YARVCore 0.4.0 Rev: 466 (2006-02-22) [opts: ]

You have a problem with your version of yarv

uln% ruby -ve 'num = "+3"; p num, Float(num), Integer(num)'
ruby 1.9.0 (2006-02-24) [x86_64-linux]
"+3"
3.0
3
uln%

uln% ruby-yarv -ve 'num = "+3"; p num, Float(num), Integer(num)'
ruby 2.0.0 (Base: Ruby 1.9.0 2006-02-14) [x86_64-linux]
YARVCore 0.4.0 Rev: 475 (2006-02-23) [opts: ]
"+3"
3.0
3
uln%


Guy Decoux



Daniel Harple

2/25/2006 3:31:00 PM

0

ts wrote:
> You have a problem with your version of yarv

I was asking specifically about the second example:

num = "3e2"
Float(num) # -> 300.0
Integer(num) # -> ArgumentError

> Guy Decoux

-- Daniel

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


ts

2/25/2006 3:38:00 PM

0

>>>>> "D" == Daniel Harple <dharple@generalconsumption.org> writes:

D> I was asking specifically about the second example:

OK, sorry, I've not understood.

Even 1.6.8 give the same result

svg% ./ruby -ve 'Integer("3e2")'
ruby 1.6.8 (2002-12-24) [i686-linux]
-e:1:in `Integer': invalid value for Integer: "3e2" (ArgumentError)
from -e:1
svg%

1.4.2 give a strange result :-)


Guy Decoux


Yukihiro Matsumoto

2/26/2006 11:58:00 PM

0

Hi,

In message "Re: Inconsistent Behavior Converting String to Integer/Float"
on Sun, 26 Feb 2006 00:07:36 +0900, Daniel Harple <dharple@generalconsumption.org> writes:

|# Strange behavior
|num = "3e2"
|Float(num) # -> 300.0
|Integer(num) # -> ArgumentError

Integer() does not understand scientific notation as an integer
representation.

matz.


Daniel Harple

2/27/2006 12:22:00 AM

0

I also find using a capatilized method name very odd and
un-rubyish. Looking through the docs, I see there is Array(),
Float(), Integer(), String(), URI(), DelegateClass(), and
possibly more. Why is this style used over Class#new?

-- Daniel


Science

9/1/2009 11:31:00 PM

0

On Tue, 1 Sep 2009 11:09:46 -0700, tankfixer
<paul.carrier@gmail.com> wrote:

>> It confiscated wealth and gave it away
>
>So they redistributed the wealth...

That's not redistribution -it's confiscation.

Science

9/1/2009 11:35:00 PM

0

On Tue, 1 Sep 2009 11:10:37 -0700, tankfixer
<paul.carrier@gmail.com> wrote:

>> You mean instead of some idiotic "rhodesia" nonsense
>> you're crying about?
>
>You could educate yourself on Rhodesia and Russia..

What's with this pathological "Rhodesia" crap?

Science

9/1/2009 11:42:00 PM

0

On Tue, 1 Sep 2009 11:13:28 -0700, tankfixer
<paul.carrier@gmail.com> wrote:

>> It confiscated land---and without a functioning society
>> was not rational
>
>And all the means of production on that farmland..
>And any other wealth held by those not in favor with the rulers..

Hasn't a thing to do with redistribution of wealth by
any sense of the meaning under discussion

America would collapse if everything was confiscated
and given to 300 million people---utter nonsense

Those civilizatons throughoutt history that allowed
more and more wealth to fewer and fewer people were
functioning, viable, societies.---eventually
collapsing---mostly by revolution.

Governments were in place and functioning

Your Rhodesian wet-dream is nothing but a disfunctional
(or unworkable) government confiscating land and
property without any ablity to maintain control

tankfixer

9/2/2009 1:21:00 AM

0

In article <sibr95lpdrv3lvr91aeup7qlop352906ea@4ax.com>,
Science@Science.com says...
>
> On Tue, 1 Sep 2009 11:07:55 -0700, tankfixer
> <paul.carrier@gmail.com> wrote:
>
> >> Your entire rebuttal is about one fucking 5th world
> >> nation?
> >
> >It is an example of how well your wealth redistribution schemes will
> >work.
>
> It's a nonsense example of confiscation

Hardly !
It is a real world example of your beloved Marxist beliefs put to work.

tankfixer

9/2/2009 1:22:00 AM

0

In article <1lbr95l7ctvmvp1s9pokeenr04membd599@4ax.com>,
Science@Science.com says...
>
> On Tue, 1 Sep 2009 11:09:46 -0700, tankfixer
> <paul.carrier@gmail.com> wrote:
>
> >> It confiscated wealth and gave it away
> >
> >So they redistributed the wealth...
>
> That's not redistribution -it's confiscation.

You just said they gave it away...
Seems you are getting yourself confused..