GNOME Bugzilla – Bug 502560
g_rand_double_range returns 'inf'
Last modified: 2011-06-04 03:39:21 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.
(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