Forums

problem with floating point literal

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

problem with floating point literal

Postby jonathandavid » Tue Dec 16, 2008 12:27 pm

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
jonathandavid
 
Posts: 159

Re: problem with floating point literal

Postby Charles » Tue Dec 16, 2008 12:47 pm

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
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: problem with floating point literal

Postby jonathandavid » Tue Dec 16, 2008 1:13 pm

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')
jonathandavid
 
Posts: 159

Re: problem with floating point literal

Postby Charles » Wed Dec 17, 2008 10:11 am

Fixed, tested and checked in.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: problem with floating point literal

Postby jonathandavid » Thu Dec 18, 2008 1:23 am

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
jonathandavid
 
Posts: 159

Re: problem with floating point literal

Postby Charles » Thu Dec 18, 2008 9:23 am

Wow, you really like small numbers. :-)

Yes, I would accept a ticket for sci. notation.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: problem with floating point literal

Postby hopscc » Sat Dec 20, 2008 5:18 am

Ticket:103 added for this.
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: problem with floating point literal

Postby Charles » Sat Dec 20, 2008 1:43 pm

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
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 17 guests

cron