After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 502560 - g_rand_double_range returns 'inf'
g_rand_double_range returns 'inf'
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-12-08 20:43 UTC by Tommi Komulainen
Modified: 2011-06-04 03:39 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tommi Komulainen 2007-12-08 20:43:45 UTC
g_rand_double_range(rand, -G_MAXDOUBLE, G_MAXDOUBLE) returns 'inf' on OSX 10.4. which is wrong.

It is triggered by the objecttests /properties/GtkHRuler test in gtk+ where the property tester tests a random double value for GtkRuler::lower property. The range for :lower is -G_MAXDOUBLE,G_MAXDOUBLE which is fed directly to g_test_rand_double_range() and thus the error.

I suppose either g_rand_double_range() needs fixing, or documentation updated to mention possible problems and the test framework take that into account.
Comment 1 Tim Janik 2007-12-11 10:32:10 UTC
(In reply to comment #0)
> g_rand_double_range(rand, -G_MAXDOUBLE, G_MAXDOUBLE) returns 'inf' on OSX 10.4.
> which is wrong.

> I suppose either g_rand_double_range() needs fixing, or documentation updated
> to mention possible problems and the test framework take that into account.

g_rand*() is a cross platform API, so should behave the same on all systems. in this case, a random number between -G_MAXDOUBLE and G_MAXDOUBLE should be returned and not inf.
sample test case:

linux$ gcc --version
gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
linux$ echo -e '#include <glib.h>\nint main(){ g_print ("rand: %g\\n", g_random_double_range (-G_MAXDOUBLE, G_MAXDOUBLE)); return 0; }' >x.c && gcc -Wall -O2 -g `pkg-config --cflags --libs glib-2.0` x.c && ./a.out
rand: -1.03339e+308

macos$ gcc --version
i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)
macos$ echo -e '#include <glib.h>\nint main(){ g_print ("rand: %g\\n", g_random_double_range (-G_MAXDOUBLE, G_MAXDOUBLE)); return 0; }' >x.c && gcc -Wall -O2 -g `pkg-config --cflags --libs glib-2.0` x.c && ./a.out
rand: inf