Page 1 of 1
Assigning Bitwise AND to Double
Posted: Thu May 31, 2012 10:50 pm
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?
Re: Assigning Bitwise AND to Double
Posted: Fri Jun 01, 2012 1:56 am
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)
Re: Assigning Bitwise AND to Double
Posted: Fri Jun 01, 2012 4:47 pm
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.
Re: Assigning Bitwise AND to Double
Posted: Sun Jun 03, 2012 8:43 am
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.
Re: Assigning Bitwise AND to Double
Posted: Sun Jun 03, 2012 7:35 pm
by TeraByte
Yikes, a newbie mistake.
