[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] [bug #25413] [patch] monte test failure under mingw

From: Guido De Rosa
Subject: [Bug-gsl] [bug #25413] [patch] monte test failure under mingw
Date: Mon, 02 Feb 2009 02:24:45 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv: Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)

Follow-up Comment #8, bug #25413 (project gsl):

Another patch (vegas-types.diff). 

As far as I tested it fixes the problem, and it's not a workaround. 

Looking at the original monte/vegas.c :

181:  {
182:    double tot_boxes = pow ((double) boxes, (double) dim);
183:    state->calls_per_box = GSL_MAX (calls / tot_boxes, 2);
184:    calls = state->calls_per_box * tot_boxes;
185:  }

* two integers are casted to double, in order to call pow() and assign the
result to another double (line 182)

* an integer is divided by a double, then compared to an integer constant,
and the result is assigned to an integer (line 183)

* the product of an integer and a double is assigned to an integer (line

I agree that FPU issues may lead only to *tiny*, platform-dependent
inaccuracies but... when floating-point variables are mixed/implicitly
converted to integers, errors get sometimes amplified and sometimes hidden.

A trivial example: convert 1.499999999999 and 1.500000000001 to the nearest
integer, and what you get? 1 and 2, which is a *huge* discrepancy!

Even better than my patch, a kind of gsl_int_pow_uint() should be implemented
to calculate an integer elevated to a an unsigned int power, returning another

int gsl_int_pow_uint(int x, unsigned int n);
unsigned int gsl_uint_pow_uint(unsigned int x, unsigned int n);
/* with long int variants, etc. */

So, the above lines of vegas.c would look like:

        unsigned int tot_boxes = gsl_uint_pow_uint (boxes, dim);
        state->calls_per_box = GSL_MAX (calls / tot_boxes, 2);
        calls = state->calls_per_box * tot_boxes;

which is clean code, with no type messing at all.

(file #17380)

Additional Item Attachment:

File name: vegas-types.diff               Size:0 KB


Reply to this item at:


  Messaggio inviato con/da Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]