Java Number Power pow10(final int exponent)

Here you can find the source of pow10(final int exponent)

Description

A very efficient function to compute powers of 10.

License

Open Source License

Parameter

Parameter Description
exponent the exponent of the base. Cannot exceed 18.

Return

the value 10^exponent

Declaration

public static long pow10(final int exponent) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w w  w  .  ja  v  a 2s . c  o  m*/
     * Powers of ten as long values 10^0; 10^1; 10^2 ...10^18.
     */
    private static final long[] POWER10 = new long[] { 1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L,
            100000000L, 1000000000L, 10000000000L, 100000000000L, 1000000000000L, 10000000000000L, 100000000000000L,
            1000000000000000L, 10000000000000000L, 100000000000000000L, 1000000000000000000L };

    /**
     * A very efficient function to compute powers of 10.
     * <p>
     * Since a long is a signed 64 bit two's-complement number, its range is
     * <code>-9,223,372,036,854,775,808</code> to <code>9,223,372,036,854,775,807</code>.
     * Thus, <code>10^18 < 9,223,372,036,854,775,807 < 10^19</code>.
     * <p>
     * <b>Precondition</b>: <code>0 <= exponent <= 18 </code>
     * 
     * @param exponent the exponent of the base. Cannot exceed 18.
     * @return the value <code>10^exponent</code>
     */
    public static long pow10(final int exponent) {
        return POWER10[exponent];
    }
}

Related

  1. pow(long base, long exp)
  2. pow(long n, long pow)
  3. pow(long value, long pow)
  4. pow(Number x, Number exponent)
  5. pow(String str, int n)
  6. pow10(int degree)
  7. pow10(int n)
  8. pow16(float a)
  9. pow2(double base, double power)