c_src/hyper_carray.c
/*
 * Sum over 2^-X where X is the value of each item in the given hyper_carray.
 */
Sum over 2^-X where X is the value of each item in the given hyper_carray.
Sum over 2^ - X where X is the value of each item in the given hyper_carray .
static ERL_NIF_TERM register_sum(ErlNifEnv * env, int argc,
				 const ERL_NIF_TERM argv[])
{
	carray_ptr arr = NULL;
	HYPER_CARRAY_OR_BADARG(argv[0], arr);
	int currval = 0;
	double sum = 0.0;
	unsigned int size = arr->size;
	for (int i = 0; i < size; ++i) {
		currval = arr->items[i];
		sum += pow(2, -currval);
	}
	return enif_make_double(env, sum);
}
static ERL_NIF_TERM register_sum ( ErlNifEnv * env , int argc , const ERL_NIF_TERM argv [ ] ) { carray_ptr arr = NULL ; HYPER_CARRAY_OR_BADARG ( argv [ 0 ] , arr ) ; int currval = 0 ; double sum = 0.0 ; unsigned int size = arr -> size ; for ( int i = 0 ; i < size ; ++ i ) { currval = arr -> items [ i ] ; sum += pow ( 2 , - currval ) ; } return enif_make_double ( env , sum ) ; }
Sum over 2^-X where X is the value of each item in the given hyper_carray.
Sum over 2^ - X where X is the value of each item in the given hyper_carray .