Tabnine Logo
Math.multiplyExact
Code IndexAdd Tabnine to your IDE (free)

How to use
multiplyExact
method
in
java.lang.Math

Best Java code snippets using java.lang.Math.multiplyExact (Showing top 20 results out of 666)

origin: spring-projects/spring-framework

/**
 * Obtain a {@link DataSize} representing the specified number of kilobytes.
 * @param kilobytes the number of kilobytes, positive or negative
 * @return a {@link DataSize}
 */
public static DataSize ofKilobytes(long kilobytes) {
  return new DataSize(Math.multiplyExact(kilobytes, BYTES_PER_KB));
}
origin: spring-projects/spring-framework

/**
 * Obtain a {@link DataSize} representing the specified number of megabytes.
 * @param megabytes the number of megabytes, positive or negative
 * @return a {@link DataSize}
 */
public static DataSize ofMegabytes(long megabytes) {
  return new DataSize(Math.multiplyExact(megabytes, BYTES_PER_MB));
}
origin: spring-projects/spring-framework

/**
 * Obtain a {@link DataSize} representing the specified number of gigabytes.
 * @param gigabytes the number of gigabytes, positive or negative
 * @return a {@link DataSize}
 */
public static DataSize ofGigabytes(long gigabytes) {
  return new DataSize(Math.multiplyExact(gigabytes, BYTES_PER_GB));
}
origin: spring-projects/spring-framework

/**
 * Obtain a {@link DataSize} representing the specified number of terabytes.
 * @param terabytes the number of terabytes, positive or negative
 * @return a {@link DataSize}
 */
public static DataSize ofTerabytes(long terabytes) {
  return new DataSize(Math.multiplyExact(terabytes, BYTES_PER_TB));
}
origin: prestodb/presto

  public byte[] get()
  {
    byte[] buffer;
    if (bufferPool.isEmpty()) {
      currentSize = min(multiplyExact(currentSize, 2), maxChunkSize);
      buffer = new byte[currentSize];
    }
    else {
      buffer = bufferPool.remove(0);
      currentSize = buffer.length;
    }
    usedBuffers.add(buffer);
    return buffer;
  }
}
origin: prestodb/presto

  public byte[] get()
  {
    byte[] buffer;
    if (bufferPool.isEmpty()) {
      currentSize = min(multiplyExact(currentSize, 2), maxChunkSize);
      buffer = new byte[currentSize];
    }
    else {
      buffer = bufferPool.remove(0);
      currentSize = buffer.length;
    }
    usedBuffers.add(buffer);
    return buffer;
  }
}
origin: prestodb/presto

public static int toMonths(int year, int months)
{
  try {
    return addExact(multiplyExact(year, 12), months);
  }
  catch (ArithmeticException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: prestodb/presto

public static int toMonths(int year, int months)
{
  try {
    return addExact(multiplyExact(year, 12), months);
  }
  catch (ArithmeticException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: neo4j/neo4j

private long calcAverageLengthInSeconds( long months, long days, long seconds )
{
  long daysInSeconds = Math.multiplyExact( days, SECONDS_PER_DAY );
  long monthsInSeconds = Math.multiplyExact( months, AVG_SECONDS_PER_MONTH );
  return Math.addExact( seconds, Math.addExact( daysInSeconds, monthsInSeconds ) );
}
origin: neo4j/neo4j

/**
 * Overflow safe multiplication of two longs
 *
 * @param a left-hand operand
 * @param b right-hand operand
 * @return a * b
 */
public static LongValue multiply( long a, long b )
{
  return longValue( Math.multiplyExact( a, b ) );
}
origin: prestodb/presto

public static long toMillis(long day, long hour, long minute, long second, long millis)
{
  try {
    long value = millis;
    value = addExact(value, multiplyExact(day, MILLIS_IN_DAY));
    value = addExact(value, multiplyExact(hour, MILLIS_IN_HOUR));
    value = addExact(value, multiplyExact(minute, MILLIS_IN_MINUTE));
    value = addExact(value, multiplyExact(second, MILLIS_IN_SECOND));
    return value;
  }
  catch (ArithmeticException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: prestodb/presto

public static long toMillis(long day, long hour, long minute, long second, long millis)
{
  try {
    long value = millis;
    value = addExact(value, multiplyExact(day, MILLIS_IN_DAY));
    value = addExact(value, multiplyExact(hour, MILLIS_IN_HOUR));
    value = addExact(value, multiplyExact(minute, MILLIS_IN_MINUTE));
    value = addExact(value, multiplyExact(second, MILLIS_IN_SECOND));
    return value;
  }
  catch (ArithmeticException e) {
    throw new IllegalArgumentException(e);
  }
}
origin: spring-projects/spring-framework

/**
 * Obtain a {@link DataSize} representing an amount in the specified {@link DataUnit}.
 * @param amount the amount of the size, measured in terms of the unit,
 * positive or negative
 * @return a corresponding {@link DataSize}
 */
public static DataSize of(long amount, DataUnit unit) {
  Assert.notNull(unit, "Unit must not be null");
  return new DataSize(Math.multiplyExact(amount, unit.size().toBytes()));
}
origin: prestodb/presto

@UsedByGeneratedCode
public static long tinyintToShortDecimal(long value, long precision, long scale, long tenToScale)
{
  try {
    long decimal = multiplyExact(value, tenToScale);
    if (overflows(decimal, intScale(precision))) {
      throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast TINYINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
    }
    return decimal;
  }
  catch (ArithmeticException e) {
    throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast TINYINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
  }
}
origin: prestodb/presto

@UsedByGeneratedCode
public static long bigintToShortDecimal(long value, long precision, long scale, long tenToScale)
{
  try {
    long decimal = multiplyExact(value, tenToScale);
    if (overflows(decimal, intScale(precision))) {
      throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast BIGINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
    }
    return decimal;
  }
  catch (ArithmeticException e) {
    throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast BIGINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
  }
}
origin: prestodb/presto

@UsedByGeneratedCode
public static long smallintToShortDecimal(long value, long precision, long scale, long tenToScale)
{
  try {
    long decimal = multiplyExact(value, tenToScale);
    if (overflows(decimal, intScale(precision))) {
      throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast SMALLINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
    }
    return decimal;
  }
  catch (ArithmeticException e) {
    throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast SMALLINT '%s' to DECIMAL(%s, %s)", value, precision, scale));
  }
}
origin: prestodb/presto

@UsedByGeneratedCode
public static long integerToShortDecimal(long value, long precision, long scale, long tenToScale)
{
  try {
    long decimal = multiplyExact(value, tenToScale);
    if (overflows(decimal, intScale(precision))) {
      throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast INTEGER '%s' to DECIMAL(%s, %s)", value, precision, scale));
    }
    return decimal;
  }
  catch (ArithmeticException e) {
    throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast INTEGER '%s' to DECIMAL(%s, %s)", value, precision, scale));
  }
}
origin: prestodb/presto

@ScalarOperator(MULTIPLY)
@SqlType(StandardTypes.BIGINT)
public static long multiply(@SqlType(StandardTypes.BIGINT) long left, @SqlType(StandardTypes.BIGINT) long right)
{
  try {
    return Math.multiplyExact(left, right);
  }
  catch (ArithmeticException e) {
    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("bigint multiplication overflow: %s * %s", left, right), e);
  }
}
origin: prestodb/presto

@ScalarOperator(MULTIPLY)
@SqlType(StandardTypes.INTEGER)
public static long multiply(@SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right)
{
  try {
    return Math.multiplyExact((int) left, (int) right);
  }
  catch (ArithmeticException e) {
    throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("integer multiplication overflow: %s * %s", left, right), e);
  }
}
origin: neo4j/neo4j

private List<RecordStresser> prepare( Condition condition, PagedFile pagedFile, RecordFormat format )
{
  int maxRecords = Math.multiplyExact( maxPages, format.getRecordsPerPage() );
  TinyLockManager locks = new TinyLockManager();
  List<RecordStresser> recordStressers = new LinkedList<>();
  for ( int threadId = 0; threadId < numberOfThreads; threadId++ )
  {
    recordStressers.add( new RecordStresser( pagedFile, condition, maxRecords, format, threadId, locks ) );
  }
  return recordStressers;
}
java.langMathmultiplyExact

Popular methods of Math

  • min
    Returns the smaller of two long values. That is, the result is the argument closer to the value of L
  • max
    Returns the greater of two long values. That is, the result is the argument closer to the value of L
  • abs
    Returns the absolute value of a long value. If the argument is not negative, the argument is returne
  • round
    Returns the closest int to the argument, with ties rounding up. Special cases: * If the argument is
  • pow
    Returns the value of the first argument raised to the power of the second argument. Special cases: *
  • sqrt
    Returns the correctly rounded positive square root of a double value. Special cases: * If the argume
  • ceil
    Returns the smallest (closest to negative infinity) double value that is greater than or equal to th
  • floor
    Returns the largest (closest to positive infinity) double value that is less than or equal to the ar
  • random
    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returne
  • sin
    Returns the trigonometric sine of an angle. Special cases: * If the argument is NaN or an infinit
  • cos
    Returns the trigonometric cosine of an angle. Special cases: * If the argument is NaN or an infin
  • log
    Returns the natural logarithm (base e) of a doublevalue. Special cases: * If the argument is NaN
  • cos,
  • log,
  • exp,
  • toRadians,
  • atan2,
  • log10,
  • acos,
  • tan,
  • toDegrees,
  • atan

Popular in Java

  • Reactive rest calls using spring rest template
  • getExternalFilesDir (Context)
  • getSharedPreferences (Context)
  • onCreateOptionsMenu (Activity)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Menu (java.awt)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • String (java.lang)
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Path (java.nio.file)
  • Top plugins for Android Studio
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