Package dev.nm.number

Class ScientificNotation

  • All Implemented Interfaces:
    Serializable

    public class ScientificNotation
    extends Number
    Scientific notation expresses a number in this form
    x = a * 10b
    a is called the significand or mantissa, and 1 ≤ |a| < 10. b is called the exponent and is an integer.

    Strictly speaking, 0 cannot be represented in this notation. This implementation, however, expresses it as 0 = 0 * 100.

    See Also:
    Wikipedia: Scientific notation, Serialized Form
    • Constructor Detail

      • ScientificNotation

        public ScientificNotation​(double significand,
                                  int exponent)
        Construct the scientific notation of a number in this form: x = a * 10b.
        Parameters:
        significand - the significand
        exponent - the exponent
      • ScientificNotation

        public ScientificNotation​(BigDecimal significand,
                                  int exponent)
        Construct the scientific notation of a number in this form: x = a * 10b.
        Parameters:
        significand - the significand
        exponent - the exponent
      • ScientificNotation

        public ScientificNotation​(BigDecimal x)
        Construct the scientific notation of a number.
        Parameters:
        x - a number
      • ScientificNotation

        public ScientificNotation​(BigInteger x)
        Construct the scientific notation of an integer.
        Parameters:
        x - an integer
      • ScientificNotation

        public ScientificNotation​(long x)
        Construct the scientific notation of a long.
        Parameters:
        x - a long integer
      • ScientificNotation

        public ScientificNotation​(double x)
        Construct the scientific notation of a double.
        Parameters:
        x - a double number
    • Method Detail

      • significand

        public BigDecimal significand()
        Get the significand.
        Returns:
        the significand
      • exponent

        public int exponent()
        Get the exponent.
        Returns:
        the exponent
      • bigDecimalValue

        public BigDecimal bigDecimalValue()
        Convert the number to BigDecimal. There is no rounding.
        Returns:
        the BigDecimal representation of the number
      • intValue

        public int intValue()
        Specified by:
        intValue in class Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class Number