Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

function to get float sign bit

  • Loading branch information...
commit 378d9bafdb39df244a683c700f26092a729bb093 1 parent d4f1dd7
@mikera authored
View
7 src/main/java/mikera/util/Bits.java
@@ -429,6 +429,13 @@ public static String toBinaryString(int a) {
}
/**
+ * Gets the sign bit of a floating point value
+ */
+ public static int signBit(float f) {
+ return (Float.floatToIntBits(f)>>>31);
+ }
+
+ /**
* Creates a long value out of high and low integer components
*
* @param high
View
7 src/test/java/mikera/util/TestBits.java
@@ -150,6 +150,13 @@
assertEquals(1,Bits.parity(0x0100F000));
}
+ @Test public void testFloatSign() {
+ assertEquals(0,Bits.signBit(1.0f));
+ assertEquals(1,Bits.signBit(-1.0f));
+ assertEquals(0,Bits.signBit(Float.POSITIVE_INFINITY));
+ assertEquals(1,Bits.signBit(Float.NEGATIVE_INFINITY));
+ }
+
@Test public void testRoll() {
assertEquals(0xFFF0000F,Bits.rollLeft(0x0000FFFF,20));
assertEquals(0xFFF0000F,Bits.rollLeft(0x0000FFFF,52));
Please sign in to comment.
Something went wrong with that request. Please try again.