LoginLogin
Might make SBS readonly: thread

Using SWAP with numbers

Root / SmileBASIC Bug Reports / [.]

12Me21Created:
DEF TEST A,B
 SWAP A,B
 ?B,A
END

TEST 7,2.3
'7   2
I guess this isn't technically a bug, but it's very annoying to deal with. SWAP doesn't actually swap number variables, it just swaps the VALUES. So if you swap a float and an int, the value that was stored in the float will be truncated. This is a problem when using SWAP in functions, because the types of the variables are controlled by the input values. (In the example, replacing 7 with 7.0 or 7# will fix the problem, but that's annoying and you can't trust the user to do that.)

The only solution (if you could call it that) that I can think of would be this:
COMMON DEF SWP A,B OUT A2,B2
 VAR C#=A
 VAR D#=B
 A2=D#
 B2=C#
 RETURN A2,B2
END