Page 1 of 1
casting issue 6.30b6
Posted: Fri Jan 02, 2026 9:32 pm
by idle
when a function parameter or result variable is a float, the compiler or ide barfs on bit logic & ! | << >>
it shouldn't matter as the evaluation should cast to float as the last step not before cx, cy and ct1 are integers
So this raises an error
Code: Select all
DisplayTransparentSprite(spriteNumber,cx-(ct1&2),cy-(ct1&1))
and needs to becomes this to avoid it.
Code: Select all
Protected x.i,y.i
x = cx-(ct1&2)
y = cy-(ct1&1)
DisplayTransparentSprite(spriteNumber,x,y)
Re: casting issue 6.30b6
Posted: Mon Jan 05, 2026 9:56 am
by Fred
It how the compiler works, if a float is expected, the whole operation is translated to floats.
Re: casting issue 6.30b6
Posted: Mon Jan 05, 2026 8:53 pm
by idle
If the breaking change has taken place for the c backend maybe add a float() cast so we don't need to break up logic and use additional variables.
Re: casting issue 6.30b6
Posted: Tue Jan 06, 2026 12:51 pm
by Fred
It's just the type of the parameters which changed to floats, that's why you have an error now (to allow in between pixels display)
Re: casting issue 6.30b6
Posted: Tue Jan 06, 2026 3:18 pm
by Michael Vogel
Would be nice to get a simple casting feature within PB (similar to the Bool function)...
Code: Select all
Procedure.f float(foo)
ProcedureReturn foo
EndProcedure
Debug Abs(float(c>>1))
Selfmade casting routines are not very useful, but internal Purebasic methods would do a perfect job...
Code: Select all
Procedure.i integer(foo)
ProcedureReturn foo
EndProcedure
x.i
y.i
cx.f
cy.f
ct1.f
x = integer(cx)-(integer(ct1)&2)
y = integer(cy)-(integer(ct1)&1)
; DisplayTransparentSprite(spriteNumber,x,y)
Re: casting issue 6.30b6
Posted: Tue Jan 06, 2026 3:42 pm
by SMaag
@idle
which of your variable is float?
The documentation says x,y of DisplayTransparentSprite(#Sprite, x, y) is an Integer.
There is no reason for the Compiler to switch to Float if your variables are not float.
maybe
Code: Select all
DisplayTransparentSprite(spriteNumber,Int(cx)-(ct1&2),INt(cy)-(ct1&1)
Re: casting issue 6.30b6
Posted: Tue Jan 06, 2026 8:48 pm
by idle
All of them are integers, the function wants floats as input but It shouldn't be an issue, the promotion to float should only happen at the end of the evaluation when it passes the parameter to the function.