Ruby
3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
|
Go to the documentation of this file.
9 #ifndef RUBY_BIG_DECIMAL_H
10 #define RUBY_BIG_DECIMAL_H 1
12 #define RUBY_NO_OLD_COMPATIBILITY
21 # define DECDIG uint32_t
22 # define DECDIG_DBL uint64_t
23 # define DECDIG_DBL_SIGNED int64_t
24 # define SIZEOF_DECDIG 4
25 # define PRI_DECDIG_PREFIX ""
27 # define PRI_DECDIG_DBL_PREFIX PRI_LL_PREFIX
29 # define PRI_DECDIG_DBL_PREFIX "l"
32 # define DECDIG uint16_t
33 # define DECDIG_DBL uint32_t
34 # define DECDIG_DBL_SIGNED int32_t
35 # define SIZEOF_DECDIG 2
36 # define PRI_DECDIG_PREFIX "h"
37 # define PRI_DECDIG_DBL_PREFIX ""
40 #define PRIdDECDIG PRI_DECDIG_PREFIX"d"
41 #define PRIiDECDIG PRI_DECDIG_PREFIX"i"
42 #define PRIoDECDIG PRI_DECDIG_PREFIX"o"
43 #define PRIuDECDIG PRI_DECDIG_PREFIX"u"
44 #define PRIxDECDIG PRI_DECDIG_PREFIX"x"
45 #define PRIXDECDIG PRI_DECDIG_PREFIX"X"
47 #define PRIdDECDIG_DBL PRI_DECDIG_DBL_PREFIX"d"
48 #define PRIiDECDIG_DBL PRI_DECDIG_DBL_PREFIX"i"
49 #define PRIoDECDIG_DBL PRI_DECDIG_DBL_PREFIX"o"
50 #define PRIuDECDIG_DBL PRI_DECDIG_DBL_PREFIX"u"
51 #define PRIxDECDIG_DBL PRI_DECDIG_DBL_PREFIX"x"
52 #define PRIXDECDIG_DBL PRI_DECDIG_DBL_PREFIX"X"
54 #if SIZEOF_DECDIG == 4
55 # define BIGDECIMAL_BASE ((DECDIG)1000000000U)
56 # define BIGDECIMAL_COMPONENT_FIGURES 9
63 # define BIGDECIMAL_INT64_MAX_LENGTH 3
65 #elif SIZEOF_DECDIG == 2
66 # define BIGDECIMAL_BASE ((DECDIG)10000U)
67 # define BIGDECIMAL_COMPONENT_FIGURES 4
74 # define BIGDECIMAL_INT64_MAX_LENGTH 5
77 # error Unknown size of DECDIG
80 #define BIGDECIMAL_DOUBLE_FIGURES (1+DBL_DIG)
82 #if defined(__cplusplus)
95 #define SZ_INF "Infinity"
96 #define SZ_PINF "+Infinity"
97 #define SZ_NINF "-Infinity"
103 #define VP_EXPORT static
106 #define VP_EXCEPTION_ALL ((unsigned short)0x00FF)
107 #define VP_EXCEPTION_INFINITY ((unsigned short)0x0001)
108 #define VP_EXCEPTION_NaN ((unsigned short)0x0002)
109 #define VP_EXCEPTION_UNDERFLOW ((unsigned short)0x0004)
110 #define VP_EXCEPTION_OVERFLOW ((unsigned short)0x0001)
111 #define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0010)
114 #define VP_EXCEPTION_OP ((unsigned short)0x0020)
116 #define BIGDECIMAL_EXCEPTION_MODE_DEFAULT 0U
119 #define VP_ROUND_MODE ((unsigned short)0x0100)
120 #define VP_ROUND_UP 1
121 #define VP_ROUND_DOWN 2
122 #define VP_ROUND_HALF_UP 3
123 #define VP_ROUND_HALF_DOWN 4
124 #define VP_ROUND_CEIL 5
125 #define VP_ROUND_FLOOR 6
126 #define VP_ROUND_HALF_EVEN 7
128 #define BIGDECIMAL_ROUNDING_MODE_DEFAULT VP_ROUND_HALF_UP
130 #define VP_SIGN_NaN 0
131 #define VP_SIGN_POSITIVE_ZERO 1
132 #define VP_SIGN_NEGATIVE_ZERO -1
133 #define VP_SIGN_POSITIVE_FINITE 2
134 #define VP_SIGN_NEGATIVE_FINITE -2
135 #define VP_SIGN_POSITIVE_INFINITE 3
136 #define VP_SIGN_NEGATIVE_INFINITE -3
138 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
139 #define FLEXIBLE_ARRAY_SIZE
140 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
141 #define FLEXIBLE_ARRAY_SIZE 0
143 #define FLEXIBLE_ARRAY_SIZE 1
183 #define VpBaseFig() BIGDECIMAL_COMPONENT_FIGURES
184 #define VpDblFig() BIGDECIMAL_DOUBLE_FIGURES
185 #define VpBaseVal() BIGDECIMAL_BASE
204 VP_EXPORT int VpIsNegDoubleZero(
double v);
222 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);
234 #define VpPower VpPowerByInt
244 #define Abs(a) (((a)>= 0)?(a):(-(a)))
245 #define Max(a, b) (((a)>(b))?(a):(b))
246 #define Min(a, b) (((a)>(b))?(b):(a))
248 #define VpMaxPrec(a) ((a)->MaxPrec)
249 #define VpPrec(a) ((a)->Prec)
250 #define VpGetFlag(a) ((a)->flag)
255 #define VpGetSign(a) (((a)->sign>0)?1:(-1))
257 #define VpChangeSign(a,s) {if((s)>0) (a)->sign=(short)Abs((ssize_t)(a)->sign);else (a)->sign=-(short)Abs((ssize_t)(a)->sign);}
259 #define VpSetSign(a,s) {if((s)>0) (a)->sign=(short)VP_SIGN_POSITIVE_FINITE;else (a)->sign=(short)VP_SIGN_NEGATIVE_FINITE;}
262 #define VpSetOne(a) {(a)->Prec=(a)->exponent=(a)->frac[0]=1;(a)->sign=VP_SIGN_POSITIVE_FINITE;}
265 #define VpIsPosZero(a) ((a)->sign==VP_SIGN_POSITIVE_ZERO)
266 #define VpIsNegZero(a) ((a)->sign==VP_SIGN_NEGATIVE_ZERO)
267 #define VpIsZero(a) (VpIsPosZero(a) || VpIsNegZero(a))
268 #define VpSetPosZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_ZERO)
269 #define VpSetNegZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_ZERO)
270 #define VpSetZero(a,s) (void)(((s)>0)?VpSetPosZero(a):VpSetNegZero(a))
273 #define VpIsNaN(a) ((a)->sign==VP_SIGN_NaN)
274 #define VpSetNaN(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NaN)
277 #define VpIsPosInf(a) ((a)->sign==VP_SIGN_POSITIVE_INFINITE)
278 #define VpIsNegInf(a) ((a)->sign==VP_SIGN_NEGATIVE_INFINITE)
279 #define VpIsInf(a) (VpIsPosInf(a) || VpIsNegInf(a))
280 #define VpIsDef(a) ( !(VpIsNaN(a)||VpIsInf(a)) )
281 #define VpSetPosInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_INFINITE)
282 #define VpSetNegInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_INFINITE)
283 #define VpSetInf(a,s) (void)(((s)>0)?VpSetPosInf(a):VpSetNegInf(a))
284 #define VpHasVal(a) (a->frac[0])
285 #define VpIsOne(a) ((a->Prec==1)&&(a->frac[0]==1)&&(a->exponent==1))
286 #define VpExponent(a) (a->exponent)
287 #ifdef BIGDECIMAL_DEBUG
288 int VpVarCheck(
Real * v);
291 #if defined(__cplusplus)
VP_EXPORT size_t VpGetPrecLimit(void)
VP_EXPORT size_t VpAsgn(Real *c, Real *a, int isw)
VP_EXPORT void * VpMemRealloc(void *ptr, size_t mb)
VP_EXPORT void VpSzMantissa(Real *a, char *psz)
VP_EXPORT size_t VpNumOfChars(Real *vp, const char *pszFmt)
VP_EXPORT int VpException(unsigned short f, const char *str, int always)
VP_EXPORT unsigned short VpSetRoundMode(unsigned short n)
VP_EXPORT size_t VpDivd(Real *c, Real *r, Real *a, Real *b)
VP_EXPORT void * VpMemAlloc(size_t mb)
VP_EXPORT void VpToFString(Real *a, char *psz, size_t fFmt, int fPlus)
VP_EXPORT int VpVtoD(double *d, SIGNED_VALUE *e, Real *m)
VP_EXPORT Real * VpCreateRbObject(size_t mx, const char *str, bool raise_exception)
VP_EXPORT void VpFree(Real *pv)
VP_EXPORT double VpGetDoubleNegZero(void)
VP_EXPORT size_t VpSetPrecLimit(size_t n)
VP_EXPORT Real * VpAlloc(size_t mx, const char *szVal, int strict_p, int exc)
VP_EXPORT int VpIsRoundMode(unsigned short n)
VP_EXPORT double VpGetDoubleNegInf(void)
VP_EXPORT int VpComp(Real *a, Real *b)
VP_EXPORT int VpToSpecialString(Real *a, char *psz, int fPlus)
VP_EXPORT int VpSqrt(Real *y, Real *x)
VP_EXPORT Real * VpOne(void)
VP_EXPORT void VpToString(Real *a, char *psz, size_t fFmt, int fPlus)
VP_EXPORT size_t VpInit(DECDIG BaseVal)
VP_EXPORT void VpDtoV(Real *m, double d)
VP_EXPORT size_t VpAddSub(Real *c, Real *a, Real *b, int operation)
VP_EXPORT ssize_t VpExponent10(Real *a)
VP_EXPORT void VpFrac(Real *y, Real *x)
VP_EXPORT int VpMidRound(Real *y, unsigned short f, ssize_t nf)
char str[HTML_ESCAPE_MAX_LEN+1]
VP_EXPORT int VpLeftRound(Real *y, unsigned short f, ssize_t nf)
VP_EXPORT int VpPowerByInt(Real *y, Real *x, SIGNED_VALUE n)
VP_EXPORT double VpGetDoubleNaN(void)
VP_EXPORT int VpActiveRound(Real *y, Real *x, unsigned short f, ssize_t il)
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 double VpGetDoublePosInf(void)
VP_EXPORT Real * VpNewRbClass(size_t mx, char const *str, VALUE klass, bool strict_p, bool raise_exception)
VP_EXPORT unsigned short VpGetRoundMode(void)
#define FLEXIBLE_ARRAY_SIZE
VP_EXPORT size_t VpMult(Real *c, Real *a, Real *b)