Forums

float literals without exponent?!

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

float literals without exponent?!

Postby ptokremin » Tue Jul 15, 2014 12:58 am

Hi,

am I missing something or is it impossible to declare floating point literal constants with an exponent, e.g.
class Test4711 is public
var epsilon as float is public, shared = 1.0e-14
?

What does work is:
class Test4711 is public
var epsilon as float is public, shared = sharp'1.0E-14'


kind regards
ptokremin
ptokremin
 
Posts: 9
Location: Ruhrgebiet - Germany

Re: float literals without exponent?!

Postby thriwkin » Wed Jul 16, 2014 2:04 am

There is a ticket for this (#103, 6 years old):
http://cobra-language.com/trac/cobra/ticket/103

The workaround in this format
x = sharp'1E-3' to float    # x = 1E-3f

can be used to create and initialize sequences as well,
for example an array of float:
class Program
def main is shared
"""
workaround for
a = @[1E-1f, 1E-2f, 1E-3f]
"""
a = @[
sharp'1E-1' to float,
sharp'1E-2' to float,
sharp'1E-3' to float,
]
assert a.getType == float[]
print a # [0.1, 0.01, 0.001]
thriwkin
 
Posts: 26

Re: float literals without exponent?!

Postby ptokremin » Wed Jul 16, 2014 10:22 pm

Hi thriwkin,

and thank's for the info!
Yes it works, but that's a pretty ugly solution, isn't it?

Let me get this straight: If I fix it, the patch will (most likely) be accepted?

kind regards
ptokremin
ptokremin
 
Posts: 9
Location: Ruhrgebiet - Germany

Re: float literals without exponent?!

Postby hopscc » Thu Jul 17, 2014 2:40 am

Sure, You've got as good a chance as anyone else ...
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron