List of usage examples for org.apache.commons.math3.util FastMath rint
public static double rint(double x)
From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java
@Override public void remainder(final double[] lhs, final double[] rhs, final double[] result) { // compute k such that lhs % rhs = lhs - k rhs final double rem = lhs[0] % rhs[0]; final double k = FastMath.rint((lhs[0] - rem) / rhs[0]); // set up value result[0] = rem;/*from ww w . j a va2 s . c o m*/ // set up partial derivatives for (int i = 1; i < sizes[parameters][order]; ++i) { result[i] = lhs[i] - (k * rhs[i]); } }
From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java
@Override @Optimizable//ww w. ja v a 2 s .c o m @StrictLoops public void remainder(final double[] lhs, final double[] rhs, final double[] result) { // compute k such that lhs % rhs = lhs - k rhs final double rem = lhs[0] % rhs[0]; final double k = FastMath.rint((lhs[0] - rem) / rhs[0]); // set up value result[0] = rem; // set up partial derivatives for (int i = 1; i < sizes[parameters][order]; ++i) { result[i] = lhs[i] - (k * rhs[i]); } }
From source file:fr.cs.examples.bodies.Phasing.java
/** Improve orbit to better match Earth phasing parameters. * @param previous previous orbit/* w w w . j ava 2 s . c om*/ * @param nbOrbits number of orbits in the phasing cycle * @param nbDays number of days in the phasing cycle * @param propagator propagator to use * @return an improved Earth phased orbit * @exception OrekitException if orbit cannot be propagated */ private CircularOrbit improveEarthPhasing(CircularOrbit previous, int nbOrbits, int nbDays, Propagator propagator) throws OrekitException { propagator.resetInitialState(new SpacecraftState(previous)); // find first ascending node double period = previous.getKeplerianPeriod(); SpacecraftState firstState = findFirstCrossing(0.0, true, previous.getDate(), previous.getDate().shiftedBy(2 * period), 0.01 * period, propagator); // go to next cycle, one orbit at a time SpacecraftState state = firstState; for (int i = 0; i < nbOrbits; ++i) { final AbsoluteDate previousDate = state.getDate(); state = findLatitudeCrossing(0.0, previousDate.shiftedBy(period), previousDate.shiftedBy(2 * period), 0.01 * period, period, propagator); period = state.getDate().durationFrom(previousDate); } double cycleDuration = state.getDate().durationFrom(firstState.getDate()); double deltaT; if (((int) FastMath.rint(cycleDuration / Constants.JULIAN_DAY)) != nbDays) { // we are very far from expected duration deltaT = nbDays * Constants.JULIAN_DAY - cycleDuration; } else { // we are close to expected duration GeodeticPoint startPoint = earth.transform(firstState.getPVCoordinates().getPosition(), firstState.getFrame(), firstState.getDate()); GeodeticPoint endPoint = earth.transform(state.getPVCoordinates().getPosition(), state.getFrame(), state.getDate()); double deltaL = MathUtils.normalizeAngle(endPoint.getLongitude() - startPoint.getLongitude(), 0.0); deltaT = deltaL * Constants.JULIAN_DAY / (2 * FastMath.PI); } double deltaA = 2 * previous.getA() * deltaT / (3 * nbOrbits * previous.getKeplerianPeriod()); return new CircularOrbit(previous.getA() + deltaA, previous.getCircularEx(), previous.getCircularEy(), previous.getI(), previous.getRightAscensionOfAscendingNode(), previous.getAlphaV(), PositionAngle.TRUE, previous.getFrame(), previous.getDate(), previous.getMu()); }
From source file:de.tuberlin.uebb.jbop.example.DerivativeStructure.java
/** * Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two * integers./*from www .j a v a2s .co m*/ * * @return a double number r such that r is an integer r - 0.5 <= this <= r + 0.5 */ public DerivativeStructure rint() { return new DerivativeStructure(compiler.getFreeParameters(), compiler.getOrder(), FastMath.rint(data[0])); }
From source file:de.tuberlin.uebb.jbop.example.DerivativeStructureOnlyCompose.java
/** * Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two * integers./*from w ww. java 2 s . c om*/ * * @return a double number r such that r is an integer r - 0.5 <= this <= r + 0.5 */ public DerivativeStructureOnlyCompose rint() { return new DerivativeStructureOnlyCompose(compiler.getFreeParameters(), compiler.getOrder(), FastMath.rint(data[0])); }
From source file:org.esa.beam.util.math.FastMathTest.java
@Test public void testMathRintFast() { for (double i = 0; i < numItr; ++i) { double val = FastMath.rint(i); }/*from ww w .j av a2 s . com*/ }
From source file:org.orekit.propagation.analytical.tle.TLE.java
/** Build the line 2 from the parsed elements. * @exception OrekitException if some parameter is too large to fit format */// w w w . ja va2 s. co m private void buildLine2() throws OrekitException { final StringBuffer buffer = new StringBuffer(); final DecimalFormat f34 = new DecimalFormat("##0.0000", SYMBOLS); final DecimalFormat f211 = new DecimalFormat("#0.00000000", SYMBOLS); buffer.append('2'); buffer.append(' '); buffer.append(addPadding("satelliteNumber-2", satelliteNumber, '0', 5, true)); buffer.append(' '); buffer.append(addPadding("inclination", f34.format(FastMath.toDegrees(inclination)), ' ', 8, true)); buffer.append(' '); buffer.append(addPadding("raan", f34.format(FastMath.toDegrees(raan)), ' ', 8, true)); buffer.append(' '); buffer.append(addPadding("eccentricity", (int) FastMath.rint(eccentricity * 1.0e7), '0', 7, true)); buffer.append(' '); buffer.append(addPadding("pa", f34.format(FastMath.toDegrees(pa)), ' ', 8, true)); buffer.append(' '); buffer.append(addPadding("meanAnomaly", f34.format(FastMath.toDegrees(meanAnomaly)), ' ', 8, true)); buffer.append(' '); buffer.append(addPadding("meanMotion", f211.format(meanMotion * 43200.0 / FastMath.PI), ' ', 11, true)); buffer.append(addPadding("revolutionNumberAtEpoch", revolutionNumberAtEpoch, ' ', 5, true)); buffer.append(Integer.toString(checksum(buffer))); line2 = buffer.toString(); }
From source file:org.orekit.time.AbsoluteDateTest.java
@Test public void testCCSDSUnsegmentedWithExtendedPreamble() throws OrekitException { AbsoluteDate reference = new AbsoluteDate("2095-03-03T22:02:45.789012345678901", utc); int leap = (int) FastMath.rint(utc.offsetFromTAI(reference)); double lsb = FastMath.pow(2.0, -48); byte extendedPreamble = (byte) -0x80; byte identification = (byte) 0x10; byte coarseLength1 = (byte) 0x0C; // four (3 + 1) bytes byte fineLength1 = (byte) 0x03; // 3 bytes byte coarseLength2 = (byte) 0x20; // 1 additional byte for coarse time byte fineLength2 = (byte) 0x0C; // 3 additional bytes for fine time byte[] timeCCSDSEpoch = new byte[] { 0x01, 0x02, 0x03, 0x04, (byte) (0x05 - leap), // 5 bytes for coarse time (seconds) -0x37, -0x04, -0x4A, -0x74, -0x2C, -0x3C // 6 bytes for fine time (sub-seconds) };/*from w w w .jav a 2s . c o m*/ byte preamble1 = (byte) (extendedPreamble | identification | coarseLength1 | fineLength1); byte preamble2 = (byte) (coarseLength2 | fineLength2); AbsoluteDate ccsds1 = AbsoluteDate.parseCCSDSUnsegmentedTimeCode(preamble1, preamble2, timeCCSDSEpoch, null); Assert.assertEquals(0, ccsds1.durationFrom(reference), lsb / 2); }
From source file:org.orekit.time.UTCTAIBulletinAFilesLoader.java
/** {@inheritDoc} */ @Override//from w w w .ja v a2 s . com public List<OffsetModel> loadOffsets() throws OrekitException { final Parser parser = new Parser(); DataProvidersManager.getInstance().feed(supportedNames, parser); final SortedMap<Integer, Integer> taiUtc = parser.getTaiUtc(); final SortedMap<Integer, Double> ut1Utc = parser.getUt1Utc(); // identify UT1-UTC discontinuities final List<Integer> leapDays = new ArrayList<Integer>(); Map.Entry<Integer, Double> previous = null; for (final Map.Entry<Integer, Double> entry : ut1Utc.entrySet()) { if (previous != null) { final double delta = entry.getValue() - previous.getValue(); if (FastMath.abs(delta) > 0.5) { // discontinuity found between previous and current entry, a leap second has occurred leapDays.add(entry.getKey()); } } previous = entry; } final List<OffsetModel> offsets = new ArrayList<OffsetModel>(); if (!taiUtc.isEmpty()) { // find the start offset, before the first UT1-UTC entry final Map.Entry<Integer, Integer> firstTaiMUtc = taiUtc.entrySet().iterator().next(); int offset = firstTaiMUtc.getValue(); final int refMJD = firstTaiMUtc.getKey(); for (final int leapMJD : leapDays) { if (leapMJD > refMJD) { break; } --offset; } // set all known time steps for (final int leapMJD : leapDays) { offsets.add(new OffsetModel(new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, leapMJD), ++offset)); } // check for missing time steps for (final Map.Entry<Integer, Integer> refTaiMUtc : taiUtc.entrySet()) { final DateComponents refDC = new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, refTaiMUtc.getKey() + 1); OffsetModel before = null; for (final OffsetModel o : offsets) { if (o.getStart().compareTo(refDC) < 0) { before = o; } } if (before != null) { if (refTaiMUtc.getValue() != (int) FastMath.rint(before.getOffset())) { throw new OrekitException(OrekitMessages.MISSING_EARTH_ORIENTATION_PARAMETERS_BETWEEN_DATES, before.getStart(), refDC); } } } // make sure we stop the linear drift that was used before 1972 if (offsets.isEmpty()) { offsets.add(0, new OffsetModel(new DateComponents(1972, 1, 1), taiUtc.get(taiUtc.firstKey()))); } else { if (offsets.get(0).getStart().getYear() > 1972) { offsets.add(0, new OffsetModel(new DateComponents(1972, 1, 1), ((int) FastMath.rint(offsets.get(0).getOffset())) - 1)); } } } return offsets; }