Class Real
- All Implemented Interfaces:
Serializable, Comparable<Real>, AbelianGroup<Real>, AbelianMonoid<Real>, Group<Real>, Magma<Real>, Monoid<Real>, Field<Real>, FieldElement<Real>, Ring<Real>, RingElement<Real>, Semiring<Real>, Set<Real>
- Direct Known Subclasses:
NativeRealBig, RealBig, RealDouble, RealFloat
Real numbers form a Field under addition and multiplication. This class provides a smart factory that chooses the backing implementation
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Realabs()abstract Realacos()Returns the arccosine of this number.abstract Realacosh()Returns the inverse hyperbolic cosine of this number.abstract RealReturns the sum of this element and another.Returns the sum of two elements (additive notation).abstract Realasin()Returns the arcsine of this number.abstract Realasinh()Returns the inverse hyperbolic sine of this number.abstract Realatan()Returns the arctangent of this number.abstract RealReturns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).abstract Realatanh()Returns the inverse hyperbolic tangent of this number.abstract BigDecimalabstract Realcbrt()Returns the cube root of this number.abstract Realceil()Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.intReturns the characteristic of this field.abstract intbooleanTests whether this set contains the specified element.abstract Realcos()Returns the cosine of this number (in radians).abstract Realcosh()Returns the hyperbolic cosine of this number.Returns a human-readable description of this set.abstract RealReturns this element divided by another.abstract doublestatic RealeE()The real number Eabstract booleanabstract Realexp()Returns e raised to this number.floatabstract Realfloor()Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.Returns the ring structure for real numbers.static RealhalfPiE()À/2 - quarter turn in radiansabstract inthashCode()abstract RealReturns sqrt(x^2 + y^2) without intermediate overflow or underflow.intintValue()abstract Realinverse()Returns the multiplicative inverse of this element.Returns the multiplicative inverse of a non-zero element.booleanisEmpty()Returnstrueif this set contains no elements.booleanisFast()booleanabstract booleanbooleanFields always have commutative multiplication.abstract booleanisNaN()booleanabstract booleanisOne()Checks if this element is the multiplicative identity (one).booleanabstract booleanisZero()Checks if this element is the additive identity (zero).static Realln10E()Natural logarithm of 10static Realln2E()Natural logarithm of 2abstract Reallog()Returns the natural logarithm of this number.abstract Reallog10()Returns the base-10 logarithm of this number.longReturns the maximum of this and another number.Returns the minimum of this and another number.Returns the modulo of this number (always non-negative).abstract RealReturns the product of this element and another.Returns the product of two elements.static RealnanE()The real number NaNabstract Realnegate()Returns the additive inverse of this element.Returns the additive inverse (negation) of an element.static RealNegative infinitystatic Realof(double value) Creates a real number from a double value.static Realof(float value) Creates a real number from a float value.static Realof(int value) Creates a real number from an int value.static Realof(long value) Creates a real number from a long value.static RealCreates a real number from a String representation.static Realof(BigDecimal value) Creates a real number from a BigDecimal value.one()Returns the multiplicative identity (one element).static RealoneE()The real number 1Performs the binary operation on two elements.static RealpiE()The real number PIstatic RealPositive infinityabstract Realpow(double exponent) Returns this number raised to a power.abstract Realpow(int exp) abstract RealReturns the remainder of this number divided by another.ring()abstract Realround()Returns the closest long to the argument, with ties rounding to positive infinity.intsign()Returns the sign of this number (-1, 0, or 1).abstract Realsin()Returns the sine of this number (in radians).abstract Realsinh()Returns the hyperbolic sine of this number.abstract Realsqrt()abstract RealReturns the difference of this element and another.abstract Realtan()Returns the tangent of this number (in radians).abstract Realtanh()Returns the hyperbolic tangent of this number.Converts an angle measured in radians to an approximately equivalent angle measured in degrees.Converts an angle measured in degrees to an approximately equivalent angle measured in radians.abstract StringtoString()static RealtwoE()The real number 2static RealtwoPiE()2À - commonly used in angular calculationsstatic Realzero()Returns the additive identity (zero element).static RealzeroE()The real number 0Methods inherited from class Number
byteValue, shortValueMethods inherited from interface AbelianGroup
isCommutative, subtractMethods inherited from interface AbelianMonoid
identity, isCommutativeMethods inherited from interface Monoid
isAssociative
-
Field Details
-
ZERO
-
ONE
-
NaN
-
PI
-
E
-
TWO
-
TWO_PI
-
HALF_PI
-
POSITIVE_INFINITY
-
NEGATIVE_INFINITY
-
LN2
-
LN10
-
-
Constructor Details
-
Real
protected Real()
-
-
Method Details
-
zero
Description copied from interface:AbelianMonoidReturns the additive identity (zero element).Delegates to
AbelianMonoid.identity().- Specified by:
zeroin interfaceAbelianMonoid<Real>- Specified by:
zeroin interfaceRingElement<Real>- Returns:
- the zero element
-
one
Description copied from interface:SemiringReturns the multiplicative identity (one element).Satisfies: 1 × a = a × 1 = a for all elements a.
-
zeroE
The real number 0 -
oneE
The real number 1 -
nanE
The real number NaN -
piE
The real number PI -
eE
The real number E -
twoE
The real number 2 -
twoPiE
2À - commonly used in angular calculations -
halfPiE
À/2 - quarter turn in radians -
positiveInfinityE
Positive infinity -
negativeInfinityE
Negative infinity -
ln2E
Natural logarithm of 2 -
ln10E
Natural logarithm of 10 -
of
Creates a real number from a double value. Uses current MathContext to decide implementation.- Parameters:
value- the value- Returns:
- the Real instance
-
of
Creates a real number from a float value. Uses current MathContext to decide implementation.- Parameters:
value- the value- Returns:
- the Real instance
-
of
Creates a real number from a BigDecimal value.- Parameters:
value- the value- Returns:
- the Real instance
- Throws:
IllegalArgumentException- if value is null
-
of
-
valueOf
-
of
Creates a real number from an int value.- Parameters:
value- the value- Returns:
- the Real instance
-
of
Creates a real number from a long value.- Parameters:
value- the value- Returns:
- the Real instance
-
add
Description copied from interface:RingElementReturns the sum of this element and another.- Specified by:
addin interfaceRingElement<Real>- Parameters:
other- the element to add- Returns:
- this + other
-
subtract
Description copied from interface:RingElementReturns the difference of this element and another.Default implementation:
this.add(other.negate())- Specified by:
subtractin interfaceRingElement<Real>- Parameters:
other- the element to subtract- Returns:
- this - other
-
multiply
Description copied from interface:RingElementReturns the product of this element and another.- Specified by:
multiplyin interfaceRingElement<Real>- Parameters:
other- the element to multiply- Returns:
- this * other
-
divide
Description copied from interface:FieldElementReturns this element divided by another.Default implementation:
this.multiply(other.inverse())- Specified by:
dividein interfaceFieldElement<Real>- Parameters:
other- the divisor- Returns:
- this / other
-
negate
Description copied from interface:RingElementReturns the additive inverse of this element.- Specified by:
negatein interfaceRingElement<Real>- Returns:
- -this
-
abs
-
inverse
Description copied from interface:FieldElementReturns the multiplicative inverse of this element.For any non-zero element e: e.multiply(e.inverse()) = e.one()
- Specified by:
inversein interfaceFieldElement<Real>- Returns:
- 1/this
-
sqrt
-
pow
-
pow
-
isZero
public abstract boolean isZero()Description copied from interface:RingElementChecks if this element is the additive identity (zero).- Specified by:
isZeroin interfaceRingElement<Real>- Returns:
- true if this equals zero()
-
isOne
public abstract boolean isOne()Description copied from interface:RingElementChecks if this element is the multiplicative identity (one).- Specified by:
isOnein interfaceRingElement<Real>- Returns:
- true if this equals one()
-
isNaN
public abstract boolean isNaN() -
isInfinite
public abstract boolean isInfinite() -
isFast
public boolean isFast() -
isHighPrecision
public boolean isHighPrecision() -
isPositive
public boolean isPositive() -
isNegative
public boolean isNegative() -
doubleValue
public abstract double doubleValue()- Specified by:
doubleValuein classNumber
-
bigDecimalValue
-
equals
-
hashCode
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<Real>
-
sign
public int sign()Returns the sign of this number (-1, 0, or 1).- Returns:
- -1 if negative, 0 if zero, 1 if positive
-
pow
Returns this number raised to a power.- Parameters:
exponent- the exponent- Returns:
- this^exponent
-
exp
-
log
-
log10
Returns the base-10 logarithm of this number.- Returns:
- logâ‚Ââ‚€(this)
-
sin
-
cos
-
tan
-
asin
-
acos
-
atan
-
atan2
-
sinh
-
cosh
-
tanh
-
asinh
Returns the inverse hyperbolic sine of this number.- Returns:
- asinh(this)
-
acosh
Returns the inverse hyperbolic cosine of this number.- Returns:
- acosh(this)
-
atanh
Returns the inverse hyperbolic tangent of this number.- Returns:
- atanh(this)
-
cbrt
-
hypot
-
ceil
Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.- Returns:
- ceil(this)
-
floor
Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.- Returns:
- floor(this)
-
round
Returns the closest long to the argument, with ties rounding to positive infinity.- Returns:
- round(this)
-
toDegrees
Converts an angle measured in radians to an approximately equivalent angle measured in degrees.- Returns:
- this converted to degrees
-
toRadians
Converts an angle measured in degrees to an approximately equivalent angle measured in radians.- Returns:
- this converted to radians
-
min
-
max
-
remainder
-
mod
-
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
intValue
-
longValue
-
characteristic
public int characteristic()Description copied from interface:FieldReturns the characteristic of this field.The characteristic is the smallest positive integer n such that:
1 + 1 + ... + 1 (n times) = 0
If no such n exists, the characteristic is 0.Examples:
- char(ℚ) = char(â„Â) = char(â„‚) = 0
- char(ðÂâ€Â½Ã¢â€šÅ¡) = p (for prime p)
- Specified by:
characteristicin interfaceField<Real>- Returns:
- the characteristic (0 for infinite fields, p for finite fields)
-
operate
Description copied from interface:MagmaPerforms the binary operation on two elements.This is the fundamental operation of a magma. The result must be an element of this magma (closure property).
Properties: None required (not necessarily associative or commutative)
-
add
Description copied from interface:AbelianMonoidReturns the sum of two elements (additive notation).Delegates to
Magma.operate(Object, Object).- Specified by:
addin interfaceAbelianMonoid<Real>- Parameters:
left- the first addendright- the second addend- Returns:
- a + b
-
multiply
Description copied from interface:SemiringReturns the product of two elements.Multiplication must be associative and distribute over addition.
-
isMultiplicationCommutative
public boolean isMultiplicationCommutative()Description copied from interface:FieldFields always have commutative multiplication.- Specified by:
isMultiplicationCommutativein interfaceField<Real>- Specified by:
isMultiplicationCommutativein interfaceSemiring<Real>- Returns:
- always
true
-
negate
Description copied from interface:AbelianGroupReturns the additive inverse (negation) of an element.Satisfies: a + (-a) = (-a) + a = 0
- Specified by:
negatein interfaceAbelianGroup<Real>- Parameters:
element- the element to negate- Returns:
- -element
- See Also:
-
inverse
Description copied from interface:FieldReturns the multiplicative inverse of a non-zero element.For element a ≠0, returns a⻹ such that: a × a⻹ = a⻹ × a = 1
Examples:
- In ℚ: inverse(2/3) = 3/2
- In â„Â: inverse(5.0) = 0.2
- In â„‚: inverse(3+4i) = (3-4i)/25
-
contains
Description copied from interface:SetTests whether this set contains the specified element.This is the fundamental operation of a set - membership testing.
-
description
Description copied from interface:SetReturns a human-readable description of this set.Examples:
- "â„ (Real Numbers)"
- "ℤ/12ℤ (Integers modulo 12)"
- "{1, 2, 3, 4, 5}"
- Specified by:
descriptionin interfaceSet<Real>- Returns:
- a description of this set
-
isEmpty
-
ring
-
getScalarRing
-