HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why the hell does this compile?

01-11-2007, 03:55 PM#1
Rising_Dusk
Collapse JASS:
    local integer lvl = GetUnitAbilityLevel(u, 'A047')
    local real dur = 1.0 + R2I(lvl)
How does this compile?
I just noticed this in the code for one of my spells, and WC3 has been parsing it like it was no problem at all.
01-11-2007, 04:05 PM#2
Jacek
well real can store integers =/
01-11-2007, 04:25 PM#3
Anitarf
I think it's for the same reason this works:Set r = 0.234 * 3 3 is technicaly an integer, but real calculations can work with them.
01-11-2007, 04:37 PM#4
Captain Griffen
I think it turns them into reals. Hence why 3. is faster than real calculations with 3 (I want to put a fullstop there).
01-11-2007, 04:43 PM#5
Rising_Dusk
I know what you mean, but it just seems weird that it would work like that.
But if you do something like...

Collapse JASS:
function Bob takes integer i returns real
    return i
endfunction
It yells at you.

It doesn't make sense to me why R2I(SomeReal) would be any different.
Is it just for calculations that WE makes this distinction?
Or are there other cases where it passes too?
01-11-2007, 05:09 PM#6
moyack
Well, I tested it in Jasscraft, and yes, it's weird. But, it gives you wrong values??

I suggest to post this issue to Pjass thread, so the program can give some warnings.
01-11-2007, 05:09 PM#7
Daelin
As far as I know, real values are special (Vex, Pipe and other masters could explain you exactly why) because they are not simply "imported" from C++ float values. Therefore, plain conversions are not allowed.

~Daelin
01-11-2007, 05:17 PM#8
Vexorian
integer values are automatically converted to reals when used in operations, comparisons with reals or assigments to real. Therefore I2R is probably the least useful native.

The only exception is when used as return values. I would dare to say that this is to allow the return bug conversion between integer and real. But that's probably a huge assumption.