当前位置: 首页>>代码示例>>Java>>正文


Java ArithmeticUtils.gcd方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.ArithmeticUtils.gcd方法的典型用法代码示例。如果您正苦于以下问题:Java ArithmeticUtils.gcd方法的具体用法?Java ArithmeticUtils.gcd怎么用?Java ArithmeticUtils.gcd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.ArithmeticUtils的用法示例。


在下文中一共展示了ArithmeticUtils.gcd方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureSinks

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
private synchronized void configureSinks() {
  sinkConfigs = config.getInstanceConfigs(SINK_KEY);
  int confPeriod = 0;
  for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) {
    MetricsConfig conf = entry.getValue();
    int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT);
    confPeriod = confPeriod == 0 ? sinkPeriod
                                 : ArithmeticUtils.gcd(confPeriod, sinkPeriod);
    String clsName = conf.getClassName("");
    if (clsName == null) continue;  // sink can be registered later on
    String sinkName = entry.getKey();
    try {
      MetricsSinkAdapter sa = newSink(sinkName,
          conf.getString(DESC_KEY, sinkName), conf);
      sa.start();
      sinks.put(sinkName, sa);
    }
    catch (Exception e) {
      LOG.warn("Error creating sink '"+ sinkName +"'", e);
    }
  }
  period = confPeriod > 0 ? confPeriod
                          : config.getInt(PERIOD_KEY, PERIOD_DEFAULT);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:MetricsSystemImpl.java

示例2: multiply

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
/**
 * <p>Multiplies the value of this fraction by another, returning the
 * result in reduced form.</p>
 *
 * @param fraction  the fraction to multiply by, must not be {@code null}
 * @return a {@code Fraction} instance with the resulting values
 * @throws NullArgumentException if the fraction is {@code null}
 * @throws MathArithmeticException if the resulting numerator or denominator exceeds
 *  {@code Integer.MAX_VALUE}
 */
public Fraction multiply(Fraction fraction) {
    if (fraction == null) {
        throw new NullArgumentException(LocalizedFormats.FRACTION);
    }
    if (numerator == 0 || fraction.numerator == 0) {
        return ZERO;
    }
    // knuth 4.5.1
    // make sure we don't overflow unless the result *must* overflow.
    int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
    int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
    return getReducedFraction
    (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
            ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:Fraction.java

示例3: configureSinks

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
private synchronized void configureSinks() {
  sinkConfigs = config.getInstanceConfigs(SINK_KEY);
  long confPeriodMillis = 0;
  for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) {
    MetricsConfig conf = entry.getValue();
    int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT);
    // Support configuring periodMillis for testing.
    long sinkPeriodMillis =
        conf.getLong(PERIOD_MILLIS_KEY, sinkPeriod * 1000);
    confPeriodMillis = confPeriodMillis == 0 ? sinkPeriodMillis
        : ArithmeticUtils.gcd(confPeriodMillis, sinkPeriodMillis);
    String clsName = conf.getClassName("");
    if (clsName == null) continue;  // sink can be registered later on
    String sinkName = entry.getKey();
    try {
      MetricsSinkAdapter sa = newSink(sinkName,
          conf.getString(DESC_KEY, sinkName), conf);
      sa.start();
      sinks.put(sinkName, sa);
    } catch (Exception e) {
      LOG.warn("Error creating sink '"+ sinkName +"'", e);
    }
  }
  long periodSec = config.getInt(PERIOD_KEY, PERIOD_DEFAULT);
  period = confPeriodMillis > 0 ? confPeriodMillis
      : config.getLong(PERIOD_MILLIS_KEY, periodSec * 1000);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:MetricsSystemImpl.java

示例4: Fraction

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
/**
 * Create a fraction given the numerator and denominator.  The fraction is
 * reduced to lowest terms.
 * @param num the numerator.
 * @param den the denominator.
 * @throws MathArithmeticException if the denominator is {@code zero}
 */
public Fraction(int num, int den) {
    if (den == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
                                          num, den);
    }
    if (den < 0) {
        if (num == Integer.MIN_VALUE ||
            den == Integer.MIN_VALUE) {
            throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
                                              num, den);
        }
        num = -num;
        den = -den;
    }
    // reduce numerator and denominator by greatest common denominator.
    final int d = ArithmeticUtils.gcd(num, den);
    if (d > 1) {
        num /= d;
        den /= d;
    }

    // move sign to numerator.
    if (den < 0) {
        num = -num;
        den = -den;
    }
    this.numerator   = num;
    this.denominator = den;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:37,代码来源:Fraction.java

示例5: getReducedFraction

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
/**
 * <p>Creates a {@code Fraction} instance with the 2 parts
 * of a fraction Y/Z.</p>
 *
 * <p>Any negative signs are resolved to be on the numerator.</p>
 *
 * @param numerator  the numerator, for example the three in 'three sevenths'
 * @param denominator  the denominator, for example the seven in 'three sevenths'
 * @return a new fraction instance, with the numerator and denominator reduced
 * @throws MathArithmeticException if the denominator is {@code zero}
 */
public static Fraction getReducedFraction(int numerator, int denominator) {
    if (denominator == 0) {
        throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR_IN_FRACTION,
                                          numerator, denominator);
    }
    if (numerator==0) {
        return ZERO; // normalize zero.
    }
    // allow 2^k/-2^31 as a valid fraction (where k>0)
    if (denominator==Integer.MIN_VALUE && (numerator&1)==0) {
        numerator/=2; denominator/=2;
    }
    if (denominator < 0) {
        if (numerator==Integer.MIN_VALUE ||
                denominator==Integer.MIN_VALUE) {
            throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION,
                                              numerator, denominator);
        }
        numerator = -numerator;
        denominator = -denominator;
    }
    // simplify fraction.
    int gcd = ArithmeticUtils.gcd(numerator, denominator);
    numerator /= gcd;
    denominator /= gcd;
    return new Fraction(numerator, denominator);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:Fraction.java

示例6: AbstractAlignedProcessingTimeWindowOperator

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
protected AbstractAlignedProcessingTimeWindowOperator(
		F function,
		KeySelector<IN, KEY> keySelector,
		TypeSerializer<KEY> keySerializer,
		TypeSerializer<STATE> stateTypeSerializer,
		long windowLength,
		long windowSlide) {
	super(function);

	if (windowLength < MIN_SLIDE_TIME) {
		throw new IllegalArgumentException("Window length must be at least " + MIN_SLIDE_TIME + " msecs");
	}
	if (windowSlide < MIN_SLIDE_TIME) {
		throw new IllegalArgumentException("Window slide must be at least " + MIN_SLIDE_TIME + " msecs");
	}
	if (windowLength < windowSlide) {
		throw new IllegalArgumentException("The window size must be larger than the window slide");
	}

	final long paneSlide = ArithmeticUtils.gcd(windowLength, windowSlide);
	if (paneSlide < MIN_SLIDE_TIME) {
		throw new IllegalArgumentException(String.format(
				"Cannot compute window of size %d msecs sliding by %d msecs. " +
						"The unit of grouping is too small: %d msecs", windowLength, windowSlide, paneSlide));
	}

	this.function = requireNonNull(function);
	this.keySelector = requireNonNull(keySelector);
	this.keySerializer = requireNonNull(keySerializer);
	this.stateTypeSerializer = requireNonNull(stateTypeSerializer);
	this.windowSize = windowLength;
	this.windowSlide = windowSlide;
	this.paneSize = paneSlide;
	this.numPanesPerWindow = MathUtils.checkedDownCast(windowLength / paneSlide);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:36,代码来源:AbstractAlignedProcessingTimeWindowOperator.java

示例7: configureSinks

import org.apache.commons.math3.util.ArithmeticUtils; //导入方法依赖的package包/类
private synchronized void configureSinks() {
  sinkConfigs = config.getInstanceConfigs(SINK_KEY);
  long confPeriodMillis = 0;
  for (Entry<String, MetricsConfig> entry : sinkConfigs.entrySet()) {
    MetricsConfig conf = entry.getValue();
    int sinkPeriod = conf.getInt(PERIOD_KEY, PERIOD_DEFAULT);
    // Support configuring periodMillis for testing.
    long sinkPeriodMillis =
        conf.getLong(PERIOD_MILLIS_KEY, sinkPeriod * 1000);
    confPeriodMillis = confPeriodMillis == 0 ? sinkPeriodMillis
        : ArithmeticUtils.gcd(confPeriodMillis, sinkPeriodMillis);
    String clsName = conf.getClassName("");
    if (clsName == null) continue;  // sink can be registered later on
    String sinkName = entry.getKey();
    try {
      MetricsSinkAdapter sa = newSink(sinkName,
          conf.getString(DESC_KEY, sinkName), conf);
      sa.start();
      sinks.put(sinkName, sa);
    }
    catch (Exception e) {
      LOG.warn("Error creating sink '"+ sinkName +"'", e);
    }
  }
  long periodSec = config.getInt(PERIOD_KEY, PERIOD_DEFAULT);
  period = confPeriodMillis > 0 ? confPeriodMillis
      : config.getLong(PERIOD_MILLIS_KEY, periodSec * 1000);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:29,代码来源:MetricsSystemImpl.java


注:本文中的org.apache.commons.math3.util.ArithmeticUtils.gcd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。