Cannot use btiwise operators in expression assigned to float

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Cannot use btiwise operators in expression assigned to float

Post by Mistrel »

I just realized that we cannot do this:

Code: Select all

Float.f=Integer&$FFFF
It produces an error:
Can't use any of the following operands with floats: <<, >>, &, |, !, %.
But we can do this:

Code: Select all

Integer=Integer&$FFFF
Float.f=Integer
Am I missing something? :|
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by Tenaja »

My guess would be, since it is a float assignment, the integer is converted to a float first, and that causes the err since we cannot do bit operations on floats.
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by sys64802 »

It shouldn't because it's clearly limiting and the integer expression "Integer & $FFFF" should be evalued and then converted to float to be assigned, but it's how the PB compiler has been written.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by Mistrel »

I always thought that promotion came after evaluating an expression in a similar fashion to C. This definitely is not the case:

Code: Select all

LongA.l=2147483647
LongB.l=2147483647
Quad.q=LongA*LongB

Debug Quad.q
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by Tenaja »

I am pretty sure PB promotes immediately after the first float is found.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by Mistrel »

This doesn't work either and reports the same error:

Code: Select all

Long.l=Float.f&$FFFF
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by sys64802 »

Unsurprisingly since "&" doesn't work with floats, as the popup error reminds you.

Code: Select all

Long.l=Int(Float.f) & $FFFF
This is different:

Code: Select all

Float.f=Integer&$FFFF
You don't have a float as operand for "&" here, so it should work, and then cast the result.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Cannot use btiwise operators in expression assigned to f

Post by Mistrel »

I know that. It's just that it seemed as though promotion is done before the expression but in second case it is not. So the rules seem inconsistent?
Post Reply