Tabnine Logo
MathLib
Code IndexAdd Tabnine to your IDE (free)

How to use
MathLib
in
javolution.lang

Best Java code snippets using javolution.lang.MathLib (Showing top 20 results out of 315)

origin: org.javolution/javolution-core-java

@Override
public void setConcurrency(int concurrency) {
  // The setting of the concurrency can only reduce the number 
  // of threads available in the context.
  int nbThreads = MathLib.min(parent.threads.length, concurrency);
  threads = new ConcurrentThreadImpl[nbThreads];
  for (int i = 0; i < nbThreads; i++) { // Reused from parent threads.
    threads[i] = parent.threads[i];
  }
}
origin: org.apache.marmotta/marmotta-commons

/**
 * Returns the arc sine of the specified value, 
 * in the range of -<i>pi</i>/2 through <i>pi</i>/2. 
 *
 * @param x the value whose arc sine is to be returned.
 * @return the arc sine in radians for the specified value.
 **/
public static double asin(double x) {
  if (x < -1.0 || x > 1.0)
    return MathLib.NaN;
  if (x == -1.0)
    return -HALF_PI;
  if (x == 1.0)
    return HALF_PI;
  return MathLib.atan(x / MathLib.sqrt(1.0 - x * x));
}
origin: org.javolution/javolution-core-java

/**
 * Returns the remainder of the division of the specified two arguments.
 *
 * @param x the dividend.
 * @param y the divisor.
 * @return <code>x - round(x / y) * y</code>
 **/
public static double rem(double x, double y) {
  double tmp = x / y;
  if (MathLib.abs(tmp) <= Long.MAX_VALUE)
    return x - MathLib.round(tmp) * y;
  else
    return NaN;
}
origin: org.apache.marmotta/marmotta-commons

/**
 * Returns the value of the first argument raised to the power of the
 * second argument. 
 *
 * @param x the base.
 * @param y the exponent.
 * @return <code>x<sup>y</sup></code>
 **/
public static double pow(double x, double y) {
  // Use close approximation (+/- LSB)
  if ((x < 0) && (y == (int) y))
    return (((int) y) & 1) == 0 ? pow(-x, y) : -pow(-x, y);
  return MathLib.exp(y * MathLib.log(x));
}
origin: org.jscience/jscience

int log10Value = (int) MathLib.floor(MathLib.log10(MathLib
    .abs(value)));
int log10Error = (int) MathLib.floor(MathLib.log10(error));
int digits = log10Value - log10Error - 1; // Exact digits.
digits = MathLib.max(1, digits + _errorDigits);
boolean scientific = (MathLib.abs(value) >= 1E6)
    || (MathLib.abs(value) < 1E-6);
boolean showZeros = false;
arg1.append('(');
TypeFormat.format(value, digits, scientific, showZeros, arg1);
arg1.append(" ± ");
scientific = (MathLib.abs(error) >= 1E6)
    || (MathLib.abs(error) < 1E-6);
showZeros = true;
TypeFormat.format(error, _errorDigits, scientific, showZeros, arg1);
origin: org.apache.marmotta/marmotta-commons

  return 0.0;
if (m == Long.MIN_VALUE)
  return toDoublePow2(Long.MIN_VALUE >> 1, n + 1);
if (m < 0)
  return -toDoublePow2(-m, n);
int bitLength = MathLib.bitLength(m);
int shift = bitLength - 53;
long exp = 1023L + 52 + n + shift; // Use long to avoid overflow.
  if (exp <= -54)
    return 0.0;
  return toDoublePow2(m, n + 54) / 18014398509481984L; // 2^54 Exact.
origin: javolution/javolution

  return 0.0;
if (m == Long.MIN_VALUE)
  return toDoublePow10(Long.MIN_VALUE / 10, n + 1);
if (m < 0)
  return -toDoublePow10(-m, n);
if (n >= 0) { // Positive power.
  if (n > 308)
  int shift = 31 - MathLib.bitLength(x3); // -1..30
  pow2 -= shift;
  long mantissa = (shift < 0) ? (x3 << 31) | (x2 >>> 1) : // x3 is 32 bits.
      (((x3 << 32) | x2) << shift) | (x1 >>> (32 - shift));
  return toDoublePow2(mantissa, pow2);
    int shift = 63 - MathLib.bitLength(x1);
    x1 <<= shift;
    x1 |= x0 >>> (63 - shift);
    pow2 -= i;
  return toDoublePow2(x1, pow2);
origin: org.jscience/jscience

/**
 * Returns this complex raised to the power of the specified complex
 * exponent.
 *
 * @param   that the exponent.
 * @return  <code>this**that</code>.
 */
public Complex pow(Complex that) {
  Complex c = FACTORY.object();
  double r1 = MathLib.log(this.magnitude());
  double i1 = this.argument();
  double r2 = (r1 * that._real) - (i1 * that._imaginary);
  double i2 = (r1 * that._imaginary) + (i1 * that._real);
  double m = MathLib.exp(r2);
  c._real = m * MathLib.cos(i2);
  c._imaginary = m * MathLib.sin(i2);
  return c;
}
origin: org.jscience/jscience

/**
 * Compares the magnitude of this number with that number.
 *
 * @return <code>|this| > |that|</code>
 */
public boolean isLargerThan(Integer64 that) {
  return MathLib.abs(this._value) > MathLib.abs(that._value);
}
origin: javolution/javolution

/**
 * Returns the hyperbolic cosine of x.
 * 
 * @param x the value for which the hyperbolic cosine is calculated.
 * @return <code>(exp(x) + exp(-x)) / 2</code>
 **/
public static double cosh(double x) {
  return (MathLib.exp(x) + MathLib.exp(-x)) * 0.5;
}
/**/
origin: javolution/javolution

/**
 * Set the {@link LocalContext local} concurrency. Concurrency is 
 * hard limited by {@link #MAXIMUM_CONCURRENCY}.
 * 
 * @param concurrency the new concurrency (<code>0</code> or negative
 *       number to disable concurrency).
 */
public static void setConcurrency(int concurrency) {
  concurrency = MathLib.max(0, concurrency);
  concurrency = MathLib.min(((Integer) MAXIMUM_CONCURRENCY.get()).intValue(), concurrency);
  CONCURRENCY.set(new Integer(concurrency));
}
origin: com.github.mrstampy/esp

/**
 * Returns the root mean square value of the given inputs over the given
 * range.
 * 
 * @param lowerFreqHz
 *          >= 1
 * @param upperFreqHz
 *          < {@link #getUpperMeasurableFrequency()}
 * @param fftd
 *          powers
 * 
 * @return the rms value
 */
public double rms(int lowerFreqHz, int upperFreqHz, double... fftd) {
  assert fftd != null && fftd.length > 0;
  assert lowerFreqHz >= 1 && lowerFreqHz < upperFreqHz && upperFreqHz < getUpperMeasurableFrequency();
  int divisor = fftd.length;
  double sum = 0;
  for (int i = lowerFreqHz; i <= upperFreqHz; i++) {
    sum += MathLib.pow(fftd[i], 2);
  }
  return MathLib.sqrt(new BigDecimal(sum).divide(new BigDecimal(divisor), 10, RoundingMode.HALF_UP).doubleValue());
}
origin: com.github.mrstampy/esp

private double getMax(double[] fftd, int lowerCutoffHz, int upperCutoffHz) {
  double max = Double.MIN_VALUE;
  for (int i = lowerCutoffHz; i <= upperCutoffHz; i++) {
    max = MathLib.max(max, fftd[i]);
  }
  return max;
}
origin: javolution/javolution

/**
 * Returns the closest <code>long</code> to the specified argument. 
 *
 * @param d the <code>double</code> value to be rounded to a 
 *        <code>long</code>
 * @return the nearest <code>long</code> value.
 **/
public static long round(double d) {
  return (long) floor(d + 0.5d);
}
/**/
origin: org.jscience/jscience

@SuppressWarnings("unchecked")
@Override
public Appendable format(Amount arg0, Appendable arg1)
    throws IOException {
  if (arg0.getUnit() instanceof Currency)
    return formatMoney(arg0, arg1);
  if (arg0.isExact()) {
    TypeFormat.format(arg0.getExactValue(), arg1);
    arg1.append(' ');
    return UnitFormat.getInstance().format(arg0.getUnit(), arg1);
  }
  double value = arg0.getEstimatedValue();
  double error = arg0.getAbsoluteError();
  int log10Value = (int) MathLib.floor(MathLib.log10(MathLib
      .abs(value)));
  int log10Error = (int) MathLib.floor(MathLib.log10(error));
  int digits = log10Value - log10Error - 1; // Exact digits.
  boolean scientific = (MathLib.abs(value) >= 1E6)
      || (MathLib.abs(value) < 1E-6);
  boolean showZeros = true;
  TypeFormat.format(value, digits, scientific, showZeros, arg1);
  arg1.append(' ');
  return UnitFormat.getInstance().format(arg0.getUnit(), arg1);
}
origin: javolution/javolution

/**
 * Returns the decimal logarithm of the specified value.
 *
 * @param x the value greater than <code>0.0</code>.
 * @return the value y such as <code>10<sup>y</sup> == x</code>
 **/
public static double log10(double x) {
  return log(x) * INV_LOG10;
}
private static double INV_LOG10 = 0.43429448190325182765112891891661;
origin: org.jscience/jscience

/**
 * Returns the magnitude of this complex number, also referred to
 * as the "modulus" or "length".
 *
 * @return the magnitude of this complex number.
 */
public double magnitude() {
  return MathLib.sqrt(_real * _real + _imaginary * _imaginary);
}
origin: org.jscience/jscience

/**
 * Indicates if this number is a power of two (equals to 2<sup>
 * ({@link #bitLength bitLength()} - 1)</sup>).
 * 
 * @return <code>true</code> if this number is a power of two; 
 *         <code>false</code> otherwise.
 */
public boolean isPowerOfTwo() {
  if (_size == 0)
    return false;
  final int n = _size - 1;
  for (int j = 0; j < n; j++) {
    if (_words[j] != 0)
      return false;
  }
  final int bitLength = MathLib.bitLength(_words[n]);
  return _words[n] == (1L << (bitLength - 1));
}
origin: org.jscience/jscience

/**
 * Returns one of the two square root of this complex number.
 *
 * @return <code>sqrt(this)</code>.
 */
public Complex sqrt() {
  Complex c = FACTORY.object();
  double m = MathLib.sqrt(this.magnitude());
  double a = this.argument() / 2.0;
  c._real = m * MathLib.cos(a);
  c._imaginary = m * MathLib.sin(a);
  return c;
}
origin: org.jscience/jscience

/**
 * Returns this complex raised to the specified power.
 *
 * @param   e the exponent.
 * @return  <code>this**e</code>.
 */
public Complex pow(double e) {
  Complex c = FACTORY.object();
  double m = MathLib.pow(this.magnitude(), e);
  double a = this.argument() * e;
  c._real = m * MathLib.cos(a);
  c._imaginary = m * MathLib.sin(a);
  return c;
}
javolution.langMathLib

Javadoc

An utility class providing a Realtime implementation of the math library.

Most used methods

  • min
    Returns the smaller of two long values.
  • sqrt
    Returns the positive square root of the specified value.
  • abs
    Returns the absolute value of the specified long argument.
  • bitLength
    Returns the number of bits in the minimal two's-complement representation of the specified long, exc
  • exp
    Returns #E raised to the specified power.
  • floor
    Returns the largest (closest to positive infinity)double value that is not greater than the argument
  • log
    Returns the natural logarithm (base #E) of the specified value.
  • max
    Returns the greater of two long values.
  • pow
    Returns the value of the first argument raised to the power of the second argument.
  • round
    Returns the closest int to the specified argument.
  • toDoublePow10
    Returns the closest double representation of the specified long number multiplied by a power of ten.
  • toDoublePow2
    Returns the closest double representation of the specified long number multiplied by a power of two.
  • toDoublePow10,
  • toDoublePow2,
  • toLongPow10,
  • _atan,
  • _ieee754_exp,
  • _ieee754_log,
  • asin,
  • atan,
  • digitLength,
  • floorLog10

Popular in Java

  • Parsing JSON documents to java classes using gson
  • startActivity (Activity)
  • setScale (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Join (org.hibernate.mapping)
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now