summaryrefslogtreecommitdiff
path: root/util.c
blob: d38c331f6c71ceb0082ff471cc51cfd1e3e5eba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//a collection of utility methods

#include "snowglobe-internal.h"
#include <math.h>
#include <float.h>


float
randf (float x)
{ //return random number in range [0,x)
    return rand()/(((double)RAND_MAX + 1) / x);
}

float
minimum (float x, float y)
{
    return ((x) < (y) ? (x) : (y));
}

float
maximum (float x, float y)
{
    return ((x) > (y) ? (x) : (y));
}

float
symmDistr()
{ //returns number in range [-1, 1] with bias towards 0, symmetric about 0.
    float x = 2*randf(1)-1;
    return x*(1-cbrt(1-fabsf(x)));
}