Skip to content

Commit f699dc1

Browse files
committed
RandomNumberEngine: changed the return types of max() and min()
1 parent dea6518 commit f699dc1

5 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/main/java/com/github/stephengold/joltjni/std/DefaultRandomEngine.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,28 @@ public DefaultRandomEngine(int seed) {
6161
/**
6262
* Return the maximum value that can be generated.
6363
*
64-
* @return the maximum value
64+
* @return an unsigned 32-bit value
6565
*/
6666
@Override
67-
public int max() {
67+
public long max() {
6868
long generatorVa = va();
69-
int result = max(generatorVa);
69+
long result = max(generatorVa);
7070

71+
assert result >= 0L : result;
7172
return result;
7273
}
7374

7475
/**
7576
* Return the minimum value that can be generated.
7677
*
77-
* @return the minimum value
78+
* @return an unsigned 32-bit value
7879
*/
7980
@Override
80-
public int min() {
81+
public long min() {
8182
long generatorVa = va();
82-
int result = min(generatorVa);
83+
long result = min(generatorVa);
8384

85+
assert result >= 0L : result;
8486
return result;
8587
}
8688

@@ -130,9 +132,9 @@ public void seed(int value) {
130132

131133
native private static void free(long generatorVa);
132134

133-
native private static int max(long generatorVa);
135+
native private static long max(long generatorVa);
134136

135-
native private static int min(long generatorVa);
137+
native private static long min(long generatorVa);
136138

137139
native private static int nextInt(long generatorVa);
138140

src/main/java/com/github/stephengold/joltjni/std/Mt19937.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,28 @@ public Mt19937(int seed) {
5959
/**
6060
* Return the maximum value that can be generated.
6161
*
62-
* @return the maximum value
62+
* @return an unsigned 32-bit value
6363
*/
6464
@Override
65-
public int max() {
65+
public long max() {
6666
long generatorVa = va();
67-
int result = max(generatorVa);
67+
long result = max(generatorVa);
6868

69+
assert result >= 0L : result;
6970
return result;
7071
}
7172

7273
/**
7374
* Return the minimum value that can be generated.
7475
*
75-
* @return the minimum value
76+
* @return an unsigned 32-bit value
7677
*/
7778
@Override
78-
public int min() {
79+
public long min() {
7980
long generatorVa = va();
80-
int result = min(generatorVa);
81+
long result = min(generatorVa);
8182

83+
assert result >= 0L : result;
8284
return result;
8385
}
8486

@@ -128,9 +130,9 @@ public void seed(int value) {
128130

129131
native private static void free(long generatorVa);
130132

131-
native private static int max(long generatorVa);
133+
native private static long max(long generatorVa);
132134

133-
native private static int min(long generatorVa);
135+
native private static long min(long generatorVa);
134136

135137
native private static int nextInt(long generatorVa);
136138

src/main/java/com/github/stephengold/joltjni/std/RandomNumberEngine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public interface RandomNumberEngine extends ConstJoltPhysicsObject {
3535
/**
3636
* Return the maximum value that can be generated.
3737
*
38-
* @return the maximum value
38+
* @return an unsigned 32-bit value
3939
*/
40-
int max();
40+
long max();
4141

4242
/**
4343
* Return the minimum value that can be generated.
4444
*
45-
* @return the minimum value
45+
* @return an unsigned 32-bit value
4646
*/
47-
int min();
47+
long min();
4848

4949
/**
5050
* Return the next integer in the sequence.

src/main/native/glue/d/DefaultRandomEngine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngi
6060
/*
6161
* Class: com_github_stephengold_joltjni_std_DefaultRandomEngine
6262
* Method: max
63-
* Signature: (J)I
63+
* Signature: (J)J
6464
*/
65-
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngine_max
65+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngine_max
6666
(JNIEnv *, jclass, jlong generatorVa) {
6767
default_random_engine * const pGenerator
6868
= reinterpret_cast<default_random_engine *> (generatorVa);
@@ -73,9 +73,9 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngi
7373
/*
7474
* Class: com_github_stephengold_joltjni_std_DefaultRandomEngine
7575
* Method: min
76-
* Signature: (J)I
76+
* Signature: (J)J
7777
*/
78-
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngine_min
78+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_std_DefaultRandomEngine_min
7979
(JNIEnv *, jclass, jlong generatorVa) {
8080
default_random_engine * const pGenerator
8181
= reinterpret_cast<default_random_engine *> (generatorVa);

src/main/native/glue/m/Mt19937.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_std_Mt19937_free
6060
/*
6161
* Class: com_github_stephengold_joltjni_std_Mt19937
6262
* Method: max
63-
* Signature: (J)I
63+
* Signature: (J)J
6464
*/
65-
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_std_Mt19937_max
65+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_std_Mt19937_max
6666
(JNIEnv *, jclass, jlong generatorVa) {
6767
const mt19937 * const pGenerator = reinterpret_cast<mt19937 *> (generatorVa);
68-
const jint result = pGenerator->max();
68+
const mt19937::result_type result = pGenerator->max();
6969
return result;
7070
}
7171

7272
/*
7373
* Class: com_github_stephengold_joltjni_std_Mt19937
7474
* Method: min
75-
* Signature: (J)I
75+
* Signature: (J)J
7676
*/
77-
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_std_Mt19937_min
77+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_std_Mt19937_min
7878
(JNIEnv *, jclass, jlong generatorVa) {
7979
const mt19937 * const pGenerator = reinterpret_cast<mt19937 *> (generatorVa);
80-
const jint result = pGenerator->min();
80+
const mt19937::result_type result = pGenerator->min();
8181
return result;
8282
}
8383

0 commit comments

Comments
 (0)