casting issue 6.30b6

Just starting out? Need help? Post your questions and find answers here.
User avatar
idle
Always Here
Always Here
Posts: 6130
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

casting issue 6.30b6

Post 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) 
Fred
Administrator
Administrator
Posts: 18421
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: casting issue 6.30b6

Post by Fred »

It how the compiler works, if a float is expected, the whole operation is translated to floats.
User avatar
idle
Always Here
Always Here
Posts: 6130
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: casting issue 6.30b6

Post 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.
Fred
Administrator
Administrator
Posts: 18421
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: casting issue 6.30b6

Post 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)
User avatar
Michael Vogel
Addict
Addict
Posts: 2831
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: casting issue 6.30b6

Post 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)
Last edited by Michael Vogel on Tue Jan 06, 2026 7:15 pm, edited 1 time in total.
SMaag
Enthusiast
Enthusiast
Posts: 352
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: casting issue 6.30b6

Post 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)
User avatar
idle
Always Here
Always Here
Posts: 6130
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: casting issue 6.30b6

Post 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.
Post Reply