FileDocCategorySizeDatePackage
MathErr.javaAPI DocAndroid 5.1 API2702Thu Mar 12 22:22:54 GMT 2015com.example.android.rs.matherr

MathErr

public class MathErr extends Object

Fields Summary
private RenderScript
mRS
private Allocation
mAllocationSrc
private Allocation
mAllocationRes
private ScriptC_math_err
mScript
private Random
mRand
private final int
BUF_SIZE
float[]
mSrc
float[]
mRef
float[]
mRes
Constructors Summary
MathErr(RenderScript rs)


      
        mRS = rs;
        mScript = new ScriptC_math_err(mRS);

        mAllocationSrc = Allocation.createSized(rs, Element.F32(rs), BUF_SIZE);
        mAllocationRes = Allocation.createSized(rs, Element.F32(rs), BUF_SIZE);

        testExp2();
        testLog2();
    
Methods Summary
voidbuildRand()

        for (int i=0; i < BUF_SIZE; i++) {
            mSrc[i] = (((float)i) / 9) - 200;
            //mSrc[i] = Float.intBitsToFloat(mRand.nextInt());
        }
        mAllocationSrc.copyFrom(mSrc);
    
voidlogErr()

        mAllocationRes.copyTo(mRes);
        for (int i=0; i < BUF_SIZE; i++) {
            int err = Float.floatToRawIntBits(mRef[i]) - Float.floatToRawIntBits(mRes[i]);
            err = Math.abs(err);
            if (err > 8096) {
                android.util.Log.v("err", "error " + err + " src " + mSrc[i] + " ref " + mRef[i] + " res " + mRes[i]);
            }
        }
    
voidtestExp2()

        android.util.Log.v("err", "testing exp2");
        buildRand();
        mScript.forEach_testExp2(mAllocationSrc, mAllocationRes);
        for (int i=0; i < BUF_SIZE; i++) {
            mRef[i] = (float)Math.pow(2.f, mSrc[i]);
        }
        logErr();
    
voidtestLog2()

        android.util.Log.v("err", "testing log2");
        buildRand();
        mScript.forEach_testLog2(mAllocationSrc, mAllocationRes);
        for (int i=0; i < BUF_SIZE; i++) {
            mRef[i] = (float)Math.log(mSrc[i]) * 1.442695041f;
        }
        logErr();