Page 1 of 1

[PB6.10] Type conversion Error 🤔?

Posted: Fri Aug 16, 2024 5:09 pm
by thyphoon
Hello !

I have a problem, but maybe it's me the problem 😅

Code: Select all

Id.w=$8825
Debug Id
Debug Hex(Id,#PB_Word)
If Id=$8825
  Debug"Ok"
EndIf 
Why not print "OK" ?

It's me ? 🙃
can you please give me your opinion? 😅🙏
Thanks for your help

Re: [PB6.10] Type conversion Error 🤔?

Posted: Fri Aug 16, 2024 5:49 pm
by Fred
You are putting an unsigned number into a signed word. Try with .u, it should be better.. 😁

Re: [PB6.10] Type conversion Error 🤔?

Posted: Fri Aug 16, 2024 5:58 pm
by thyphoon
😱
Thanks Fred 🥰

Re: [PB6.10] Type conversion Error 🤔?

Posted: Fri Aug 16, 2024 6:13 pm
by Kiffi
A little tip on the side: If you are unsure whether it is a bug, then ask in "Coding Questions" first. This will save Fred from having to move the thread.

Re: [PB6.10] Type conversion Error 🤔?

Posted: Sun Aug 18, 2024 5:51 pm
by thyphoon
Okay, noted! THANKS.

Re: [PB6.10] Type conversion Error 🤔?

Posted: Sun Aug 18, 2024 6:24 pm
by infratec
In my opinion there is a bug.

If $8825 is not a valid word, the first line should throw an error.

If this is not an error, and it isn't, because $8825 is a valid negative word value,
then the comparrison should be also true.

You can see that Hex() return this value too, so this is the value of the variable :!:
If the variable is a word, then the constant should be converted to a word and the compare have to return true.
If the conversion to a word is not possible (out of range) an error can be thrown.

It is simply not logical that I can asign this value, Hex() returns this value, but the comparrison says that it is false.

Re: [PB6.10] Type conversion Error 🤔?

Posted: Sun Aug 18, 2024 7:01 pm
by Fred
It was actually a test about it in previous version but we removed it for consistency. For example you can do:

Code: Select all

a.l=$8825
b.w = a

If b=$8825
  Debug"Ok"
EndIf
And it will still not print OK event if it looks it will. There is no bug here, as you are comparing a word value with a positive constante and the word value is negative. Forcing the Hex() output to word doesn't mean it's right. As you can see the compared values are indeed different.

Code: Select all

Id.w=$8825
Debug Id
Debug $8825

If Id=$8825
  Debug"Ok"
EndIf

Re: [PB6.10] Type conversion Error 🤔?

Posted: Sun Aug 18, 2024 7:41 pm
by infratec
Then we need inbuild type conversion procedures.

Code: Select all

Procedure.w Word(v.w)
  ProcedureReturn v
EndProcedure

Debug word($8825)

Id.w=$8825
If Id=Word($8825)
  Debug"Ok"
EndIf
Or ... $8825.w