Its happening when you case gsl_sf_choose() to (int). Try this instead:

int nchoosetwo_gsl = (int) round(gsl_sf_choose(n,2))

On 08/02/2016 06:34 AM, Eldon, Bjarki wrote:
Dear GSL,

I'm using GSL  version 1.16-5.1.3 on  openSUSE-13.2-Oss  on x86_64 arch.


the C code  below  returns a lot of 1s; is there a bug in gsl_sf_choose or am I 
doing something wrong?

best regards
bjarki


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_elementary.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_sf_exp.h>



int main()
{
   unsigned int n ;
   int nchoosetwo ;

   for( n = 2 ; n <= 102 ; n++){
     nchoosetwo = (int) ( ( (double)( n*(n-1)) )/2. ) ;

     printf( "%d:  %d\n", n, (nchoosetwo != (int)gsl_sf_choose( n,2)) ? 1 : 0 
); }

   return GSL_SUCCESS;

}





Reply via email to