logo       

Re: Problem with Numbers: msg#00000

lang.boo.devel

Subject: Re: Problem with Numbers

On Mon, 31 Jan 2005 23:25:28 +0100, Martin Karlsch
<martin.karlsch-pbucWI+kC1JoahveU0mBMoQuADTiUCJX@xxxxxxxxxxxxxxxx> wrote:
> Hallo,
>
> I found something that really annoys me.
>
> b as ulong = 255*255*255*255 throws an OverflowException
>
> b as ulong = cast(ulong,255) *cast(ulong,255) *cast(ulong,255) *
> cast(ulong,255)
>
> Is the RHS always treated as System.Int32 and casted to ulong after
> evaluation?
>
> Kind regards,
> A boo loving Martin ;-)

I believe so. Numbers are parsed as signed integers unless you put an
"L" after them:
b as ulong = 255L*255L*255L*255L*255L //works

Maybe we should add "U" (unsigned int) and "UL" (unsigned long)
suffixes like C#:
c as ulong = 18446744073709551615UL
print c if c == ulong.MaxValue

Also, I think when there is no suffix, C# converts a literal number to
a long or unsigned long if the value is too big.

Other types for literal numbers in boo (these work):
x = 255
print x.GetType() //-> int (System.Int32)
y = 255L
print y.GetType() //-> long (System.Int64)
z = 255.0
print z.GetType() //-> double (System.Double)
q = 255ms
print q.GetType() //-> timespace (System.TimeSpan)



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise