Java Number Power pow(final float a, final float b)

Here you can find the source of pow(final float a, final float b)

Description

Computes a fast approximation to Math.pow(a, b).

License

Open Source License

Parameter

Parameter Description
a a positive number
b a number

Return

a^b

Declaration


public static final float pow(final float a, final float b) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w  .  jav  a 2  s .  c  o m
     * Computes a fast approximation to <code>Math.pow(a, b)</code>. Adapted
     * from <url>http://www.dctsystems.co.uk/Software/power.html</url>.
     * 
     * @param a
     *            a positive number
     * @param b
     *            a number
     * @return a^b
     */
    // UNTESTED
    public static final float pow(final float a, final float b) {
        return (float) Math.pow(a, b);
        // TODO(pruggia) reenable fast pow ?
        // JBOX2DCODE:
        // // adapted from: http://www.dctsystems.co.uk/Software/power.html
        // if (Settings.FAST_MATH) {
        // float x = Float.floatToRawIntBits(a);
        // x *= 1.0f / (1 << 23);
        // x = x - 127;
        // float y = x - MathUtils.floor(x);
        // b *= x + (y - y * y) * 0.346607f;
        // y = b - MathUtils.floor(b);
        // y = (y - y * y) * 0.33971f;
        // return Float.intBitsToFloat((int) ((b + 127 - y) * (1 << 23)));
        // }
        // else {
        // return (float) Math.pow(a, b);
        // }
    }
}

Related

  1. pow(double x, double y)
  2. pow(double x, int n)
  3. pow(double[] array, double exp)
  4. pow(double[][] x, int p)
  5. pow(final double[] values, final double exp)
  6. pow(final int a, final int b)
  7. pow(final int a, final int b)
  8. pow(final int b, final int e)
  9. pow(final long base, final long exponent)