forked from personal/squiggle.c
format squiggle.c
This commit is contained in:
parent
6247fbfb7b
commit
bebb7c6d46
24
squiggle.c
24
squiggle.c
|
@ -10,11 +10,9 @@
|
||||||
#define EXIT_ON_ERROR 0
|
#define EXIT_ON_ERROR 0
|
||||||
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
||||||
|
|
||||||
// PI constant
|
|
||||||
const float PI = 3.14159265358979323846; // M_PI in gcc gnu99
|
const float PI = 3.14159265358979323846; // M_PI in gcc gnu99
|
||||||
|
|
||||||
// Pseudo Random number generator
|
// Pseudo Random number generator
|
||||||
|
|
||||||
uint32_t xorshift32(uint32_t* seed)
|
uint32_t xorshift32(uint32_t* seed)
|
||||||
{
|
{
|
||||||
// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"
|
// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"
|
||||||
|
@ -30,7 +28,6 @@ uint32_t xorshift32(uint32_t* seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distribution & sampling functions
|
// Distribution & sampling functions
|
||||||
|
|
||||||
float rand_0_to_1(uint32_t* seed)
|
float rand_0_to_1(uint32_t* seed)
|
||||||
{
|
{
|
||||||
return ((float)xorshift32(seed)) / ((float)UINT32_MAX);
|
return ((float)xorshift32(seed)) / ((float)UINT32_MAX);
|
||||||
|
@ -128,16 +125,17 @@ struct box {
|
||||||
char* error_msg;
|
char* error_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct box process_error(const char* error_msg, int should_exit, char* file, int line){
|
struct box process_error(const char* error_msg, int should_exit, char* file, int line)
|
||||||
if(should_exit){
|
{
|
||||||
printf("@, in %s (%d)", file, line);
|
if (should_exit) {
|
||||||
exit(1);
|
printf("@, in %s (%d)", file, line);
|
||||||
}else{
|
exit(1);
|
||||||
char error_msg[MAX_ERROR_LENGTH];
|
} else {
|
||||||
snprintf(error_msg, MAX_ERROR_LENGTH, "@, in %s (%d)", file, line);
|
char error_msg[MAX_ERROR_LENGTH];
|
||||||
struct box error = { .empty = 1, .error_msg = error_msg };
|
snprintf(error_msg, MAX_ERROR_LENGTH, "@, in %s (%d)", file, line);
|
||||||
return error;
|
struct box error = { .empty = 1, .error_msg = error_msg };
|
||||||
}
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inverse cdf at point
|
// Inverse cdf at point
|
||||||
|
|
Loading…
Reference in New Issue
Block a user