Package fj.data
Class Natural
java.lang.Object
java.lang.Number
fj.data.Natural
- All Implemented Interfaces:
Serializable
Represents a natural number (zero, one, two, etc.)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionA function that adds two natural numbers.static final F
<Natural, BigInteger> A function that returns the BigInteger value of a given Natural.A function that divides its second argument by its first.A function that divides its second argument by its first, yielding both the quotient and the remainder.static final F
<BigInteger, Option<Natural>> A function that returns the natural number equal to a given BigIntegerA function that yields the remainder of division of its second argument by its first.A function that multiplies a natural number by another.static final Natural
The natural number oneprivate static final long
A function that subtracts its first argument from its second.private final BigInteger
static final Natural
The natural number zero -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd two natural numbers together.Return the BigInteger value of this natural number.Divide a natural number by another.Divide a natural number by another yielding both the quotient and the remainder.double
Return the double value of this natural number.boolean
float
Return the float value of this natural number.int
hashCode()
int
intValue()
Return the int value of this natural number.long
Return the long value of this natural number.Take the remainder of a natural number division.Multiply a natural number by another.natural
(long i) Returns the natural number equal to the given longReturns the natural number equal to the given BigIntegerpred()
Return the predecessor of this natural numberpred_()
First-class predecessor function.static Natural
Takes the product of a list of natural numbers.static Natural
Takes the product of a stream of natural numbers.Subtract a natural number from another.succ()
Return the successor of this natural numbersucc_()
First-class successor function.static Natural
Sums a list of natural numbers.static Natural
Sums a stream of natural numbers.toString()
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
value
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
fromBigInt
A function that returns the natural number equal to a given BigInteger -
ZERO
The natural number zero -
ONE
The natural number one -
add
A function that adds two natural numbers. -
subtract
A function that subtracts its first argument from its second. -
multiply
A function that multiplies a natural number by another. -
divide
A function that divides its second argument by its first. -
mod
A function that yields the remainder of division of its second argument by its first. -
divmod
A function that divides its second argument by its first, yielding both the quotient and the remainder. -
bigIntegerValue
A function that returns the BigInteger value of a given Natural.
-
-
Constructor Details
-
Natural
-
-
Method Details
-
natural
Returns the natural number equal to the given BigInteger- Parameters:
i
- A given BigInteger- Returns:
- An optional natural number, or none if the given BigInteger is less than zero.
-
natural
Returns the natural number equal to the given long- Parameters:
i
- A given long- Returns:
- An optional natural number, or none if the given long is less than zero.
-
succ
Return the successor of this natural number- Returns:
- the successor of this natural number
-
succ_
First-class successor function.- Returns:
- A function that returns the successor of a given natural number.
-
pred
Return the predecessor of this natural number- Returns:
- the predecessor of this natural number
-
pred_
First-class predecessor function.- Returns:
- A function that returns the predecessor of a given natural number, or None if it's zero.
-
add
Add two natural numbers together.- Parameters:
n
- A natural number to add to this one.- Returns:
- the sum of the two natural numbers.
-
subtract
Subtract a natural number from another.- Parameters:
n
- A natural number to subtract from this one.- Returns:
- The difference between the two numbers, if this number is larger than the given one. Otherwise none.
-
multiply
Multiply a natural number by another.- Parameters:
n
- A natural number to multiply by this one.- Returns:
- The product of the two numbers.
-
divide
Divide a natural number by another.- Parameters:
n
- A natural number to divide this one by.- Returns:
- The quotient of this number and the highest number, less than or equal to the given number, that divides this number.
-
mod
Take the remainder of a natural number division.- Parameters:
n
- A natural number to divide this one by.- Returns:
- The remainder of division of this number by the given number.
-
divmod
Divide a natural number by another yielding both the quotient and the remainder.- Parameters:
n
- A natural number to divide this one by.- Returns:
- The quotient and the remainder, in that order.
-
bigIntegerValue
Return the BigInteger value of this natural number.- Returns:
- the BigInteger value of this natural number.
-
longValue
public long longValue()Return the long value of this natural number. -
floatValue
public float floatValue()Return the float value of this natural number.- Specified by:
floatValue
in classNumber
- Returns:
- the float value of this natural number.
-
doubleValue
public double doubleValue()Return the double value of this natural number.- Specified by:
doubleValue
in classNumber
- Returns:
- the double value of this natural number.
-
intValue
public int intValue()Return the int value of this natural number. -
sum
Sums a stream of natural numbers.- Parameters:
ns
- A stream of natural numbers.- Returns:
- The sum of all the natural numbers in the stream.
-
product
Takes the product of a stream of natural numbers.- Parameters:
ns
- A stream of natural numbers.- Returns:
- The product of all the natural numbers in the stream.
-
sum
Sums a list of natural numbers.- Parameters:
ns
- A list of natural numbers.- Returns:
- The sum of all the natural numbers in the list.
-
product
Takes the product of a list of natural numbers.- Parameters:
ns
- A list of natural numbers.- Returns:
- The product of all the natural numbers in the list.
-
hashCode
public int hashCode() -
equals
-
toString
-