Pow Method In Math Package Of Java

Pow Method In Math Package Of Java

Math Pow is one of the methods included in java.lang.Math class that can be used to carry out simple numeric operations. The biggest advantage of java math class methods can be called without any object creation as they have been declared as static. Arbitary precision integer arithmetic and arbitrary precision decimal arithmetic can be performed using the classes provided by java.math.

Introduction to java.math.BigDecimal:

The java.math.BigDecimal class performs arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion operations. The scale of a BigDecimal is manipulated through decimal point motion operations or scaling operations. You need to have basic java programming knowledge to perform such operations.

  • Class declaration:

                      public class BigDecimal

                          extends Number

                             implements Comparable<BigDecimal>

Introduction to java.math.BigInteger:

The java.math.BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation etc. BigIntegers are represented in two’s-complement notation in context of all the operations. Java’s integer arithmetic operators have semantics similar to arithmetic operations and bitwise logical operations.

In order to compute residues, exponentiation and multiplicative inverses modular arithmetic operations are provided. When a null object reference is passed for an input parameter, NullPointerException is thrown by all methods in this class.

  • Class Declaration

                        public class BigInteger

                           extends Number

                               implements Comparable<BigInteger>

Introduction to java.math.MathContext:

The base independent settings for java.math.MathContext either precision or rounding mode; in precision mode, the results are rounded to the number of digits used in the operation. In rounding mode an object determines which algorithm will be used for rounding. RoundingMode reflects a rounding behavior where numerical operations have the capability to discard precision. Each rounding mode shows the process in which the calculation of the least significant returned digit of a rounded result is carried out.

If the number of digits returned is lesser than the number of digits needed for the exact representation of the numerical result then the discarded digit is called discarded fraction without giving any consideration for the digit’s contribution to the overall value of the number.

The java.math.MathContext class doesn’t provide operations, instead it provides objects that are immutable in character and that describe specific rules for numerical operators. These immutable objects also contain the context setting s for said operators.

  • Class declaration:

                   public final class MathContext

                       extends Object

                          implements Serializable

Categories: Technology

About Author

Write a Comment

Your e-mail address will not be published.
Required fields are marked*

four × one =