docs: FastMath
This commit is contained in:
parent
ebaffdb123
commit
e71f866b14
@ -18,43 +18,42 @@ package org.oscim.utils;
|
||||
|
||||
public class FastMath {
|
||||
/**
|
||||
* from http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
|
||||
* Integer version of log2(x)
|
||||
*
|
||||
* @param v
|
||||
* ...
|
||||
* @return ...
|
||||
* from http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
|
||||
*/
|
||||
public static int log2(int v) {
|
||||
public static int log2(int x) {
|
||||
|
||||
int r = 0; // result of log2(v) will go here
|
||||
|
||||
if ((v & 0xFFFF0000) != 0) {
|
||||
v >>= 16;
|
||||
if ((x & 0xFFFF0000) != 0) {
|
||||
x >>= 16;
|
||||
r |= 16;
|
||||
}
|
||||
if ((v & 0xFF00) != 0) {
|
||||
v >>= 8;
|
||||
if ((x & 0xFF00) != 0) {
|
||||
x >>= 8;
|
||||
r |= 8;
|
||||
}
|
||||
if ((v & 0xF0) != 0) {
|
||||
v >>= 4;
|
||||
if ((x & 0xF0) != 0) {
|
||||
x >>= 4;
|
||||
r |= 4;
|
||||
}
|
||||
if ((v & 0xC) != 0) {
|
||||
v >>= 2;
|
||||
if ((x & 0xC) != 0) {
|
||||
x >>= 2;
|
||||
r |= 2;
|
||||
}
|
||||
if ((v & 0x2) != 0) {
|
||||
if ((x & 0x2) != 0) {
|
||||
r |= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static float pow(int pow) {
|
||||
if (pow == 0)
|
||||
/** Integer version of 2^x */
|
||||
public static float pow(int x) {
|
||||
if (x == 0)
|
||||
return 1;
|
||||
|
||||
return (pow > 0 ? (1 << pow) : (1.0f / (1 << -pow)));
|
||||
return (x > 0 ? (1 << x) : (1.0f / (1 << -x)));
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max) {
|
||||
@ -87,12 +86,12 @@ public class FastMath {
|
||||
return a2 < a1 ? a1 : a2;
|
||||
}
|
||||
|
||||
// test if any absolute value is greater than 'cmp'
|
||||
/** test if any absolute value is greater than 'cmp' */
|
||||
public static boolean absMaxCmp(float value1, float value2, float cmp) {
|
||||
return value1 < -cmp || value1 > cmp || value2 < -cmp || value2 > cmp;
|
||||
}
|
||||
|
||||
// test if any absolute value is greater than 'cmp'
|
||||
/** test if any absolute value is greater than 'cmp' */
|
||||
public static boolean absMaxCmp(int value1, int value2, int cmp) {
|
||||
return value1 < -cmp || value1 > cmp || value2 < -cmp || value2 > cmp;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user