void _num(class,x) SV* x INIT: AV* a; NV fac; SV* temp; NV num; I32 elems; I32 index; NV BASE; CODE: a = (AV*)SvRV(x); /* ref to aray, don't check ref */ elems = av_len(a); /* number of elems in array */ if (elems == 0) /* only one element? */ { ST(0) = *av_fetch(a, 0, 0); /* fetch first (only) element */ XSRETURN(1); /* return it */ } fac = 1.0; /* factor */ index = 0; num = 0.0; BASE = XS_BASE; while (index <= elems) { temp = *av_fetch(a, index, 0); /* fetch current element */ num += fac * SvNV(temp); fac *= BASE; index++; } ST(0) = newSVnv(num);