org.apfloat

## Class AprationalMath

• ```public class AprationalMath
extends Object```
Various mathematical functions for arbitrary precision rational numbers.
Version:
1.7.0
Author:
Mikko Tommila
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static Aprational` `abs(Aprational x)`
Absolute value.
`static Aprational` ```copySign(Aprational x, Aprational y)```
Copy sign from one argument to another.
`static Aprational` `negate(Aprational x)`
Deprecated.
`static Aprational` ```pow(Aprational x, long n)```
Integer power.
`static Aprational` `product(Aprational... x)`
Product of numbers.
`static Apfloat` ```round(Aprational x, long precision, RoundingMode roundingMode)```
Rounds the given number to the specified precision with the specified rounding mode.
`static Aprational` ```scale(Aprational x, long scale)```
Multiply by a power of the radix.
`static Aprational` `sum(Aprational... x)`
Sum of numbers.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### pow

```public static Aprational pow(Aprational x,
long n)
throws ArithmeticException,
ApfloatRuntimeException```
Integer power.
Parameters:
`x` - Base of the power operator.
`n` - Exponent of the power operator.
Returns:
`x` to the `n`:th power, that is `xn`.
Throws:
`ArithmeticException` - If both `x` and `n` are zero.
`ApfloatRuntimeException`
• #### negate

```@Deprecated
public static Aprational negate(Aprational x)
throws ApfloatRuntimeException```
Deprecated.
Returns an aprational whose value is `-x`.
Parameters:
`x` - The argument.
Returns:
`-x`.
Throws:
`ApfloatRuntimeException`
• #### abs

```public static Aprational abs(Aprational x)
throws ApfloatRuntimeException```
Absolute value.
Parameters:
`x` - The argument.
Returns:
Absolute value of `x`.
Throws:
`ApfloatRuntimeException`
• #### copySign

```public static Aprational copySign(Aprational x,
Aprational y)
throws ApfloatRuntimeException```
Copy sign from one argument to another.
Parameters:
`x` - The value whose sign is to be adjusted.
`y` - The value whose sign is to be used.
Returns:
`x` with its sign changed to match the sign of `y`.
Throws:
`ApfloatRuntimeException`
Since:
1.1
• #### scale

```public static Aprational scale(Aprational x,
long scale)
throws ApfloatRuntimeException```
Multiply by a power of the radix. Note that this method is prone to intermediate overflow errors. Also, scaling by a very large negative number won't result in an underflow and a zero result, but an overflow of the denominator and an exception thrown.
Parameters:
`x` - The argument.
`scale` - The scaling factor.
Returns:
`x * x.radix()scale`.
Throws:
`ApfloatRuntimeException`
• #### round

```public static Apfloat round(Aprational x,
long precision,
RoundingMode roundingMode)
throws IllegalArgumentException,
ArithmeticException,
ApfloatRuntimeException```
Rounds the given number to the specified precision with the specified rounding mode.
Parameters:
`x` - The number to round.
`precision` - The precision to round to.
`roundingMode` - The rounding mode to use.
Returns:
The rounded number.
Throws:
`IllegalArgumentException` - If `precision` is less than zero or zero.
`ArithmeticException` - If rounding is necessary (result is not exact) and rounding mode is `RoundingMode.UNNECESSARY`.
`ApfloatRuntimeException`
Since:
1.7.0
• #### product

```public static Aprational product(Aprational... x)
throws ApfloatRuntimeException```
Product of numbers. This method may perform significantly better than simply multiplying the numbers sequentially.

If there are no arguments, the return value is `1`.

Parameters:
`x` - The argument(s).
Returns:
The product of the given numbers.
Throws:
`ApfloatRuntimeException`
Since:
1.3
• #### sum

```public static Aprational sum(Aprational... x)
throws ApfloatRuntimeException```
Sum of numbers. This method may perform significantly better than simply adding the numbers sequentially.

If there are no arguments, the return value is `0`.

Parameters:
`x` - The argument(s).
Returns:
The sum of the given numbers.
Throws:
`ApfloatRuntimeException`
Since:
1.3