Page 1 of 1

problem with floating point literal

PostPosted: Tue Dec 16, 2008 12:27 pm
by jonathandavid
The following program does not work

class Test
def main is shared
x = 0.00001f # line 4
print x


I get the error "; expected at line 4"

Seems like a parser problem to me. It works fine if I remove the "f" at the end of the literal, or if I change it to "0.00001f".

Regards,
Manuel

Re: problem with floating point literal

PostPosted: Tue Dec 16, 2008 12:47 pm
by Charles
I assume you meant to say that you changed it to "0.0001f".

The bug is in the code generation which outputs "1E-05.0". This is coming from the .NET library (since Cobra is a .NET language) but apparently is not a format that makes C# happy.

I'm booked for today, so I'll have to fix tomorrow. The temporary workaround is:
x = sharp'0.00001' to float

Re: problem with floating point literal

PostPosted: Tue Dec 16, 2008 1:13 pm
by jonathandavid
Chuck wrote:I assume you meant to say that you changed it to "0.0001f".


It's funny, actually I wanted to say '1.00001f'.

BTW my workaround was slightly less efficient :)

x = float.parse('0.00001')

Re: problem with floating point literal

PostPosted: Wed Dec 17, 2008 10:11 am
by Charles
Fixed, tested and checked in.

Re: problem with floating point literal

PostPosted: Thu Dec 18, 2008 1:23 am
by jonathandavid
Thanks, works great now.

On a related note, I see that scientific notation (e.g. 1e-10f) is not supported. Chuck: if you want you can open a ticket, I'll take care when I have some spare time.

For anyone that's interested, there is an obvious workaround for this:

x = sharp'10e-10'


Regards,
Manuel

Re: problem with floating point literal

PostPosted: Thu Dec 18, 2008 9:23 am
by Charles
Wow, you really like small numbers. :-)

Yes, I would accept a ticket for sci. notation.

Re: problem with floating point literal

PostPosted: Sat Dec 20, 2008 5:18 am
by hopscc
Ticket:103 added for this.

Re: problem with floating point literal

PostPosted: Sat Dec 20, 2008 1:43 pm
by Charles
I added comment "Approved." just to make it extra clear that I'll accept patches on this. I guess Trac doesn't have an explicit approval flag on tickets.

Also, I recommend linking to tickets for convenience. ticket:103