Page 1 of 1

float literals without exponent?!

PostPosted: Tue Jul 15, 2014 12:58 am
by ptokremin
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

Re: float literals without exponent?!

PostPosted: Wed Jul 16, 2014 2:04 am
by thriwkin
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]

Re: float literals without exponent?!

PostPosted: Wed Jul 16, 2014 10:22 pm
by ptokremin
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

Re: float literals without exponent?!

PostPosted: Thu Jul 17, 2014 2:40 am
by hopscc
Sure, You've got as good a chance as anyone else ...