diff -r e14a1aba4c56 -r b1fbfab67908 np-conv.h --- a/np-conv.h Wed Feb 23 08:47:59 2000 +0100 +++ b/np-conv.h Wed Apr 19 22:03:38 2000 +0200 @@ -9,6 +9,52 @@ #include +#ifdef NP_SIMPLE_IMPL + +#define FN_NUM_TO_SIGNED(T, UMAX, MAX, MIN) \ + static int num_to_##T(T *ret, const NPNum *num, bool allow_uns_big) \ + { \ + if(num->type!=NPNUM_INT) \ + return E_TOKZ_NOTINT; \ + \ + if(!num->negative){ \ + *ret=num->ival; \ + if(allow_uns_big?num->ival>UMAX:num->ival>MAX) \ + return E_TOKZ_RANGE; \ + }else{ \ + *ret=-num->ival; \ + if(num->ival>-(ulong)MIN) \ + return E_TOKZ_RANGE; \ + } \ + return 0; \ + } + +#define FN_NUM_TO_UNSIGNED(T, UMAX, MIN) \ + static int num_to_##T(T *ret, const NPNum *num, bool allow_neg) \ + { \ + if(num->type!=NPNUM_INT) \ + return E_TOKZ_NOTINT; \ + \ + if(!num->negative){ \ + *ret=num->ival; \ + if(num->ival>UMAX) \ + return E_TOKZ_RANGE; \ + }else{ \ + *ret=-num->ival; \ + if(!allow_neg || num->ival>(ulong)-MIN) \ + return E_TOKZ_RANGE; \ + } \ + return 0; \ + } + +#define FN_NUM_TO_FLOAT(T, POW) \ + static int num_to_##T(T *ret, const NPNum *num) \ + { \ + *ret=(num->negative?-num->fval:num->fval); \ + return 0; \ + } + +#else /* NP_SIMPLE_IMPL */ #define FN_NUM_TO_SIGNED(T, UMAX, MAX, MIN) \ static int num_to_##T(T *ret, const NPNum *num, bool allow_uns_big) \ @@ -60,12 +106,14 @@ for(i=num->nmantissa;i>=0;i--) \ d=d*(T)(ULONG_MAX+1.0)+num->mantissa[i]; \ \ - d*=POW(10, num->exponent); \ + d*=POW(num->base, num->exponent); \ *ret=d; \ \ return 0; \ } +#endif /* NP_SIMPLE_IMPL */ + FN_NUM_TO_SIGNED(long, ULONG_MAX, LONG_MAX, LONG_MIN) FN_NUM_TO_SIGNED(char, UCHAR_MAX, CHAR_MAX, CHAR_MIN) FN_NUM_TO_FLOAT(double, pow)