Bug: interchangeability float/Double
Posted: Sun Dec 21, 2008 2:27 am
Heres an interesting bug in the interchangeability of Cobra float and .Net Double with respect to method returns and comparisons
gives
huh - Double and float should be the same type ( or at least directly assignable/comparable)
I suspect a missing Type fixup equating Double to float in method return types or wrt comparisons but dunno why Single/float32 wouldnt exhibit the same behaviour
THis and the bug reported in ticket:114 made the supposed 5 min generation of sandeep325's TPK problem into Cobra code a 30 minute exercise in the generation of obscene language
- Code: Select all
class FloatDbl
def main is shared
d0 as Double = 32f
d1 as Double = 32f64
d2 as Single = 32f32
print d0, d1, d2
x = Math.sqrt(Math.abs(d0)) + (5.0f * Math.pow(d0, 3.0f))
print "[if(x>400f, 'TOO LARGE', x)]" # line 9 - OK
y = .fn
/# no difference
if y > 400f # same bug/error here
print 'TOO LARGE'
else
print y
#/
print "[if(y>400f, 'TOO LARGE', y)]" # line 17 - bug
z = .fn1
print "[if(z>400f, 'TOO LARGE', z)]"
# try same with Single
xs = Math.sqrt(Math.abs(d2))
print "[if(xs>400f, 'TOO LARGE', xs)]"
xs1 = .fn2
print "[if(xs1>400f, 'TOO LARGE', xs1)]"
def fn as Double is shared
d0 as Double = 32f
return Math.sqrt(Math.abs(d0)) + (5.0f * Math.pow(d0, 3.0f))
def fn1 as float is shared
d0 as float = 32f
return Math.sqrt(Math.abs(d0)) + (5.0f * Math.pow(d0, 3.0f))
def fn2 as float32 is shared
d0 as Single = 32f32
return Math.abs(d0)
gives
- Code: Select all
floatDbl.cobra(17): error: The left and right sides of the ">" expression cannot be compared because of their types ("Double" and "float").
Compilation failed - 1 error, 0 warnings
huh - Double and float should be the same type ( or at least directly assignable/comparable)
I suspect a missing Type fixup equating Double to float in method return types or wrt comparisons but dunno why Single/float32 wouldnt exhibit the same behaviour
THis and the bug reported in ticket:114 made the supposed 5 min generation of sandeep325's TPK problem into Cobra code a 30 minute exercise in the generation of obscene language