Octopus
quickrnd.c File Reference

Go to the source code of this file.

Typedefs

typedef signed char int8_t
 
typedef short int int16_t
 
typedef int int32_t
 
typedef long int int64_t
 
typedef unsigned char uint8_t
 
typedef short unsigned int uint16_t
 
typedef unsigned int uint32_t
 
typedef long unsigned int uint64_t
 
typedef signed char int_least8_t
 
typedef short int int_least16_t
 
typedef int int_least32_t
 
typedef long int int_least64_t
 
typedef unsigned char uint_least8_t
 
typedef short unsigned int uint_least16_t
 
typedef unsigned int uint_least32_t
 
typedef long unsigned int uint_least64_t
 
typedef signed char int_fast8_t
 
typedef long int int_fast16_t
 
typedef long int int_fast32_t
 
typedef long int int_fast64_t
 
typedef unsigned char uint_fast8_t
 
typedef long unsigned int uint_fast16_t
 
typedef long unsigned int uint_fast32_t
 
typedef long unsigned int uint_fast64_t
 
typedef long int intptr_t
 
typedef long unsigned int uintptr_t
 
typedef long int intmax_t
 
typedef long unsigned int uintmax_t
 

Functions

void __assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) __attribute__((__nothrow__
 
void __leaf__ __attribute__ ((__noreturn__))
 
void __assert_perror_fail (int __errnum, const char *__file, unsigned int __line, const char *__function) __attribute__((__nothrow__
 
void __assert (const char *__assertion, const char *__file, int __line) __attribute__((__nothrow__
 
double u64_to_open01 (const uint64_t x)
 Convert a 64-bit unsigned integer to a double in the open interval (0, 1). More...
 
double i64_to_open01 (const int64_t x)
 Convert a 64-bit signed integer to a double in (0, 1). More...
 
uint64_t splitmix64_mixer (const uint64_t x)
 Mix a 64-bit integer using the SplitMix64 mixer. More...
 
uint64_t splitmix64_mixer_2pow63 (const uint64_t x)
 Mix a 64-bit integer using the SplitMix64 mixer. More...
 
uint64_t hash_combine_ids (const uint64_t *ids, const uint32_t n)
 Mix an array of 64-bit integer IDs into a single deterministic 64-bit value. More...
 

Variables

static const uint64_t GOLDEN_RATIO = 0x9e3779b97f4a7c15ULL
 
static const double two_powm52 = 0x1.0p-52
 
static const double two_powm53 = 0x1.0p-53
 

Typedef Documentation

◆ int8_t

typedef signed char int8_t

Definition at line 43 of file quickrnd.c.

◆ int16_t

typedef short int int16_t

Definition at line 46 of file quickrnd.c.

◆ int32_t

typedef int int32_t

Definition at line 49 of file quickrnd.c.

◆ int64_t

typedef long int int64_t

Definition at line 52 of file quickrnd.c.

◆ uint8_t

typedef unsigned char uint8_t

Definition at line 55 of file quickrnd.c.

◆ uint16_t

typedef short unsigned int uint16_t

Definition at line 58 of file quickrnd.c.

◆ uint32_t

typedef unsigned int uint32_t

Definition at line 61 of file quickrnd.c.

◆ uint64_t

typedef long unsigned int uint64_t

Definition at line 64 of file quickrnd.c.

◆ int_least8_t

typedef signed char int_least8_t

Definition at line 69 of file quickrnd.c.

◆ int_least16_t

typedef short int int_least16_t

Definition at line 70 of file quickrnd.c.

◆ int_least32_t

typedef int int_least32_t

Definition at line 71 of file quickrnd.c.

◆ int_least64_t

typedef long int int_least64_t

Definition at line 72 of file quickrnd.c.

◆ uint_least8_t

typedef unsigned char uint_least8_t

Definition at line 73 of file quickrnd.c.

◆ uint_least16_t

typedef short unsigned int uint_least16_t

Definition at line 74 of file quickrnd.c.

◆ uint_least32_t

typedef unsigned int uint_least32_t

Definition at line 75 of file quickrnd.c.

◆ uint_least64_t

typedef long unsigned int uint_least64_t

Definition at line 76 of file quickrnd.c.

◆ int_fast8_t

typedef signed char int_fast8_t

Definition at line 80 of file quickrnd.c.

◆ int_fast16_t

typedef long int int_fast16_t

Definition at line 81 of file quickrnd.c.

◆ int_fast32_t

typedef long int int_fast32_t

Definition at line 82 of file quickrnd.c.

◆ int_fast64_t

typedef long int int_fast64_t

Definition at line 83 of file quickrnd.c.

◆ uint_fast8_t

typedef unsigned char uint_fast8_t

Definition at line 84 of file quickrnd.c.

◆ uint_fast16_t

typedef long unsigned int uint_fast16_t

Definition at line 85 of file quickrnd.c.

◆ uint_fast32_t

typedef long unsigned int uint_fast32_t

Definition at line 86 of file quickrnd.c.

◆ uint_fast64_t

typedef long unsigned int uint_fast64_t

Definition at line 87 of file quickrnd.c.

◆ intptr_t

typedef long int intptr_t

Definition at line 92 of file quickrnd.c.

◆ uintptr_t

typedef long unsigned int uintptr_t

Definition at line 95 of file quickrnd.c.

◆ intmax_t

typedef long int intmax_t

Definition at line 100 of file quickrnd.c.

◆ uintmax_t

typedef long unsigned int uintmax_t

Definition at line 101 of file quickrnd.c.

Function Documentation

◆ __assert_fail()

void __assert_fail ( const char *  __assertion,
const char *  __file,
unsigned int  __line,
const char *  __function 
)

◆ __attribute__()

void __leaf__ __attribute__ ( (__noreturn__)  )

◆ __assert_perror_fail()

void __assert_perror_fail ( int  __errnum,
const char *  __file,
unsigned int  __line,
const char *  __function 
)

◆ __assert()

void __assert ( const char *  __assertion,
const char *  __file,
int  __line 
)

◆ u64_to_open01()

double u64_to_open01 ( const uint64_t  x)

Convert a 64-bit unsigned integer to a double in the open interval (0, 1).

This function uses the upper 52 bits of the input value x to construct a uniformly distributed IEEE-754 double-precision value in the interval (2^-53, 1 - 2^-53), which is a strict subset of (0, 1). The distribution of outputs is uniform over the 2^52 possible results, assuming x is uniformly distributed.

Parameters
x64-bit input value, typically from a uniform RNG. Only the upper 52 bits are used; the lower 12 bits are ignored.
Returns
A double-precision value strictly inside the interval (0, 1).

Definition at line 929 of file quickrnd.c.

◆ i64_to_open01()

double i64_to_open01 ( const int64_t  x)

Convert a 64-bit signed integer to a double in (0, 1).

This function interprets the two's-complement bit pattern of x as an unsigned 64-bit integer and forwards to u64_to_open01().

Parameters
x64-bit signed input value, typically from a uniform RNG. Only the upper 52 bits are used; the lower 12 bits are ignored.
Returns
A double-precision value strictly inside the interval (0, 1).
See also
u64_to_open01

Definition at line 945 of file quickrnd.c.

◆ splitmix64_mixer()

uint64_t splitmix64_mixer ( const uint64_t  x)

Mix a 64-bit integer using the SplitMix64 mixer.

Adapted from https://xorshift.di.unimi.it/splitmix64.c This is the fixed-increment mixing function from Java 8's SplittableRandom. References:

This mixer is very fast, passes BigCrush, and is useful when you want a high-quality 64-bit input diffusion function.

Parameters
xThe 64-bit input value to be mixed.
Returns
A well-scrambled 64-bit result.

Definition at line 966 of file quickrnd.c.

◆ splitmix64_mixer_2pow63()

uint64_t splitmix64_mixer_2pow63 ( const uint64_t  x)

Mix a 64-bit integer using the SplitMix64 mixer.

Adapted from https://xorshift.di.unimi.it/splitmix64.c This is the fixed-increment mixing function from Java 8's SplittableRandom. References:

This mixer is very fast, passes BigCrush, and is useful when you want a high-quality 64-bit input diffusion function.

Parameters
xThe 64-bit input value to be mixed.
Returns
A well-scrambled 64-bit result in the range [0, 2^{63} - 1] such that a fortran caller will always get a positive number.

Definition at line 989 of file quickrnd.c.

◆ hash_combine_ids()

uint64_t hash_combine_ids ( const uint64_t *  ids,
const uint32_t  n 
)

Mix an array of 64-bit integer IDs into a single deterministic 64-bit value.

Parameters
idsArray of 64-bit ids to be mixed.
nNumber of elements in ids.
Returns
s Single, deterministic integer in the range [0, 2^{63} - 1], such that a fortran caller will always get a positive number.

Definition at line 1002 of file quickrnd.c.

Variable Documentation

◆ GOLDEN_RATIO

const uint64_t GOLDEN_RATIO = 0x9e3779b97f4a7c15ULL
static

Definition at line 908 of file quickrnd.c.

◆ two_powm52

const double two_powm52 = 0x1.0p-52
static

Definition at line 911 of file quickrnd.c.

◆ two_powm53

const double two_powm53 = 0x1.0p-53
static

Definition at line 914 of file quickrnd.c.