public final class HackersDelight
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static long |
BUT_EXPONENT_BIT_MASK
Bit mask to isolate all but the sign bit of a long or double.
|
static long |
BUT_SIGN_BIT_MASK_L
Bit mask to isolate all but the sign bit of a long or double.
|
static long |
EXPONENT_BITS_MASK
Bit mask to isolate the sign bit of a long or double.
|
static int |
SIGN_BIT_MASK_I
Bit mask to isolate the sign bit of an int or a float.
|
static long |
SIGN_BIT_MASK_L
Bit mask to isolate the sign bit of a long or double.
|
Constructor and Description |
---|
HackersDelight() |
Modifier and Type | Method and Description |
---|---|
static double |
abs(double x) |
static int |
abs(int x) |
static long |
abs(long x) |
static int |
doz(int x,
int y)
Doz stands for "difference or zero" (see p. 37 of HD).
|
static long |
doz(long x,
long y)
Doz stands for "difference or zero" (see p. 37 of HD).
|
static int |
floorInt(double a) |
static int |
floorIntN(double a) |
static int |
floorIntP(double a) |
static long |
floorLong(double a) |
static long |
floorLongN(double a) |
static long |
floorLongP(double a) |
long |
flp2(long x) |
static double |
fromBits(long doubleBits) |
static double |
halfOf(double x) |
static boolean |
isPowOf2(int x)
Determines if an integer is a power of two, exact solution.
|
static boolean |
isPowOf2Fast(int x)
Determines if an integer is a power of two, including 0.
|
static void |
main(java.lang.String[] args) |
static int |
max(int x,
int y)
Returns the greater of two values.
|
static long |
max(long x,
long y)
Returns the greater of two values.
|
static int |
min(int x,
int y)
Returns the smaller of two values.
|
static long |
min(long x,
long y)
Returns the smaller of two values.
|
static int |
nlz(int x)
Branch-free version of
Integer.numberOfLeadingZeros(int) (also taken from the HD). |
static long |
toBits(double x) |
public static final int SIGN_BIT_MASK_I
public static final long SIGN_BIT_MASK_L
public static final long BUT_SIGN_BIT_MASK_L
public static final long EXPONENT_BITS_MASK
public static final long BUT_EXPONENT_BIT_MASK
public static boolean isPowOf2(int x)
x
- the argumentpublic static boolean isPowOf2Fast(int x)
x
- the argumentisPowOf2(int)
.public long flp2(long x)
public static double halfOf(double x)
public static long toBits(double x)
public static double fromBits(long doubleBits)
public static int abs(int x)
public static long abs(long x)
public static double abs(double x)
public static int floorIntP(double a)
public static int floorIntN(double a)
public static int floorInt(double a)
public static long floorLongP(double a)
public static long floorLongN(double a)
public static long floorLong(double a)
public static int doz(int x, int y)
0
if x > y
, else returns x - y
,
so it can be replace by (x - y) > 0 ? x - y : 0
x
- an argumenty
- another argument0
if x > y
, else returns x - y
.public static long doz(long x, long y)
0
if x > y
, else returns x - y
,
so it can be replace by (x - y) > 0 ? x - y : 0
x
- an argumenty
- another argument0
if x > y
, else returns x - y
.public static int min(int x, int y)
x
- an argumenty
- another argumentpublic static long min(long x, long y)
x
- an argumenty
- another argumentpublic static int max(int x, int y)
x
- an argumenty
- another argumentpublic static long max(long x, long y)
x
- an argumenty
- another argumentpublic static int nlz(int x)
Integer.numberOfLeadingZeros(int)
(also taken from the HD).
See "Number of leading zeros, branch-free binary search" in HD.x
- the argumentpublic static void main(java.lang.String[] args)
Copyright © 2018 F.-X. Pineau, CDS, Observatoire Astronomique de Strasbourg, Universite de Strasbourg, CNRS. All Rights Reserved.