9 #ifndef RUBY_BIG_DECIMAL_H 10 #define RUBY_BIG_DECIMAL_H 1 12 #define RUBY_NO_OLD_COMPATIBILITY 19 # define RB_UNUSED_VAR(x) x __attribute__ ((unused)) 21 # define RB_UNUSED_VAR(x) x 32 #undef BDIGIT_DBL_SIGNED 33 #undef PRI_BDIGIT_PREFIX 34 #undef PRI_BDIGIT_DBL_PREFIX 37 # define BDIGIT uint32_t 38 # define BDIGIT_DBL uint64_t 39 # define BDIGIT_DBL_SIGNED int64_t 40 # define SIZEOF_BDIGITS 4 41 # define PRI_BDIGIT_PREFIX "" 43 # define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX 45 # define PRI_BDIGIT_DBL_PREFIX "l" 48 # define BDIGIT uint16_t 49 # define BDIGIT_DBL uint32_t 50 # define BDIGIT_DBL_SIGNED int32_t 51 # define SIZEOF_BDIGITS 2 52 # define PRI_BDIGIT_PREFIX "h" 53 # define PRI_BDIGIT_DBL_PREFIX "" 56 #define PRIdBDIGIT PRI_BDIGIT_PREFIX"d" 57 #define PRIiBDIGIT PRI_BDIGIT_PREFIX"i" 58 #define PRIoBDIGIT PRI_BDIGIT_PREFIX"o" 59 #define PRIuBDIGIT PRI_BDIGIT_PREFIX"u" 60 #define PRIxBDIGIT PRI_BDIGIT_PREFIX"x" 61 #define PRIXBDIGIT PRI_BDIGIT_PREFIX"X" 63 #define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d" 64 #define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i" 65 #define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o" 66 #define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u" 67 #define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x" 68 #define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X" 70 #if defined(__cplusplus) 87 static inline LONG_LONG
88 llabs(LONG_LONG
const x)
104 # ifndef HAVE_ISFINITE 105 # define HAVE_ISFINITE 1 106 # define isfinite(x) finite(x) 110 #ifndef FIX_CONST_VALUE_PTR 111 # if defined(__fcc__) || defined(__fcc_version) || \ 112 defined(__FCC__) || defined(__FCC_VERSION) 114 # define FIX_CONST_VALUE_PTR(x) ((const VALUE *)(x)) 116 # define FIX_CONST_VALUE_PTR(x) (x) 120 #ifndef HAVE_RB_ARRAY_CONST_PTR 121 static inline const VALUE *
122 rb_array_const_ptr(
VALUE a)
129 #ifndef RARRAY_CONST_PTR 130 # define RARRAY_CONST_PTR(a) rb_array_const_ptr(a) 134 # define RARRAY_AREF(a, i) (RARRAY_CONST_PTR(a)[i]) 137 #ifndef HAVE_RB_SYM2STR 148 #if SIZEOF_VALUE <= SIZEOF_INT 150 #elif SIZEOF_VALUE <= SIZEOF_LONG 152 #elif SIZEOF_VALUE <= SIZEOF_LONG_LONG 158 #if 0 || SIZEOF_BDIGITS >= 16 159 # define RMPD_COMPONENT_FIGURES 38 160 # define RMPD_BASE ((BDIGIT)100000000000000000000000000000000000000U) 161 #elif SIZEOF_BDIGITS >= 8 162 # define RMPD_COMPONENT_FIGURES 19 163 # define RMPD_BASE ((BDIGIT)10000000000000000000U) 164 #elif SIZEOF_BDIGITS >= 4 165 # define RMPD_COMPONENT_FIGURES 9 166 # define RMPD_BASE ((BDIGIT)1000000000U) 167 #elif SIZEOF_BDIGITS >= 2 168 # define RMPD_COMPONENT_FIGURES 4 169 # define RMPD_BASE ((BDIGIT)10000U) 171 # define RMPD_COMPONENT_FIGURES 2 172 # define RMPD_BASE ((BDIGIT)100U) 180 #define SZ_INF "Infinity" 181 #define SZ_PINF "+Infinity" 182 #define SZ_NINF "-Infinity" 188 #define VP_EXPORT static 191 #define VP_EXCEPTION_ALL ((unsigned short)0x00FF) 192 #define VP_EXCEPTION_INFINITY ((unsigned short)0x0001) 193 #define VP_EXCEPTION_NaN ((unsigned short)0x0002) 194 #define VP_EXCEPTION_UNDERFLOW ((unsigned short)0x0004) 195 #define VP_EXCEPTION_OVERFLOW ((unsigned short)0x0001) 196 #define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0010) 199 #define VP_EXCEPTION_OP ((unsigned short)0x0020) 200 #define VP_EXCEPTION_MEMORY ((unsigned short)0x0040) 202 #define RMPD_EXCEPTION_MODE_DEFAULT 0U 205 #define VP_ROUND_MODE ((unsigned short)0x0100) 206 #define VP_ROUND_UP 1 207 #define VP_ROUND_DOWN 2 208 #define VP_ROUND_HALF_UP 3 209 #define VP_ROUND_HALF_DOWN 4 210 #define VP_ROUND_CEIL 5 211 #define VP_ROUND_FLOOR 6 212 #define VP_ROUND_HALF_EVEN 7 214 #define RMPD_ROUNDING_MODE_DEFAULT VP_ROUND_HALF_UP 216 #define VP_SIGN_NaN 0 217 #define VP_SIGN_POSITIVE_ZERO 1 218 #define VP_SIGN_NEGATIVE_ZERO -1 219 #define VP_SIGN_POSITIVE_FINITE 2 220 #define VP_SIGN_NEGATIVE_FINITE -2 221 #define VP_SIGN_POSITIVE_INFINITE 3 222 #define VP_SIGN_NEGATIVE_INFINITE -3 225 #define FLEXIBLE_ARRAY_SIZE 0 227 #define FLEXIBLE_ARRAY_SIZE 1 269 rmpd_base_value(
void) {
return RMPD_BASE; }
273 rmpd_double_figures(
void) {
return 1+
DBL_DIG; }
275 #define VpBaseFig() rmpd_component_figures() 276 #define VpDblFig() rmpd_double_figures() 277 #define VpBaseVal() rmpd_base_value() 296 VP_EXPORT int VpIsNegDoubleZero(
double v);
314 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);
335 #define Abs(a) (((a)>= 0)?(a):(-(a))) 336 #define Max(a, b) (((a)>(b))?(a):(b)) 337 #define Min(a, b) (((a)>(b))?(b):(a)) 339 #define VpMaxPrec(a) ((a)->MaxPrec) 340 #define VpPrec(a) ((a)->Prec) 341 #define VpGetFlag(a) ((a)->flag) 346 #define VpGetSign(a) (((a)->sign>0)?1:(-1)) 348 #define VpChangeSign(a,s) {if((s)>0) (a)->sign=(short)Abs((ssize_t)(a)->sign);else (a)->sign=-(short)Abs((ssize_t)(a)->sign);} 350 #define VpSetSign(a,s) {if((s)>0) (a)->sign=(short)VP_SIGN_POSITIVE_FINITE;else (a)->sign=(short)VP_SIGN_NEGATIVE_FINITE;} 353 #define VpSetOne(a) {(a)->Prec=(a)->exponent=(a)->frac[0]=1;(a)->sign=VP_SIGN_POSITIVE_FINITE;} 356 #define VpIsPosZero(a) ((a)->sign==VP_SIGN_POSITIVE_ZERO) 357 #define VpIsNegZero(a) ((a)->sign==VP_SIGN_NEGATIVE_ZERO) 358 #define VpIsZero(a) (VpIsPosZero(a) || VpIsNegZero(a)) 359 #define VpSetPosZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_ZERO) 360 #define VpSetNegZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_ZERO) 361 #define VpSetZero(a,s) (void)(((s)>0)?VpSetPosZero(a):VpSetNegZero(a)) 364 #define VpIsNaN(a) ((a)->sign==VP_SIGN_NaN) 365 #define VpSetNaN(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NaN) 368 #define VpIsPosInf(a) ((a)->sign==VP_SIGN_POSITIVE_INFINITE) 369 #define VpIsNegInf(a) ((a)->sign==VP_SIGN_NEGATIVE_INFINITE) 370 #define VpIsInf(a) (VpIsPosInf(a) || VpIsNegInf(a)) 371 #define VpIsDef(a) ( !(VpIsNaN(a)||VpIsInf(a)) ) 372 #define VpSetPosInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_INFINITE) 373 #define VpSetNegInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_INFINITE) 374 #define VpSetInf(a,s) (void)(((s)>0)?VpSetPosInf(a):VpSetNegInf(a)) 375 #define VpHasVal(a) (a->frac[0]) 376 #define VpIsOne(a) ((a->Prec==1)&&(a->frac[0]==1)&&(a->exponent==1)) 377 #define VpExponent(a) (a->exponent) 378 #ifdef BIGDECIMAL_DEBUG 379 int VpVarCheck(
Real * v);
382 #if defined(__cplusplus) VP_EXPORT void * VpMemRealloc(void *ptr, size_t mb)
VP_EXPORT int VpActiveRound(Real *y, Real *x, unsigned short f, ssize_t il)
VP_EXPORT ssize_t VpExponent10(Real *a)
VP_EXPORT double VpGetDoubleNaN(void)
#define FIX_CONST_VALUE_PTR(x)
VP_EXPORT size_t VpGetPrecLimit(void)
VP_EXPORT size_t VpDivd(Real *c, Real *r, Real *a, Real *b)
VP_EXPORT size_t VpMult(Real *c, Real *a, Real *b)
VP_EXPORT int VpComp(Real *a, Real *b)
VP_EXPORT int VpVtoD(double *d, SIGNED_VALUE *e, Real *m)
VP_EXPORT void VpFrac(Real *y, Real *x)
VP_EXPORT size_t VpAddSub(Real *c, Real *a, Real *b, int operation)
VP_EXPORT void VpToFString(Real *a, char *psz, size_t fFmt, int fPlus)
VP_EXPORT int VpMidRound(Real *y, unsigned short f, ssize_t nf)
VP_EXPORT Real * VpNewRbClass(size_t mx, char const *str, VALUE klass)
#define RMPD_COMPONENT_FIGURES
VP_EXPORT void * VpMemAlloc(size_t mb)
VP_EXPORT void VpToString(Real *a, char *psz, size_t fFmt, int fPlus)
VP_EXPORT size_t VpNumOfChars(Real *vp, const char *pszFmt)
VP_EXPORT void VpFree(Real *pv)
VP_EXPORT Real * VpCreateRbObject(size_t mx, const char *str)
RUBY_EXTERN int isinf(double)
VP_EXPORT double VpGetDoubleNegZero(void)
VP_EXPORT int VpIsRoundMode(unsigned short n)
VP_EXPORT int VpSqrt(Real *y, Real *x)
VP_EXPORT void VpDtoV(Real *m, double d)
VP_EXPORT int VpToSpecialString(Real *a, char *psz, int fPlus)
VP_EXPORT double VpGetDoubleNegInf(void)
VP_EXPORT size_t VpSetPrecLimit(size_t n)
VP_EXPORT size_t VpAsgn(Real *c, Real *a, int isw)
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 void VpSzMantissa(Real *a, char *psz)
VP_EXPORT int VpPower(Real *y, Real *x, SIGNED_VALUE n)
VP_EXPORT unsigned short VpGetRoundMode(void)
VP_EXPORT int VpLeftRound(Real *y, unsigned short f, ssize_t nf)
VP_EXPORT Real * VpAlloc(size_t mx, const char *szVal)
#define FLEXIBLE_ARRAY_SIZE
VP_EXPORT size_t VpInit(BDIGIT BaseVal)
VP_EXPORT double VpGetDoublePosInf(void)
VP_EXPORT int VpException(unsigned short f, const char *str, int always)
VP_EXPORT Real * VpOne(void)
VP_EXPORT unsigned short VpSetRoundMode(unsigned short n)