Example usage for java.lang StrictMath asin

List of usage examples for java.lang StrictMath asin

Introduction

In this page you can find the example usage for java.lang StrictMath asin.

Prototype

public static native double asin(double a);

Source Link

Document

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

From source file:Main.java

public static void main(String[] args) {

    double d1 = 0.90, d2 = 5.00, d3 = 0;

    System.out.println("arc sine value of " + d1 + " = " + StrictMath.asin(d1));

    // returns NaN if argument is NaN or its absolute value is greater than 1
    System.out.println("arc sine value of " + d2 + " = " + StrictMath.asin(d2));

    // returns zero if the argument is 0
    System.out.println("arc sine value of " + d3 + " = " + StrictMath.asin(d3));
}

From source file:net.nicoulaj.benchmarks.math.DoubleAsin.java

@GenerateMicroBenchmark
public void strictmath(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(StrictMath.asin(data[i]));
}

From source file:edu.cornell.med.icb.goby.alignments.AlleleFrequencyOutputFormat.java

public void writeRecord(DiscoverVariantIterateSortedAlignments iterator, SampleCountInfo[] sampleCounts,
        int referenceIndex, int position, DiscoverVariantPositionData list, int groupIndexA, int groupIndexB) {
    // report 1-based positions
    position = position + 1;// ww w .j a  va2s  .co  m
    fillVariantCountArrays(sampleCounts);
    // records are only written for site where at least one sample is bi-allelic
    if (!eventObserved)
        return;

    int totalCount = 0;
    for (int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++) {
        SampleCountInfo sci = sampleCounts[sampleIndex];
        int sumInSample = 0;
        for (int genotypeIndex = 0; genotypeIndex < sci.getGenotypeMaxIndex(); ++genotypeIndex) {
            final int genotypeCount = sci.getGenotypeCount(genotypeIndex);
            totalCount += genotypeCount;
            sumInSample += genotypeCount;
            assert genotypeCount >= 0 : "counts must not be negative.";
        }
        // must observe at least one base in each sample to write output for this position.
        if (sumInSample == 0)
            return;
    }
    if (totalCount == 0)
        return;
    statsWriter.setInfo(depthFieldIndex, totalCount);

    CharSequence currentReferenceId = iterator.getReferenceId(referenceIndex);

    statsWriter.setId(".");
    statsWriter.setInfo(biomartFieldIndex, String.format("%s:%d:%d", currentReferenceId, position, position));
    statsWriter.setChromosome(currentReferenceId);
    statsWriter.setPosition(position);

    for (final GroupComparison comparison : groupComparisons) {
        Arrays.fill(valuesGroupsA[comparison.index], 0);
        Arrays.fill(valuesGroupsB[comparison.index], 0);
        Arrays.fill(valuesGroupAIndex, 0);
        Arrays.fill(valuesGroupBIndex, 0);

    }
    Arrays.fill(averageRPPerGroup, 0);
    Arrays.fill(numSamplesPerGroup, 0);

    for (int sampleIndex = 0; sampleIndex < numberOfSamples; sampleIndex++) {
        int numAlleles = 0;
        totalCount = 0;
        final SampleCountInfo sampleCount = sampleCounts[sampleIndex];
        for (int genotypeIndex = 0; genotypeIndex < sampleCount.getGenotypeMaxIndex(); ++genotypeIndex) {

            final int count = sampleCount.getGenotypeCount(genotypeIndex);
            if (count > 0)
                numAlleles++;
            totalCount += count;
        }

        // estimate reference allele proportion:
        double refProportion = (double) sampleCounts[sampleIndex].refCount;
        refProportion /= sampleCounts[sampleIndex].refCount + sampleCounts[sampleIndex].varCount;
        statsWriter.setSampleValue(refPropFieldIndex, sampleIndex, refProportion);
        final int groupIndex = readerIndexToGroupIndex[sampleIndex];
        final double transformedValue = StrictMath.asin(StrictMath.sqrt(refProportion));

        averageRPPerGroup[groupIndex] += refProportion;
        for (final GroupComparison comparison : groupComparisons) {

            final int index = comparison.index;
            if (groupIndex == comparison.indexGroup1) {
                valuesGroupsA[index][valuesGroupAIndex[index]++] = transformedValue;
            }
            if (groupIndex == comparison.indexGroup2) {
                valuesGroupsB[index][valuesGroupBIndex[index]++] = transformedValue;
            }
        }
        numSamplesPerGroup[groupIndex]++;
    }

    for (int groupIndex = 0; groupIndex < numberOfGroups; groupIndex++) {
        averageRPPerGroup[groupIndex] /= numSamplesPerGroup[groupIndex];
        statsWriter.setInfo(averageRPGroupsIndex[groupIndex], averageRPPerGroup[groupIndex]);
    }
    // write effect size:
    float effectSize = Math.abs(averageRPPerGroup[0] - averageRPPerGroup[1]);
    statsWriter.setInfo(effectSizeInfoIndex, effectSize);

    genotypeFormatter.writeGenotypes(statsWriter, sampleCounts, position);
    if (!statsWriter.hasAlternateAllele() || effectSize < minimumAllelelicDifference) {
        // do not write a record if the position does not have an alternate allele or if the effect size is negligible.
        return;
    }
    for (final GroupComparison comparison : groupComparisons) {
        double pValue = 1;
        final int index = comparison.index;
        try {
            if (valuesGroupAIndex[index] >= 2 && valuesGroupBIndex[index] >= 2) { // need two samples per group
                pValue = mathCommonsTTest.homoscedasticTTest(valuesGroupsA[index], valuesGroupsB[index]);
            }

        } catch (MathException e) {
            pValue = 1;
        }
        statsWriter.setInfo(pValueIndex[index], pValue);
    }
    statsWriter.writeRecord();
}

From source file:org.esa.beam.util.math.FastMathPerformance.java

public void testAsin() {
    System.gc();/*from  w w  w.j  av  a  2 s.com*/
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.asin(i / 10000000.0);
    long strictTime = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.asin(i / 10000000.0);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.asin(i / 10000000.0);
    long mathTime = System.nanoTime() - time;

    report("asin", x + y + z, strictTime, fastTime, mathTime);
}