chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] passing variable number of floats to C


From: Kon Lovett
Subject: Re: [Chicken-users] passing variable number of floats to C
Date: Tue, 19 Feb 2008 12:09:29 -0800


On Feb 19, 2008, at 11:32 AM, Heinrich Taube wrote:

thanks, i see now. since its a list it would be nice from the users perspective to be able to pass immediate ints in addition to floats without having to cons the floats on the scheme side. so on the c side ill have to make sure that the car is either an int or a float before i access it -- ive been poking around in the doc but dont see any obvious predicates to do this.

The "C Interface" section (http://galinha.ucpel.tche.br/C% 20interface) is incomplete. This should be a To Do item. For now look in the source @ "chicken.h".

can you please point me in the right direction? thanks for your help!

for ( ; C_SCHEME_END_OF_LIST != lyst; lyst = C_u_i_cdr( lyst )) {
 if ( IS_INT(C_u_i_car(lyst)) )
   sum += (double)C_u_i_car(lyst) ;
 else if ( IS_FLOAT(C_u_i_car(lyst))
   sum += C_u_i_car(lyst) ;
}



/*
C_truep used here since the predicate macros - F_foop - have Chicken Scheme boolean results,
not C.
*/

double sum = 0.0;
for ( ; C_SCHEME_END_OF_LIST != lyst; lyst = C_u_i_cdr( lyst )) {
    C_word word = C_u_i_car( lyst );
    if (C_truep( C_flonump( word ) )) {
        sum += C_flonum_magnitude( word );
    } else if (C_truep( C_fixnump( word ) )) {
        sum += (double) C_unfix( word );
    }
}

If we were only interested in integers then "C_num_to_int" could be used.



But this works:

#>
static double
double_sum( C_word lyst )
{
  double sum = 0.0;
  for ( ; C_SCHEME_END_OF_LIST != lyst; lyst = C_u_i_cdr( lyst )) {
    sum += C_flonum_magnitude( C_u_i_car( lyst ) );
  }
  return sum;
}
<#

Best Wishes,
Kon






reply via email to

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