All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.obermuhlner.math.big.internal.SinCalculator Maven / Gradle / Ivy

There is a newer version: 2.3.2
Show newest version
package ch.obermuhlner.math.big.internal;

import java.math.BigDecimal;
import java.math.MathContext;

import ch.obermuhlner.math.big.BigRational;

/**
 * Calculates sinus using the Maclaurin series.
 * 
 * 

See Wikipedia: Taylorreihe

* *

No argument checking or optimizations are done. * This implementation is not intended to be called directly.

*/ public class SinCalculator extends SeriesCalculator { public static final SinCalculator INSTANCE = new SinCalculator(); private int n = 0; private boolean negative = false; private BigRational factorial2nPlus1 = BigRational.ONE; private SinCalculator() { super(true); } @Override protected BigRational getCurrentFactor() { BigRational factor = factorial2nPlus1.reciprocal(); if (negative) { factor = factor.negate(); } return factor; } @Override protected void calculateNextFactor() { n++; factorial2nPlus1 = factorial2nPlus1.multiply(2 * n); factorial2nPlus1 = factorial2nPlus1.multiply(2 * n + 1); negative = !negative; } @Override protected PowerIterator createPowerIterator(BigDecimal x, MathContext mathContext) { return new PowerTwoNPlusOneIterator(x, mathContext); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy