cern.jet.math.tlong
Class LongFunctions
- java.lang.Object
-
- cern.jet.math.tlong.LongFunctions
-
public class LongFunctions extends java.lang.ObjectLong Function objects to be passed to generic methods. Same asDoubleFunctionsexcept operating on longs.For aliasing see
longFunctions.
-
-
Field Summary
Fields Modifier and Type Field and Description static LongFunctionabsFunction that returns Math.abs(a) == (a < 0) ? -a : a.static LongLongFunctionandFunction that returns a & b.static LongLongFunctioncompareFunction that returns a < b ? -1 : a > b ? 1 : 0.static LongFunctiondecFunction that returns a--.static LongLongFunctiondivFunction that returns a / b.static LongLongFunctiondivNegFunction that returns -(a / b).static LongLongFunctionequalsFunction that returns a == b ? 1 : 0.static LongFunctionfactorialFunction that returns (long) Arithmetic.factorial(a).static LongFunctionidentityFunction that returns its argument.static LongFunctionincFunction that returns a++.static LongLongProcedureisEqualFunction that returns a == b.static LongLongProcedureisGreaterFunction that returns a > b.static LongLongProcedureisLessFunction that returns a < b.static LongFunctionslongFunctionsLittle trick to allow for "aliasing", that is, renaming this class.static LongLongFunctionmaxFunction that returns Math.max(a,b).static LongLongFunctionminFunction that returns Math.min(a,b).static LongLongFunctionminusFunction that returns a - b.static LongLongFunctionmodFunction that returns a % b.static LongLongFunctionmultFunction that returns a * b.static LongLongFunctionmultNegFunction that returns -(a * b).static LongLongFunctionmultSquareFunction that returns a * b^2.static LongFunctionnegFunction that returns -a.static LongFunctionnotFunction that returns ~a.static LongLongFunctionorFunction that returns a | b.static LongLongFunctionplusFunction that returns a + b.static LongLongFunctionplusAbsFunction that returns Math.abs(a) + Math.abs(b).static LongLongFunctionpowFunction that returns (long) Math.pow(a,b).static LongLongFunctionshiftLeftFunction that returns a << b.static LongLongFunctionshiftRightSignedFunction that returns a >> b.static LongLongFunctionshiftRightUnsignedFunction that returns a >>> b.static LongFunctionsignFunction that returns a < 0 ? -1 : a > 0 ? 1 : 0.static LongFunctionsquareFunction that returns a * a.static LongLongFunctionxorFunction that returns a ^ b.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static LongFunctionand(long b)Constructs a function that returns a & b.static LongFunctionbetween(long from, long to)Constructs a function that returns (from<=a && a<=to) ? 1 : 0.static LongFunctionbindArg1(LongLongFunction function, long c)Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant c.static LongFunctionbindArg2(LongLongFunction function, long c)Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant c.static LongFunctionchain(LongFunction g, LongFunction h)Constructs the function g( h(a) ).static LongLongFunctionchain(LongFunction g, LongLongFunction h)Constructs the function g( h(a,b) ).static LongLongFunctionchain(LongLongFunction f, LongFunction g, LongFunction h)Constructs the function f( g(a), h(b) ).static LongFunctioncompare(long b)Constructs a function that returns a < b ? -1 : a > b ? 1 : 0.static LongFunctionconstant(long c)Constructs a function that returns the constant c.static LongFunctiondiv(long b)Constructs a function that returns a / b.static LongFunctionequals(long b)Constructs a function that returns a == b ? 1 : 0.static LongProcedureisBetween(long from, long to)Constructs a function that returns from<=a && a<=to.static LongProcedureisEqual(long b)Constructs a function that returns a == b.static LongProcedureisGreater(long b)Constructs a function that returns a > b.static LongProcedureisLess(long b)Constructs a function that returns a < b.static LongFunctionmax(long b)Constructs a function that returns Math.max(a,b).static LongFunctionmin(long b)Constructs a function that returns Math.min(a,b).static LongFunctionminus(long b)Constructs a function that returns a - b.static LongLongFunctionminusMult(long constant)Constructs a function that returns a - b*constant.static LongFunctionmod(long b)Constructs a function that returns a % b.static LongFunctionmult(long b)Constructs a function that returns a * b.static LongLongFunctionmultSecond(long constant)Constructs a function that returns b*constant.static LongFunctionor(long b)Constructs a function that returns a | b.static LongFunctionplus(long b)Constructs a function that returns a + b.static LongLongFunctionplusMultFirst(long constant)Constructs a function that returns a * constant + b.static LongLongFunctionplusMultSecond(long constant)Constructs a function that returns a + b*constant.static LongFunctionpow(long b)Constructs a function that returns (long) Math.pow(a,b).static LongFunctionrandom()Constructs a function that returns a 32 bit uniformly distributed random number in the closed longerval [Long.MIN_VALUE,Long.MAX_VALUE] (including Long.MIN_VALUE and Long.MAX_VALUE).static LongFunctionshiftLeft(long b)Constructs a function that returns a << b.static LongFunctionshiftRightSigned(long b)Constructs a function that returns a >> b.static LongFunctionshiftRightUnsigned(long b)Constructs a function that returns a >>> b.static LongLongFunctionswapArgs(LongLongFunction function)Constructs a function that returns function.apply(b,a), i.e.static LongFunctionxor(long b)Constructs a function that returns a | b.
-
-
-
Field Detail
-
longFunctions
public static final LongFunctions longFunctions
Little trick to allow for "aliasing", that is, renaming this class. Writing code likeLongFunctions.chain(LongFunctions.plus,LongFunctions.mult(3),LongFunctions.chain(LongFunctions.square,LongFunctions.div(2)));
is a bit awkward, to say the least. Using the aliasing you can instead write
LongFunctions F = LongFunctions.longFunctions;
F.chain(F.plus,F.mult(3),F.chain(F.square,F.div(2)));
-
abs
public static final LongFunction abs
Function that returns Math.abs(a) == (a < 0) ? -a : a.
-
dec
public static final LongFunction dec
Function that returns a--.
-
factorial
public static final LongFunction factorial
Function that returns (long) Arithmetic.factorial(a).
-
identity
public static final LongFunction identity
Function that returns its argument.
-
inc
public static final LongFunction inc
Function that returns a++.
-
neg
public static final LongFunction neg
Function that returns -a.
-
not
public static final LongFunction not
Function that returns ~a.
-
sign
public static final LongFunction sign
Function that returns a < 0 ? -1 : a > 0 ? 1 : 0.
-
square
public static final LongFunction square
Function that returns a * a.
-
and
public static final LongLongFunction and
Function that returns a & b.
-
compare
public static final LongLongFunction compare
Function that returns a < b ? -1 : a > b ? 1 : 0.
-
div
public static final LongLongFunction div
Function that returns a / b.
-
divNeg
public static final LongLongFunction divNeg
Function that returns -(a / b).
-
equals
public static final LongLongFunction equals
Function that returns a == b ? 1 : 0.
-
isEqual
public static final LongLongProcedure isEqual
Function that returns a == b.
-
isLess
public static final LongLongProcedure isLess
Function that returns a < b.
-
isGreater
public static final LongLongProcedure isGreater
Function that returns a > b.
-
max
public static final LongLongFunction max
Function that returns Math.max(a,b).
-
min
public static final LongLongFunction min
Function that returns Math.min(a,b).
-
minus
public static final LongLongFunction minus
Function that returns a - b.
-
mod
public static final LongLongFunction mod
Function that returns a % b.
-
mult
public static final LongLongFunction mult
Function that returns a * b.
-
multNeg
public static final LongLongFunction multNeg
Function that returns -(a * b).
-
multSquare
public static final LongLongFunction multSquare
Function that returns a * b^2.
-
or
public static final LongLongFunction or
Function that returns a | b.
-
plus
public static final LongLongFunction plus
Function that returns a + b.
-
plusAbs
public static final LongLongFunction plusAbs
Function that returns Math.abs(a) + Math.abs(b).
-
pow
public static final LongLongFunction pow
Function that returns (long) Math.pow(a,b).
-
shiftLeft
public static final LongLongFunction shiftLeft
Function that returns a << b.
-
shiftRightSigned
public static final LongLongFunction shiftRightSigned
Function that returns a >> b.
-
shiftRightUnsigned
public static final LongLongFunction shiftRightUnsigned
Function that returns a >>> b.
-
xor
public static final LongLongFunction xor
Function that returns a ^ b.
-
-
Method Detail
-
and
public static LongFunction and(long b)
Constructs a function that returns a & b. a is a variable, b is fixed.
-
between
public static LongFunction between(long from, long to)
Constructs a function that returns (from<=a && a<=to) ? 1 : 0. a is a variable, from and to are fixed.
-
bindArg1
public static LongFunction bindArg1(LongLongFunction function, long c)
Constructs a unary function from a binary function with the first operand (argument) fixed to the given constant c. The second operand is variable (free).- Parameters:
function- a binary function taking operands in the form function.apply(c,var).- Returns:
- the unary function function(c,var).
-
bindArg2
public static LongFunction bindArg2(LongLongFunction function, long c)
Constructs a unary function from a binary function with the second operand (argument) fixed to the given constant c. The first operand is variable (free).- Parameters:
function- a binary function taking operands in the form function.apply(var,c).- Returns:
- the unary function function(var,c).
-
chain
public static LongFunction chain(LongFunction g, LongFunction h)
Constructs the function g( h(a) ).- Parameters:
g- a unary function.h- a unary function.- Returns:
- the unary function g( h(a) ).
-
chain
public static LongLongFunction chain(LongFunction g, LongLongFunction h)
Constructs the function g( h(a,b) ).- Parameters:
g- a unary function.h- a binary function.- Returns:
- the unary function g( h(a,b) ).
-
chain
public static LongLongFunction chain(LongLongFunction f, LongFunction g, LongFunction h)
Constructs the function f( g(a), h(b) ).- Parameters:
f- a binary function.g- a unary function.h- a unary function.- Returns:
- the binary function f( g(a), h(b) ).
-
compare
public static LongFunction compare(long b)
Constructs a function that returns a < b ? -1 : a > b ? 1 : 0. a is a variable, b is fixed.
-
constant
public static LongFunction constant(long c)
Constructs a function that returns the constant c.
-
div
public static LongFunction div(long b)
Constructs a function that returns a / b. a is a variable, b is fixed.
-
equals
public static LongFunction equals(long b)
Constructs a function that returns a == b ? 1 : 0. a is a variable, b is fixed.
-
isBetween
public static LongProcedure isBetween(long from, long to)
Constructs a function that returns from<=a && a<=to. a is a variable, from and to are fixed.
-
isEqual
public static LongProcedure isEqual(long b)
Constructs a function that returns a == b. a is a variable, b is fixed.
-
isGreater
public static LongProcedure isGreater(long b)
Constructs a function that returns a > b. a is a variable, b is fixed.
-
isLess
public static LongProcedure isLess(long b)
Constructs a function that returns a < b. a is a variable, b is fixed.
-
max
public static LongFunction max(long b)
Constructs a function that returns Math.max(a,b). a is a variable, b is fixed.
-
min
public static LongFunction min(long b)
Constructs a function that returns Math.min(a,b). a is a variable, b is fixed.
-
minus
public static LongFunction minus(long b)
Constructs a function that returns a - b. a is a variable, b is fixed.
-
minusMult
public static LongLongFunction minusMult(long constant)
Constructs a function that returns a - b*constant. a and b are variables, constant is fixed.
-
mod
public static LongFunction mod(long b)
Constructs a function that returns a % b. a is a variable, b is fixed.
-
mult
public static LongFunction mult(long b)
Constructs a function that returns a * b. a is a variable, b is fixed.
-
or
public static LongFunction or(long b)
Constructs a function that returns a | b. a is a variable, b is fixed.
-
plus
public static LongFunction plus(long b)
Constructs a function that returns a + b. a is a variable, b is fixed.
-
multSecond
public static LongLongFunction multSecond(long constant)
Constructs a function that returns b*constant.
-
pow
public static LongFunction pow(long b)
Constructs a function that returns (long) Math.pow(a,b). a is a variable, b is fixed.
-
plusMultSecond
public static LongLongFunction plusMultSecond(long constant)
Constructs a function that returns a + b*constant. a and b are variables, constant is fixed.
-
plusMultFirst
public static LongLongFunction plusMultFirst(long constant)
Constructs a function that returns a * constant + b. a and b are variables, constant is fixed.
-
random
public static LongFunction random()
Constructs a function that returns a 32 bit uniformly distributed random number in the closed longerval [Long.MIN_VALUE,Long.MAX_VALUE] (including Long.MIN_VALUE and Long.MAX_VALUE). Currently the engine isDoubleMersenneTwisterand is seeded with the current time.Note that any random engine derived from
DoubleRandomEngineand any random distribution derived fromAbstractDoubleDistributionare function objects, because they implement the proper longerfaces. Thus, if you are not happy with the default, just pass your favourite random generator to function evaluating methods.
-
shiftLeft
public static LongFunction shiftLeft(long b)
Constructs a function that returns a << b. a is a variable, b is fixed.
-
shiftRightSigned
public static LongFunction shiftRightSigned(long b)
Constructs a function that returns a >> b. a is a variable, b is fixed.
-
shiftRightUnsigned
public static LongFunction shiftRightUnsigned(long b)
Constructs a function that returns a >>> b. a is a variable, b is fixed.
-
swapArgs
public static LongLongFunction swapArgs(LongLongFunction function)
Constructs a function that returns function.apply(b,a), i.e. applies the function with the first operand as second operand and the second operand as first operand.- Parameters:
function- a function taking operands in the form function.apply(a,b).- Returns:
- the binary function function(b,a).
-
xor
public static LongFunction xor(long b)
Constructs a function that returns a | b. a is a variable, b is fixed.
-
-
DMelt 3.0 © DataMelt by jWork.ORG