[PB6.10] Type conversion Error 🤔?

Just starting out? Need help? Post your questions and find answers here.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 358
Joined: Sat Dec 25, 2004 2:37 pm

[PB6.10] Type conversion Error 🤔?

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

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

Post by Fred »

You are putting an unsigned number into a signed word. Try with .u, it should be better.. 😁
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 358
Joined: Sat Dec 25, 2004 2:37 pm

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

Post by thyphoon »

😱
Thanks Fred 🥰
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post 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.
Hygge
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 358
Joined: Sat Dec 25, 2004 2:37 pm

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

Post by thyphoon »

Okay, noted! THANKS.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

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

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

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

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