mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8285658: Fix two typos in the spec of j.u.random.RandomGenerator
Reviewed-by: bpb, darcy
This commit is contained in:
parent
8a16842b4e
commit
1f868f1d09
1 changed files with 9 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -55,7 +55,8 @@ import java.util.stream.Stream;
|
||||||
* possible values of the type. In the case of {@code float} and {@code double}
|
* possible values of the type. In the case of {@code float} and {@code double}
|
||||||
* values, first a value is always chosen uniformly from the set of
|
* values, first a value is always chosen uniformly from the set of
|
||||||
* 2<sup><i>w</i></sup> values between 0.0 (inclusive) and 1.0 (exclusive),
|
* 2<sup><i>w</i></sup> values between 0.0 (inclusive) and 1.0 (exclusive),
|
||||||
* where <i>w</i> is 23 for {@code float} values and 52 for {@code double}
|
* where <i>w</i> is {@link Float#PRECISION} for {@code float} values
|
||||||
|
* and {@link Double#PRECISION} for {@code double}
|
||||||
* values, such that adjacent values differ by 2<sup>−<i>w</i></sup>
|
* values, such that adjacent values differ by 2<sup>−<i>w</i></sup>
|
||||||
* (notice that this set is a <i>subset</i> of the set of
|
* (notice that this set is a <i>subset</i> of the set of
|
||||||
* <i>all representable floating-point values</i> between 0.0 (inclusive) and 1.0 (exclusive));
|
* <i>all representable floating-point values</i> between 0.0 (inclusive) and 1.0 (exclusive));
|
||||||
|
@ -496,11 +497,11 @@ public interface RandomGenerator {
|
||||||
*
|
*
|
||||||
* @return a pseudorandom {@code float} value between zero (inclusive) and one (exclusive)
|
* @return a pseudorandom {@code float} value between zero (inclusive) and one (exclusive)
|
||||||
*
|
*
|
||||||
* @implSpec The default implementation uses the 24 high-order bits from a call to
|
* @implSpec The default implementation uses the {@link Float#PRECISION}
|
||||||
* {@link RandomGenerator#nextInt() nextInt}().
|
* high-order bits from a call to {@link RandomGenerator#nextInt() nextInt()}.
|
||||||
*/
|
*/
|
||||||
default float nextFloat() {
|
default float nextFloat() {
|
||||||
return (nextInt() >>> 8) * 0x1.0p-24f;
|
return (nextInt() >>> (Float.SIZE - Float.PRECISION)) * 0x1.0p-24f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -562,11 +563,11 @@ public interface RandomGenerator {
|
||||||
* @return a pseudorandom {@code double} value between zero (inclusive)
|
* @return a pseudorandom {@code double} value between zero (inclusive)
|
||||||
* and one (exclusive)
|
* and one (exclusive)
|
||||||
*
|
*
|
||||||
* @implSpec The default implementation uses the 53 high-order bits from a call to
|
* @implSpec The default implementation uses the {@link Double#PRECISION}
|
||||||
* {@link RandomGenerator#nextLong nextLong}().
|
* high-order bits from a call to {@link RandomGenerator#nextLong() nextLong()}.
|
||||||
*/
|
*/
|
||||||
default double nextDouble() {
|
default double nextDouble() {
|
||||||
return (nextLong() >>> 11) * 0x1.0p-53;
|
return (nextLong() >>> (Double.SIZE - Double.PRECISION)) * 0x1.0p-53;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue