Assigning Bitwise AND to Double

Just starting out? Need help? Post your questions and find answers here.
TeraByte
User
User
Posts: 40
Joined: Wed May 09, 2012 12:40 am

Assigning Bitwise AND to Double

Post by TeraByte »

I am trying to do the following:

Code: Select all

Define d1.d, d2.d, d3.d
d1 = Int(d2) & Int(d3)
Which throws compiler error "Can't use any of the following operands with floats: <<,>>,&..."

If I change it to this it works:

Code: Select all

Procedure.d Double( MyInt.i )
  ProcedureReturn MyInt
EndProcedure

Define d1.d, d2.d, d3.d
d1 = Double(Int(d2) & Int(d3))
Is there a more graceful way to do this typecast from Int to Double?
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Assigning Bitwise AND to Double

Post by idle »

if you really do need to do a logical And on doubles, you'll have to use SSE2 Instructions
though I'm not sure if you know what your doing yet after seeing your other post
about array indices.

no idea if this safe

Code: Select all


Procedure testSSE2()
  !mov eax, 1
  !cpuid 
  !and edx, $4000000 
  !sar edx,26
  !mov eax,edx
  ProcedureReturn  
EndProcedure 

Procedure.f fand(a.f,b.f)
  Protected result.f 
  !movss xmm0, [p.v_a]
  !movss xmm1, [p.v_b]
  !andps xmm0,xmm1
  !movss [p.v_result],xmm0
  ProcedureReturn result 
EndProcedure   

Procedure.d dand(a.d,b.d)
  Protected result.d 
  !movsd xmm0, [p.v_a]
  !movsd xmm1, [p.v_b]
  !andpd xmm0,xmm1
  !movsd [p.v_result] , xmm0
  ProcedureReturn result 
EndProcedure


Debug testSSE2()
Debug fand(123.456,111.456)
Debug dand(123.456,111.456)
Windows 11, Manjaro, Raspberry Pi OS
Image
TeraByte
User
User
Posts: 40
Joined: Wed May 09, 2012 12:40 am

Re: Assigning Bitwise AND to Double

Post by TeraByte »

Thank you Addict for the code for Logical And on doubles.

I would appreciate your input on my array index question also. Sorry if it seems silly, but I'm new to PB and am just trying to make sure I'm not coding it inefficiently.

Thank you.
void
Enthusiast
Enthusiast
Posts: 116
Joined: Sat Aug 27, 2011 9:50 pm
Location: Washington, USA

Re: Assigning Bitwise AND to Double

Post by void »

TeraByte wrote:Thank you Addict for the code for Logical And on doubles.
You are addressing someone with the username of 'idle', not 'addict'.

In these forums 'Addict' is a forum title. Not a name.
TeraByte wrote:Sorry if it seems silly, but I'm new to PB and am just trying to make sure I'm not coding it inefficiently.
At this stage of your learning I would suggest you focus more on 'correct result' than 'efficient'.

It is highly unlikely that what you are trying to do (bitwise operation on a float) is what you actually want to do.
TeraByte
User
User
Posts: 40
Joined: Wed May 09, 2012 12:40 am

Re: Assigning Bitwise AND to Double

Post by TeraByte »

Yikes, a newbie mistake. :oops:
Post Reply