本文整理了Java中java.lang.Math.addExact()
方法的一些代码示例,展示了Math.addExact()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.addExact()
方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:addExact
暂无
代码示例来源:origin: neo4j/neo4j
public void increment( long count )
{
this.count = Math.addExact( this.count, count );
}
代码示例来源:origin: neo4j/neo4j
private long secondsWithNanos( long seconds, long nanos )
{
return Math.addExact( seconds, nanos / NANOS_PER_SECOND );
}
代码示例来源:origin: neo4j/neo4j
private long offset( long position )
{
if ( position < 0 )
{
throw new IllegalArgumentException( "Position must be >= 0." );
}
return Math.addExact( position, offset );
}
代码示例来源:origin: prestodb/presto
static long addExact(long usedBytes, long bytes)
{
try {
return Math.addExact(usedBytes, bytes);
}
catch (ArithmeticException e) {
throw new RuntimeException(format("Overflow detected. usedBytes: %d, bytes: %d", usedBytes, bytes), e);
}
}
}
代码示例来源:origin: prestodb/presto
@Override
public void addValue(long value)
{
nonNullValueCount++;
minimum = Math.min(value, minimum);
maximum = Math.max(value, maximum);
if (!overflow) {
try {
sum = addExact(sum, value);
}
catch (ArithmeticException e) {
overflow = true;
}
}
}
代码示例来源: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: apache/flink
/**
* Constructs a Deadline that is a given duration after now.
*/
public static Deadline fromNow(Duration duration) {
return new Deadline(Math.addExact(System.nanoTime(), duration.toNanos()));
}
}
代码示例来源: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: 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 addition of two longs
*
* @param a left-hand operand
* @param b right-hand operand
* @return a + b
*/
public static LongValue add( long a, long b )
{
return longValue( Math.addExact( a, b ) );
}
代码示例来源:origin: apache/flink
public Deadline plus(Duration other) {
return new Deadline(Math.addExact(timeNanos, other.toNanos()));
}
代码示例来源:origin: prestodb/presto
@UsedByGeneratedCode
public static int checkedAdd(int x, int y)
{
try {
return addExact(x, y);
}
catch (ArithmeticException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Concatenated string is too large");
}
}
}
代码示例来源:origin: prestodb/presto
public void add(Page page)
{
checkState(canAdd(page), "page buffer is full");
pages.add(page);
usedMemoryBytes += page.getRetainedSizeInBytes();
rowCount = addExact(rowCount, page.getPositionCount());
}
代码示例来源:origin: neo4j/neo4j
public IndexSample combine( IndexSample sample1, IndexSample sample2 )
{
long indexSize = Math.addExact( sample1.indexSize(), sample2.indexSize() );
long uniqueValues = Math.addExact( sample1.uniqueValues(), sample2.uniqueValues() );
long sampleSize = Math.addExact( sample1.sampleSize(), sample2.sampleSize() );
return new IndexSample( indexSize, uniqueValues, sampleSize );
}
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(ADD)
@SqlType(StandardTypes.BIGINT)
public static long add(@SqlType(StandardTypes.BIGINT) long left, @SqlType(StandardTypes.BIGINT) long right)
{
try {
return Math.addExact(left, right);
}
catch (ArithmeticException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("bigint addition overflow: %s + %s", left, right), e);
}
}
代码示例来源:origin: prestodb/presto
@ScalarOperator(ADD)
@SqlType(StandardTypes.INTEGER)
public static long add(@SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right)
{
try {
return Math.addExact((int) left, (int) right);
}
catch (ArithmeticException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("integer addition overflow: %s + %s", left, right), e);
}
}
代码示例来源:origin: prestodb/presto
@SqlType(StandardTypes.INTEGER)
public static long add(
@SqlType(StandardTypes.INTEGER) long left,
@SqlType(StandardTypes.INTEGER) long right)
{
return Math.addExact((int) left, (int) right);
}
代码示例来源:origin: prestodb/presto
@SqlType(StandardTypes.INTEGER)
public static long addBlockPosition(
@SqlType(StandardTypes.INTEGER) long first,
@BlockPosition @SqlType(value = StandardTypes.INTEGER, nativeContainerType = long.class) Block block,
@BlockIndex int position)
{
return Math.addExact((int) first, (int) INTEGER.getLong(block, position));
}
}
内容来源于网络,如有侵权,请联系作者删除!