java.lang.Math.max()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中java.lang.Math.max()方法的一些代码示例,展示了Math.max()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.max()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:max

Math.max介绍

[英]Returns the most positive (closest to positive infinity) of the two arguments.

Special cases:

  • max(NaN, (anything)) = NaN
  • max((anything), NaN) = NaN
  • max(+0.0, -0.0) = +0.0
  • max(-0.0, +0.0) = +0.0
    [中]返回两个参数中最正的(最接近正无穷大)。
    特殊情况:
    *max(NaN,(任何事物))=NaN
    *max((任何),NaN)=NaN
    *最大值(+0.0,-0.0)=+0.0
    *最大值(-0.0,+0.0)=+0.0

代码示例

代码示例来源:origin: stackoverflow.com

jQuery.fn.center = function () {
  this.css("position","absolute");
  this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + 
                        $(window).scrollTop()) + "px");
  this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + 
                        $(window).scrollLeft()) + "px");
  return this;
}

代码示例来源:origin: ReactiveX/RxJava

public ObservableConcatMap(ObservableSource<T> source, Function<? super T, ? extends ObservableSource<? extends U>> mapper,
    int bufferSize, ErrorMode delayErrors) {
  super(source);
  this.mapper = mapper;
  this.delayErrors = delayErrors;
  this.bufferSize = Math.max(8, bufferSize);
}

代码示例来源:origin: google/guava

long longSize() {
 Segment<K, V>[] segments = this.segments;
 long sum = 0;
 for (int i = 0; i < segments.length; ++i) {
  sum += Math.max(0, segments[i].count); // see https://github.com/google/guava/issues/2108
 }
 return sum;
}

代码示例来源:origin: google/guava

@Override
 public int size() {
  return Math.max(0, super.size() + delta);
 }
};

代码示例来源:origin: google/guava

static int closedTableSize(int expectedEntries, double loadFactor) {
 // Get the recommended table size.
 // Round down to the nearest power of 2.
 expectedEntries = Math.max(expectedEntries, 2);
 int tableSize = Integer.highestOneBit(expectedEntries);
 // Check to make sure that we will not exceed the maximum load factor.
 if (expectedEntries > (int) (loadFactor * tableSize)) {
  tableSize <<= 1;
  return (tableSize > 0) ? tableSize : MAX_TABLE_SIZE;
 }
 return tableSize;
}

代码示例来源:origin: ReactiveX/RxJava

MergeSubscriber(Subscriber<? super U> actual, Function<? super T, ? extends Publisher<? extends U>> mapper,
    boolean delayErrors, int maxConcurrency, int bufferSize) {
  this.downstream = actual;
  this.mapper = mapper;
  this.delayErrors = delayErrors;
  this.maxConcurrency = maxConcurrency;
  this.bufferSize = bufferSize;
  this.scalarLimit = Math.max(1, maxConcurrency >> 1);
  subscribers.lazySet(EMPTY);
}

代码示例来源:origin: google/guava

private AvlNode<E> addRightChild(E e, int count) {
 right = new AvlNode<E>(e, count);
 successor(this, right, succ);
 height = Math.max(2, height);
 distinctElements++;
 totalCount += count;
 return this;
}

代码示例来源:origin: google/guava

private AvlNode<E> addLeftChild(E e, int count) {
 left = new AvlNode<E>(e, count);
 successor(pred, left, this);
 height = Math.max(2, height);
 distinctElements++;
 totalCount += count;
 return this;
}

代码示例来源:origin: google/guava

/**
 * Reserves next ticket and returns the wait time that the caller must wait for.
 *
 * @return the required wait time, never negative
 */
final long reserveAndGetWaitLength(int permits, long nowMicros) {
 long momentAvailable = reserveEarliestAvailable(permits, nowMicros);
 return max(momentAvailable - nowMicros, 0);
}

代码示例来源:origin: google/guava

@Override
 protected Set<String> create(String[] elements) {
  ImmutableSet.Builder<String> builder =
    ImmutableSet.builderWithExpectedSize(Math.max(0, Sets.newHashSet(elements).size() - 1));
  for (String e : elements) {
   builder.add(e);
  }
  return builder.build();
 }
}

代码示例来源:origin: google/guava

@Override
int maxEncodedSize(int bytes) {
 int unseparatedSize = delegate.maxEncodedSize(bytes);
 return unseparatedSize
   + separator.length() * divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR);
}

代码示例来源:origin: google/guava

/** Pseudoconstructor for serialization support. */
void init(int expectedSize, float loadFactor) {
 Preconditions.checkArgument(expectedSize >= 0, "Initial capacity must be non-negative");
 Preconditions.checkArgument(loadFactor > 0, "Illegal load factor");
 int buckets = Hashing.closedTableSize(expectedSize, loadFactor);
 this.table = newTable(buckets);
 this.loadFactor = loadFactor;
 this.elements = new Object[expectedSize];
 this.entries = newEntries(expectedSize);
 this.threshold = Math.max(1, (int) (buckets * loadFactor));
}

代码示例来源:origin: ReactiveX/RxJava

public SpscLinkedArrayQueue(final int bufferSize) {
  int p2capacity = Pow2.roundToPowerOfTwo(Math.max(8, bufferSize));
  int mask = p2capacity - 1;
  AtomicReferenceArray<Object> buffer = new AtomicReferenceArray<Object>(p2capacity + 1);
  producerBuffer = buffer;
  producerMask = mask;
  adjustLookAheadStep(p2capacity);
  consumerBuffer = buffer;
  consumerMask = mask;
  producerLookAhead = mask - 1; // we know it's all empty to start with
  soProducerIndex(0L);
}

代码示例来源:origin: google/guava

@Override
public int count(@Nullable Object element) {
 int count1 = multiset1.count(element);
 return (count1 == 0) ? 0 : Math.max(0, count1 - multiset2.count(element));
}

代码示例来源:origin: google/guava

private static long worstCaseQueryOperations(Map<?, ?> map, CallsCounter counter) {
  long worstCalls = 0;
  for (Object k : map.keySet()) {
   counter.zero();
   Object unused = map.get(k);
   worstCalls = Math.max(worstCalls, counter.total());
  }
  return worstCalls;
 }
}

代码示例来源:origin: google/guava

private long measureTotalTimeMillis(RateLimiter rateLimiter, int permits, Random random) {
 long startTime = stopwatch.instant;
 while (permits > 0) {
  int nextPermitsToAcquire = Math.max(1, random.nextInt(permits));
  permits -= nextPermitsToAcquire;
  rateLimiter.acquire(nextPermitsToAcquire);
 }
 rateLimiter.acquire(1); // to repay for any pending debt
 return NANOSECONDS.toMillis(stopwatch.instant - startTime);
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_REMOVE)
public void testKeysRemove() {
 int original = multimap().keys().remove(k0(), 1);
 assertEquals(Math.max(original - 1, 0), multimap().get(k0()).size());
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Integer> createPublisher(long elements) {
    return
        Flowable.range(1, Math.max(0, (int)elements - 1))
        .concatWith(Single.just((int)elements))
      ;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Publisher<Integer> createPublisher(long elements) {
    return
        Flowable.range(1, Math.max(0, (int)elements - 1))
        .concatWith(Maybe.just((int)elements))
      ;
  }
}

代码示例来源:origin: google/guava

private static long worstCaseQueryOperations(Multiset<?> multiset, CallsCounter counter) {
  long worstCalls = 0;
  for (Object k : multiset.elementSet()) {
   counter.zero();
   int unused = multiset.count(k);
   worstCalls = Math.max(worstCalls, counter.total());
  }
  return worstCalls;
 }
}

相关文章