mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 20:33:08 +02:00
GRand: avoid overflow
Otherwise, g_random_double_range (-G_MAXDOUBLE, G_MAXDOUBLE) doesn't work as expected. https://bugzilla.gnome.org/show_bug.cgi?id=502560
This commit is contained in:
parent
deed4dd36b
commit
77be95cdce
@ -586,7 +586,11 @@ g_rand_double (GRand* rand)
|
|||||||
gdouble
|
gdouble
|
||||||
g_rand_double_range (GRand* rand, gdouble begin, gdouble end)
|
g_rand_double_range (GRand* rand, gdouble begin, gdouble end)
|
||||||
{
|
{
|
||||||
return g_rand_double (rand) * (end - begin) + begin;
|
gdouble r;
|
||||||
|
|
||||||
|
r = g_rand_double (rand);
|
||||||
|
|
||||||
|
return r * end - (r - 1) * begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user