I’ve been indirectly proposed by @normen to contribute to jMonkey. I have my own math library for jMonkey projects, so I thought you could find it useful.

Are you interested in more utility methods for FastMath?

Here are some methods I use :

```
public static final int SIGN_BIT_MASK = 0x80000000;
public static final int BIT_COUNT_EXCLUDING_SIGN = 31;
/**
* Indexifies a normal that is either -1, 0 or 1. In other words, negative numbers become 0 and positive numbers, including 0, become 1.
*
* @param normal A normal that should be either -1, 0 or 1. If it's smaller than -1, it will treated as -1. If it's bigger than 1, it will be treated as 1.
*
* @return An index that is either 0 (negative) or 1 (null or positive normal).
*/
public static int indexifyNormalZeroPositive(int normal) {
return ~((normal | 1) - 1 >> BIT_COUNT_EXCLUDING_SIGN) & 1;
}
/**
* Indexifies a normal that is either -1, 0 or 1. In other words, negative numbers become 0, positive numbers become 1 and zero is left unchanged.
*
* @param normal A normal that should be either -1, 0 or 1. If it's smaller than -1, it will treated as -1. If it's bigger than 1, it will be treated as 1.
*
* @return An index that is either 0 (negative and null normal) or 1 (positive normal).
*/
public static int indexifyNormal(int normal) {
return ~(normal - 1 >> BIT_COUNT_EXCLUDING_SIGN) & 1;
}
/**
* Gets the sign of the supplied number. The method being "zero position" means that the sign of zero is 1.
*
* @param number The number to get the sign from.
*
* @return The number's sign.
*/
public static int getSignZeroPositive(int number) {
return (number & SIGN_BIT_MASK) >> BIT_COUNT_EXCLUDING_SIGN | 1;
}
/**
* Gets the negative sign of the supplied number. So, in other words, if the number is negative, -1 is returned but if the number is positive or zero, then zero is returned.
*
* @param number The number to get its negative sign.
*
* @return -1 if the number is negative, 0 otherwise.
*/
public static int getNegativeSign(int number) {
return number >> BIT_COUNT_EXCLUDING_SIGN;
}
/**
* Gets the negative sign of the supplied number. So, in other words, if the number is negative, -1 is returned but if the number is positive or zero, then zero is returned. It
* does not check if the parameter is NaN.
*
* @param number The number to get its negative sign.
*
* @return -1 if the number is negative, 0 otherwise.
*/
public static int getNegativeSign(float number) {
return Float.floatToRawIntBits(number) >> BIT_COUNT_EXCLUDING_SIGN;
}
/**
* Checks if the supplied number is a power of 2.
*
* @param number The number to check against.
*
* @return True if the given number is a power of 2, false otherwise.
*/
public static boolean isPowerOfTwo(int number) {
return number > 0 && ((number & (number - 1)) == 0);
}
/**
* Cycles between the inclusive minimum and the exclusive maximum.
*
* @param min The inclusive minimum.
* @param exclusiveMax The exclusive maximum.
* @param index The index to use to cycle.
*
* @return The cycle index.
*/
public static int cycle(int min, int exclusiveMax, int index) {
return index >= exclusiveMax ? min : (index < min ? exclusiveMax - 1 : index);
}
```