Serializable
public final class RationalNumber extends Number
dividend/divisor
with dividend
and divisor
being integer numbers.
BigInteger
to represent 'dividend' and
'divisor'.Modifier and Type | Field | Description |
---|---|---|
static char |
DIVISION_CHARACTER |
The default
DIVISION_CHARACTER is ÷ which (on Windows) can by typed
using Alt+ 246. |
static RationalNumber |
ONE |
|
static RationalNumber |
ZERO |
Modifier and Type | Method | Description |
---|---|---|
RationalNumber |
abs() |
Returns a
RationalNumber whose value is the absolute value of this
RationalNumber . |
RationalNumber |
add(RationalNumber that) |
Returns a new instance of
RationalNumber representing the addition
this + that . |
BigDecimal |
bigDecimalValue() |
|
int |
compareTo(RationalNumber that) |
Compares two
RationalNumber values numerically. |
RationalNumber |
divide(RationalNumber that) |
Returns a new instance of
RationalNumber representing the division
this / that . |
double |
doubleValue() |
|
boolean |
equals(Object x) |
Compares this RationalNumber with the specified Object for equality.
|
float |
floatValue() |
|
BigInteger |
getDividend() |
For a non-negative rational number, returns a non-negative dividend.
|
BigInteger |
getDivisor() |
By convention, returns a non-negative divisor.
|
int |
hashCode() |
|
int |
intValue() |
|
boolean |
isInteger() |
|
long |
longValue() |
|
RationalNumber |
multiply(RationalNumber that) |
Returns a new instance of
RationalNumber representing the
multiplication this * that . |
RationalNumber |
negate() |
Returns a new instance of
RationalNumber representing the negation of
this . |
static RationalNumber |
of(double number) |
Returns a
RationalNumber that represents the given double precision
number , with an accuracy equivalent to BigDecimal.valueOf(double) . |
static RationalNumber |
of(long dividend,
long divisor) |
Returns a
RationalNumber that represents the division
dividend/divisor . |
static RationalNumber |
of(BigDecimal decimalValue) |
Returns a
RationalNumber that represents the given BigDecimal decimalValue. |
static RationalNumber |
of(BigInteger dividend,
BigInteger divisor) |
Returns a
RationalNumber that represents the division
dividend/divisor . |
static RationalNumber |
ofInteger(long number) |
Returns a
RationalNumber with divisor ONE. |
static RationalNumber |
ofInteger(BigInteger number) |
Returns a
RationalNumber with divisor ONE. |
RationalNumber |
pow(int exponent) |
Returns a new instance of
RationalNumber representing the reciprocal
of this . |
RationalNumber |
reciprocal() |
Returns a new instance of
RationalNumber representing the reciprocal
of this . |
int |
signum() |
|
RationalNumber |
subtract(RationalNumber that) |
Returns a new instance of
RationalNumber representing the subtraction
this - that . |
String |
toRationalString() |
Returns a string representation of this
RationalNumber , using
fractional notation, eg. |
String |
toRationalString(char divisionCharacter) |
Returns a string representation of this
RationalNumber , using
fractional notation, eg. |
String |
toString() |
byteValue, shortValue
public static char DIVISION_CHARACTER
DIVISION_CHARACTER
is ÷ which (on Windows) can by typed
using Alt+ 246.
Note: Number parsing will fail if this is a white-space character.
public static final RationalNumber ZERO
public static final RationalNumber ONE
public static RationalNumber ofInteger(long number)
RationalNumber
with divisor ONE. In other words,
returns a RationalNumber
that represents given integer
number
.number
- NullPointerException
- - if number is null
public static RationalNumber ofInteger(BigInteger number)
RationalNumber
with divisor ONE. In other words,
returns a RationalNumber
that represents given integer
number
.number
- NullPointerException
- - if number is null
public static RationalNumber of(long dividend, long divisor)
RationalNumber
that represents the division
dividend/divisor
.dividend
- divisor
- IllegalArgumentException
- if divisor = 0
public static RationalNumber of(double number)
RationalNumber
that represents the given double precision
number
, with an accuracy equivalent to BigDecimal.valueOf(double)
.number
- public static RationalNumber of(BigDecimal decimalValue)
RationalNumber
that represents the given BigDecimal decimalValue.decimalValue
- public static RationalNumber of(BigInteger dividend, BigInteger divisor)
RationalNumber
that represents the division
dividend/divisor
.dividend
- divisor
- IllegalArgumentException
- if divisor = 0
NullPointerException
- - if dividend is null
or divisor is
null
public BigInteger getDividend()
RationalNumber
,
whereas @link getDivisor()
does not and is always non-negative.public BigInteger getDivisor()
public boolean isInteger()
RationalNumber
represents an integer numberpublic int signum()
RationalNumber
: -1, 0 or +1public BigDecimal bigDecimalValue()
RationalNumber
converted to BigDecimal
representationpublic RationalNumber add(RationalNumber that)
RationalNumber
representing the addition
this + that
.that
- public RationalNumber subtract(RationalNumber that)
RationalNumber
representing the subtraction
this - that
.that
- public RationalNumber multiply(RationalNumber that)
RationalNumber
representing the
multiplication this * that
.that
- public RationalNumber divide(RationalNumber that)
RationalNumber
representing the division
this / that
.that
- public RationalNumber negate()
RationalNumber
representing the negation of
this
.public RationalNumber reciprocal()
RationalNumber
representing the reciprocal
of this
.public RationalNumber pow(int exponent)
RationalNumber
representing the reciprocal
of this
.exponent
- public RationalNumber abs()
RationalNumber
whose value is the absolute value of this
RationalNumber
.abs(this)
public int compareTo(RationalNumber that)
RationalNumber
values numerically.that
- 0
if this
equals (numerically)
that
; a value less than 0
if this < that
; and
a value greater than 0
if this > that
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public String toRationalString()
RationalNumber
, using
fractional notation, eg. 5÷3
or -5÷3
.RationalNumber
, using
fractional notation.public String toRationalString(char divisionCharacter)
RationalNumber
, using
fractional notation, eg. 5÷3
or -5÷3
.divisionCharacter
- the character to use instead of the default ÷
RationalNumber
, using
fractional notation.Copyright © 2005–2020 Units of Measurement project. All rights reserved.