diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-14 15:22:43 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-14 15:22:43 +0000 |
commit | d86da0fcf1954397587ab6b9cb16400bd93c2695 (patch) | |
tree | 28f38eb1f973747b8b7d8b7e271261312af878a2 /ext/bigdecimal/bigdecimal.h | |
parent | 01e3f613d75fd06264fd9264dcccfe383a410796 (diff) |
* ext/bigdecimal/extconf.rb, ext/bigdecimal/bigdecimal.h (labs, llabs): support environments missing labs and llabs.
* ext/bigdecimal/bigdecimal.h (vabs): added.
* ext/bigdecimal/extconf.rb, ext/bigdecimal/bigdecimal.h, ext/bigdecimal/bigdecimal.c, test/bigdecimal/test_bigdecimal.rb (TestBigDecimal#test_new): replace U_LONG, S_LONG, S_INT, and U_INT with appropreate standard or ruby-provided types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.h')
-rw-r--r-- | ext/bigdecimal/bigdecimal.h | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index 8cec3f7843..e5a8c36e29 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -23,6 +23,35 @@ extern "C" { #endif +#ifndef HAVE_LABS +static inline long +labs(long const x) +{ + if (x < 0) return -x; + return x; +} +#endif + +#ifndef HAVE_LLABS +static inline long long +llabs(long long const x) +{ + if (x < 0) return -x; + return x; +} +#endif + +#ifdef vabs +# undef vabs +#endif +#if SIZEOF_VALUE <= SIZEOF_INT +# define vabs abs +#elif SIZEOF_VALUE <= SIZEOF_LONG +# define vabs labs +#elif SIZEOF_VALUE <= SIZEOF_LONG_LONG +# define vabs llabs +#endif + extern VALUE rb_cBigDecimal; #if 0 || SIZEOF_BDIGITS >= 16 @@ -57,11 +86,6 @@ extern VALUE rb_cBigDecimal; */ #define VP_EXPORT static -#define U_LONG unsigned long -#define S_LONG long -#define U_INT unsigned int -#define S_INT int - /* Exception codes */ #define VP_EXCEPTION_ALL ((unsigned short)0x00FF) #define VP_EXCEPTION_INFINITY ((unsigned short)0x0001) @@ -98,13 +122,13 @@ extern VALUE rb_cBigDecimal; */ typedef struct { VALUE obj; /* Back pointer(VALUE) for Ruby object. */ - U_LONG MaxPrec; /* Maximum precision size */ + size_t MaxPrec; /* Maximum precision size */ /* This is the actual size of pfrac[] */ /*(frac[0] to frac[MaxPrec] are available). */ - U_LONG Prec; /* Current precision size. */ + size_t Prec; /* Current precision size. */ /* This indicates how much the. */ /* the array frac[] is actually used. */ - S_INT exponent;/* Exponent part. */ + SIGNED_VALUE exponent; /* Exponent part. */ short sign; /* Attributes of the value. */ /* * ==0 : NaN @@ -126,9 +150,9 @@ typedef struct { */ VP_EXPORT Real * -VpNewRbClass(U_LONG mx, char *str, VALUE klass); +VpNewRbClass(size_t mx, char *str, VALUE klass); -VP_EXPORT Real *VpCreateRbObject(U_LONG mx,const char *str); +VP_EXPORT Real *VpCreateRbObject(size_t mx,const char *str); static inline BDIGIT rmpd_base_value(void) { return RMPD_BASE; } @@ -148,8 +172,8 @@ VP_EXPORT double VpGetDoubleNegInf(void); VP_EXPORT double VpGetDoubleNegZero(void); /* These 2 functions added at v1.1.7 */ -VP_EXPORT U_LONG VpGetPrecLimit(void); -VP_EXPORT U_LONG VpSetPrecLimit(U_LONG n); +VP_EXPORT size_t VpGetPrecLimit(void); +VP_EXPORT size_t VpSetPrecLimit(size_t n); /* Round mode */ VP_EXPORT int VpIsRoundMode(unsigned long n); @@ -160,33 +184,33 @@ VP_EXPORT int VpException(unsigned short f,const char *str,int always); #if 0 /* unused */ VP_EXPORT int VpIsNegDoubleZero(double v); #endif -VP_EXPORT U_LONG VpNumOfChars(Real *vp,const char *pszFmt); +VP_EXPORT size_t VpNumOfChars(Real *vp,const char *pszFmt); VP_EXPORT size_t VpInit(BDIGIT BaseVal); -VP_EXPORT void *VpMemAlloc(U_LONG mb); +VP_EXPORT void *VpMemAlloc(size_t mb); VP_EXPORT void VpFree(Real *pv); -VP_EXPORT Real *VpAlloc(U_LONG mx, const char *szVal); -VP_EXPORT U_LONG VpAsgn(Real *c,Real *a,int isw); -VP_EXPORT U_LONG VpAddSub(Real *c,Real *a,Real *b,int operation); -VP_EXPORT U_LONG VpMult(Real *c,Real *a,Real *b); -VP_EXPORT U_LONG VpDivd(Real *c,Real *r,Real *a,Real *b); +VP_EXPORT Real *VpAlloc(size_t mx, const char *szVal); +VP_EXPORT size_t VpAsgn(Real *c, Real *a, int isw); +VP_EXPORT size_t VpAddSub(Real *c,Real *a,Real *b,int operation); +VP_EXPORT size_t VpMult(Real *c,Real *a,Real *b); +VP_EXPORT size_t VpDivd(Real *c,Real *r,Real *a,Real *b); VP_EXPORT int VpComp(Real *a,Real *b); -VP_EXPORT S_LONG VpExponent10(Real *a); +VP_EXPORT ssize_t VpExponent10(Real *a); VP_EXPORT void VpSzMantissa(Real *a,char *psz); VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus); -VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,int fPlus); -VP_EXPORT void VpToFString(Real *a,char *psz,int fFmt,int fPlus); -VP_EXPORT int VpCtoV(Real *a,const char *int_chr,U_LONG ni,const char *frac,U_LONG nf,const char *exp_chr,U_LONG ne); -VP_EXPORT int VpVtoD(double *d,S_LONG *e,Real *m); +VP_EXPORT void VpToString(Real *a, char *psz, size_t fFmt, int fPlus); +VP_EXPORT void VpToFString(Real *a, char *psz, size_t fFmt, int fPlus); +VP_EXPORT int VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, const char *exp_chr, size_t ne); +VP_EXPORT int VpVtoD(double *d, ssize_t *e, Real *m); VP_EXPORT void VpDtoV(Real *m,double d); #if 0 /* unused */ VP_EXPORT void VpItoV(Real *m,S_INT ival); #endif VP_EXPORT int VpSqrt(Real *y,Real *x); -VP_EXPORT int VpActiveRound(Real *y,Real *x,int f,S_LONG il); -VP_EXPORT int VpMidRound(Real *y, int f, S_LONG nf); -VP_EXPORT int VpLeftRound(Real *y, int f, S_LONG nf); -VP_EXPORT void VpFrac(Real *y,Real *x); -VP_EXPORT int VpPower(Real *y,Real *x,S_INT n); +VP_EXPORT int VpActiveRound(Real *y, Real *x, int f, ssize_t il); +VP_EXPORT int VpMidRound(Real *y, int f, ssize_t nf); +VP_EXPORT int VpLeftRound(Real *y, int f, ssize_t nf); +VP_EXPORT void VpFrac(Real *y, Real *x); +VP_EXPORT int VpPower(Real *y, Real *x, SIGNED_VALUE n); /* VP constants */ VP_EXPORT Real *VpOne(void); @@ -209,7 +233,7 @@ VP_EXPORT Real *VpOne(void); /* VpGetSign(a) returns 1,-1 if a>0,a<0 respectively */ #define VpGetSign(a) (((a)->sign>0)?1:(-1)) /* Change sign of a to a>0,a<0 if s = 1,-1 respectively */ -#define VpChangeSign(a,s) {if((s)>0) (a)->sign=(short)Abs((S_LONG)(a)->sign);else (a)->sign=-(short)Abs((S_LONG)(a)->sign);} +#define VpChangeSign(a,s) {if((s)>0) (a)->sign=(short)Abs((ssize_t)(a)->sign);else (a)->sign=-(short)Abs((ssize_t)(a)->sign);} /* Sets sign of a to a>0,a<0 if s = 1,-1 respectively */ #define VpSetSign(a,s) {if((s)>0) (a)->sign=(short)VP_SIGN_POSITIVE_FINITE;else (a)->sign=(short)VP_SIGN_NEGATIVE_FINITE;} @@ -247,5 +271,4 @@ VP_EXPORT int VPrint(FILE *fp,const char *cntl_chr,Real *a); #if defined(__cplusplus) } /* extern "C" { */ #endif - #endif /* RUBY_BIG_DECIMAL_H */ |