You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/10/11 15:50:38 UTC
[commons-rng] branch master updated: Detect endianness for raw64
debugging output.
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git
The following commit(s) were added to refs/heads/master by this push:
new 1e35cf1 Detect endianness for raw64 debugging output.
1e35cf1 is described below
commit 1e35cf12cf2fa078aa9c386ba84f7688ddfffe5d
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Oct 11 16:40:14 2019 +0100
Detect endianness for raw64 debugging output.
---
.../examples-stress/src/main/c/stdin2testu01.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/commons-rng-examples/examples-stress/src/main/c/stdin2testu01.c b/commons-rng-examples/examples-stress/src/main/c/stdin2testu01.c
index 383e54b..3def771 100644
--- a/commons-rng-examples/examples-stress/src/main/c/stdin2testu01.c
+++ b/commons-rng-examples/examples-stress/src/main/c/stdin2testu01.c
@@ -166,7 +166,6 @@ double nextDouble(void *par,
return nextInt(par, sta) / 4294967296.0;
}
-
static void dummy(void *sta) {
printf("N/A");
@@ -221,16 +220,31 @@ int main(int argc,
} else if (strcmp(spec, TU_B) == 0) {
bbattery_BigCrush(gen);
} else if (strcmp(spec, T_RAW_32) == 0) {
- // Print to stdout until stdin closes
+ /* Print to stdout until stdin closes. */
while (1) {
printInt(nextInt(0, gen->state));
}
} else if (strcmp(spec, T_RAW_64) == 0) {
- // Print to stdout until stdin closes
+ /* Detect endianness required to join two 32-bit values. */
+ uint32_t val = 0x01;
+ /*
+ * Use a raw view of the bytes with a char* to determine if
+ * the first byte is unset (big endian) or set (little endian).
+ */
+ char * buff = (char *)&val;
+
+ int littleEndian = (buff[0] != 0);
+
+ /* Print to stdout until stdin closes. */
while (1) {
+ /* Read 2 values. */
uint64_t hi = nextInt(0, gen->state);
uint64_t lo = nextInt(0, gen->state);
- printLong((hi << 32) | lo);
+ if (littleEndian) {
+ printLong((lo << 32) | hi);
+ } else {
+ printLong((hi << 32) | lo);
+ }
}
} else {
printf("[ERROR] Unknown specification: '%s'\n", spec);