Can you AND and OR Doubles in Xojo?

I’m porting some Java code where there is a lot of bit masking.

In Java, you can binary AND and OR between two Double values but in Xojo the compiler complains that they are Integer operations. Is there a way to do this in Xojo?

The code I’m trying to port is part of Java’s standard library: Double.copySign(). The original Java code is:

public static double copySign(double magnitude, double sign) {
  return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) &
     (DoubleConsts.SIGN_BIT_MASK)) |
    (Double.doubleToRawLongBits(magnitude) &
    (DoubleConsts.EXP_BIT_MASK |
    DoubleConsts.SIGNIF_BIT_MASK)));
}

As you can see, Java lets you mask off floating point numbers but Xojo won’t. Are there ill-effects in this case from casting a Double to an Integer and then bit-masking? The point of this method is to copy the sign from the second argument to the first argument.

My current implementation is this:

Return If(sign < 0, -Abs(magnitude), Abs(magnitude))

I’m just curious because the maths library I’m porting has lots of floating point bit-masking which will be harder to deal with…

use a memoryblock, put the double in there, pull it out as a Int64 or Uint64, do the or and reverse this

1 Like

Yep - that’s the solution I think. Thanks