--- mtwist.h.orig 2013-06-13 08:22:03.618758633 +0200
+++ mtwist.h 2017-08-26 17:00:01.764590668 +0200
@@ -289,9 +289,12 @@
extern double mts_drand(mt_state* state);
/* Generate floating value, any gen. */
/* Fast, with only 32-bit precision */
-extern double mts_ldrand(mt_state* state);
+extern NVTYPE mts_ldrand(mt_state* state);
/* Generate floating value, any gen. */
/* Slower, with 64-bit precision */
+extern NVTYPE mts_lldrand(mt_state* state);
+ /* Generate floating value, any gen. */
+ /* Slower, with 128-bit precision */
extern uint32_t mt_lrand(void); /* Generate 32-bit random value */
#ifdef UINT64_MAX
@@ -301,7 +304,7 @@
extern double mt_drand(void);
/* Generate floating value */
/* Fast, with only 32-bit precision */
-extern double mt_ldrand(void);
+extern NVTYPE mt_ldrand(void);
/* Generate floating value */
/* Slower, with 64-bit precision */
@@ -363,8 +366,10 @@
/* State of the default generator */
extern double mt_32_to_double;
/* Multiplier to convert long to dbl */
-extern double mt_64_to_double;
+extern NVTYPE mt_64_to_double;
/* Mult'r to cvt long long to dbl */
+extern NVTYPE mt_96_to_double;
+extern NVTYPE mt_128_to_double;
/*
* In gcc, inline functions must be declared extern or they'll produce
@@ -502,7 +507,7 @@
* (exclusive). This function generates 64 bits of precision. Use
* mts_drand for more speed but less precision.
*/
-MT_EXTERN MT_INLINE double mts_ldrand(
+MT_EXTERN MT_INLINE NVTYPE mts_ldrand(
register mt_state* state) /* State for the PRNG */
{
#ifdef UINT64_MAX
@@ -541,10 +546,40 @@
final_value = ((uint64_t) random_value_1 << 32) | (uint64_t) random_value_2;
return final_value * mt_64_to_double;
#else /* UINT64_MAX */
- return random_value_1 * mt_32_to_double + random_value_2 * mt_64_to_double;
+ return random_value_1 * (NVTYPE)mt_32_to_double + random_value_2 * mt_64_to_double;
#endif /* UINT64_MAX */
}
+MT_EXTERN MT_INLINE NVTYPE mts_lldrand(
+ register mt_state* state) /* State for the PRNG */
+ {
+ unsigned i;
+ uint32_t rv[4]; /* Pseudorandom values generated */
+ uint32_t* rvp = rv;
+
+ for (i = 0; i < 4; i++) {
+ if (state->stateptr <= 0)
+ mts_refresh(state);
+
+ *rvp = state->statevec[--state->stateptr];
+ MT_TEMPER(*rvp);
+ rvp++;
+ }
+
+#ifdef UINT64_MAX
+ return
+ ((uint64_t)rv[0] << 32 | (uint64_t)rv[1]) * mt_64_to_double +
+ ((uint64_t)rv[2] << 32 | (uint64_t)rv[3]) * mt_128_to_double;
+#else
+ return rv[0] * (NVTYPE)mt_32_to_double + rv[1] * mt_64_to_double + rv[2] * mt_96_to_double + rv[3] * mt_128_to_double;
+#endif
+ }
+
+MT_EXTERN MT_INLINE NVTYPE mt_lldrand(void)
+ {
+ return mts_lldrand(&mt_default_state);
+ }
+
/*
* Generate a random number in the range 0 to 2^32-1, inclusive, working
* from the default state vector.
@@ -632,7 +667,7 @@
* (exclusive). This function generates 64 bits of precision. Use
* mts_drand for more speed but less precision.
*/
-MT_EXTERN MT_INLINE double mt_ldrand(void)
+MT_EXTERN MT_INLINE NVTYPE mt_ldrand(void)
{
#ifdef UINT64_MAX
uint64_t final_value; /* Final (integer) value */
@@ -672,7 +707,7 @@
final_value = ((uint64_t) random_value_1 << 32) | (uint64_t) random_value_2;
return final_value * mt_64_to_double;
#else /* UINT64_MAX */
- return random_value_1 * mt_32_to_double + random_value_2 * mt_64_to_double;
+ return random_value_1 * (NVTYPE)mt_32_to_double + random_value_2 * mt_64_to_double;
#endif /* UINT64_MAX */
}
#endif /* MT_GENERATE_CODE_IN_HEADER */
@@ -778,7 +813,7 @@
{
return mts_drand(&state);
}
- double ldrand() // Generate slow 64-bit floating value
+ NVTYPE ldrand() // Generate slow 64-bit floating value
{
return mts_ldrand(&state);
}
@@ -793,7 +828,7 @@
* // ...
* coinFlip = ranno() >= 0.5 ? heads : tails;
*/
- double operator()()
+ NVTYPE operator()()
{
return mts_drand(&state);
}