path: root/ext/bigdecimal/bigdecimal.h
diff options
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 15:22:43 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 15:22:43 +0000
commitd86da0fcf1954397587ab6b9cb16400bd93c2695 (patch)
tree28f38eb1f973747b8b7d8b7e271261312af878a2 /ext/bigdecimal/bigdecimal.h
parent01e3f613d75fd06264fd9264dcccfe383a410796 (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:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.h')
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" {
+#ifndef HAVE_LABS
+static inline long
+labs(long const x)
+ if (x < 0) return -x;
+ return x;
+#ifndef HAVE_LLABS
+static inline long long
+llabs(long long const x)
+ if (x < 0) return -x;
+ return x;
+#ifdef vabs
+# undef vabs
+# define vabs abs
+# define vabs labs
+# define vabs llabs
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 {
-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 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);
-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);
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 /* RUBY_BIG_DECIMAL_H */