Ruby
2.5.0dev(2017-10-22revision60238)
|
#include "bigdecimal.h"
#include "ruby/util.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
Go to the source code of this file.
Macros | |
#define | NDEBUG |
#define | MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) |
#define | SIGNED_VALUE_MAX INTPTR_MAX |
#define | SIGNED_VALUE_MIN INTPTR_MIN |
#define | MUL_OVERFLOW_SIGNED_VALUE_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, SIGNED_VALUE_MIN, SIGNED_VALUE_MAX) |
#define | ENTER(n) volatile VALUE RB_UNUSED_VAR(vStack[n]);int iStack=0 |
#define | PUSH(x) (vStack[iStack++] = (VALUE)(x)) |
#define | SAVE(p) PUSH((p)->obj) |
#define | GUARD_OBJ(p, y) ((p)=(y), SAVE(p)) |
#define | BASE_FIG RMPD_COMPONENT_FIGURES |
#define | BASE RMPD_BASE |
#define | HALF_BASE (BASE/2) |
#define | BASE1 (BASE/10) |
#define | DBLE_FIG (DBL_DIG+1) /* figure of double */ |
#define | RRATIONAL_ZERO_P(x) |
#define | RRATIONAL_NEGATIVE_P(x) RTEST(rb_funcall((x), '<', 1, INT2FIX(0))) |
#define | RB_OBJ_CLASSNAME(obj) rb_obj_class(obj) |
#define | RB_OBJ_STRING(obj) (obj) |
#define | BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0) |
#define | BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0) |
#define | DoSomeOne(x, y, f) rb_num_coerce_bin(x,y,f) |
#define | VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(BDIGIT)) |
#define | VpReallocReal(ptr, prec) (Real *)VpMemRealloc((ptr), offsetof(Real, frac) + (prec) * sizeof(BDIGIT)) |
#define | BigMath_exp(x, n) BigMath_s_exp(rb_mBigMath, (x), (n)) |
#define | BigMath_log(x, n) BigMath_s_log(rb_mBigMath, (x), (n)) |
#define | is_positive(x) (!is_negative(x)) |
#define | maxnr 100UL /* Maximum iterations for calculating sqrt. */ |
#define | MemCmp(x, y, z) memcmp(x,y,z) |
#define | StrCmp(x, y) strcmp(x,y) |
#define | rmpd_set_thread_local_exception_mode(mode) |
#define | rmpd_set_thread_local_precision_limit(limit) |
#define | RMPD_PRECISION_LIMIT_DEFAULT ((size_t)0) |
#define | rmpd_set_thread_local_rounding_mode(mode) |
Enumerations | |
enum | op_sw { OP_SW_ADD = 1, OP_SW_SUB, OP_SW_MULT, OP_SW_DIV } |
Functions | |
NORETURN (static void cannot_be_coerced_into_BigDecimal(VALUE, VALUE)) | |
VP_EXPORT Real * | VpNewRbClass (size_t mx, const char *str, VALUE klass) |
VP_EXPORT Real * | VpCreateRbObject (size_t mx, const char *str) |
void | Init_bigdecimal (void) |
VP_EXPORT void * | VpMemAlloc (size_t mb) |
VP_EXPORT void * | VpMemRealloc (void *ptr, size_t mb) |
VP_EXPORT void | VpFree (Real *pv) |
VP_EXPORT size_t | VpGetPrecLimit (void) |
VP_EXPORT size_t | VpSetPrecLimit (size_t n) |
VP_EXPORT unsigned short | VpGetRoundMode (void) |
VP_EXPORT int | VpIsRoundMode (unsigned short n) |
VP_EXPORT unsigned short | VpSetRoundMode (unsigned short n) |
VP_EXPORT double | VpGetDoubleNaN (void) |
VP_EXPORT double | VpGetDoublePosInf (void) |
VP_EXPORT double | VpGetDoubleNegInf (void) |
VP_EXPORT double | VpGetDoubleNegZero (void) |
VP_EXPORT int | VpException (unsigned short f, const char *str, int always) |
VP_EXPORT size_t | VpNumOfChars (Real *vp, const char *pszFmt) |
VP_EXPORT size_t | VpInit (BDIGIT BaseVal) |
VP_EXPORT Real * | VpOne (void) |
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 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, 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, SIGNED_VALUE *e, Real *m) |
VP_EXPORT void | VpDtoV (Real *m, double d) |
VP_EXPORT int | VpSqrt (Real *y, Real *x) |
VP_EXPORT int | VpMidRound (Real *y, unsigned short f, ssize_t nf) |
VP_EXPORT int | VpLeftRound (Real *y, unsigned short f, ssize_t nf) |
VP_EXPORT int | VpActiveRound (Real *y, Real *x, unsigned short f, ssize_t nf) |
VP_EXPORT void | VpFrac (Real *y, Real *x) |
VP_EXPORT int | VpPower (Real *y, Real *x, SIGNED_VALUE n) |
Variables | |
VALUE | rb_cBigDecimal |
VALUE | rb_mBigMath |
volatile const double | gZero_ABCED9B1_CE73__00400511F31D = 0.0 |
volatile const double | gOne_ABCED9B4_CE73__00400511F31D = 1.0 |
#define BASE RMPD_BASE |
Definition at line 74 of file bigdecimal.c.
Referenced by VpDtoV(), VpInit(), VpMidRound(), VpPower(), VpSqrt(), VpToFString(), and VpVtoD().
#define BASE1 (BASE/10) |
Definition at line 77 of file bigdecimal.c.
Referenced by VpComp(), VpExponent10(), VpInit(), VpSzMantissa(), and VpToFString().
#define BASE_FIG RMPD_COMPONENT_FIGURES |
Definition at line 73 of file bigdecimal.c.
Referenced by VpAlloc(), VpExponent10(), VpInit(), VpLeftRound(), VpMidRound(), VpNumOfChars(), VpPower(), VpSqrt(), VpToFString(), and VpVtoD().
#define BIGDECIMAL_NEGATIVE_P | ( | bd | ) | ((bd)->sign < 0) |
Definition at line 131 of file bigdecimal.c.
Referenced by VpComp(), VpMidRound(), VpSqrt(), VpSzMantissa(), and VpToFString().
#define BIGDECIMAL_POSITIVE_P | ( | bd | ) | ((bd)->sign > 0) |
Definition at line 130 of file bigdecimal.c.
Referenced by VpMidRound(), and VpPower().
#define BigMath_exp | ( | x, | |
n | |||
) | BigMath_s_exp(rb_mBigMath, (x), (n)) |
Definition at line 2189 of file bigdecimal.c.
#define BigMath_log | ( | x, | |
n | |||
) | BigMath_s_log(rb_mBigMath, (x), (n)) |
Definition at line 2190 of file bigdecimal.c.
#define DBLE_FIG (DBL_DIG+1) /* figure of double */ |
Definition at line 80 of file bigdecimal.c.
#define DoSomeOne | ( | x, | |
y, | |||
f | |||
) | rb_num_coerce_bin(x,y,f) |
Definition at line 136 of file bigdecimal.c.
#define ENTER | ( | n | ) | volatile VALUE RB_UNUSED_VAR(vStack[n]);int iStack=0 |
Definition at line 68 of file bigdecimal.c.
#define GUARD_OBJ | ( | p, | |
y | |||
) | ((p)=(y), SAVE(p)) |
Definition at line 71 of file bigdecimal.c.
#define HALF_BASE (BASE/2) |
Definition at line 76 of file bigdecimal.c.
Referenced by VpInit().
#define is_positive | ( | x | ) | (!is_negative(x)) |
Definition at line 2213 of file bigdecimal.c.
#define maxnr 100UL /* Maximum iterations for calculating sqrt. */ |
Definition at line 3481 of file bigdecimal.c.
Referenced by VpSqrt().
#define MemCmp | ( | x, | |
y, | |||
z | |||
) | memcmp(x,y,z) |
Definition at line 3485 of file bigdecimal.c.
#define MUL_OVERFLOW_SIGNED_INTEGER_P | ( | a, | |
b, | |||
min, | |||
max | |||
) |
Definition at line 35 of file bigdecimal.c.
#define MUL_OVERFLOW_SIGNED_VALUE_P | ( | a, | |
b | |||
) | MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, SIGNED_VALUE_MIN, SIGNED_VALUE_MAX) |
Definition at line 43 of file bigdecimal.c.
#define NDEBUG |
Definition at line 17 of file bigdecimal.c.
#define PUSH | ( | x | ) | (vStack[iStack++] = (VALUE)(x)) |
Definition at line 69 of file bigdecimal.c.
#define RB_OBJ_CLASSNAME | ( | obj | ) | rb_obj_class(obj) |
Definition at line 98 of file bigdecimal.c.
#define RB_OBJ_STRING | ( | obj | ) | (obj) |
Definition at line 99 of file bigdecimal.c.
#define RMPD_PRECISION_LIMIT_DEFAULT ((size_t)0) |
Definition at line 3594 of file bigdecimal.c.
#define rmpd_set_thread_local_exception_mode | ( | mode | ) |
Definition at line 3555 of file bigdecimal.c.
#define rmpd_set_thread_local_precision_limit | ( | limit | ) |
Definition at line 3588 of file bigdecimal.c.
Referenced by VpSetPrecLimit().
#define rmpd_set_thread_local_rounding_mode | ( | mode | ) |
Definition at line 3625 of file bigdecimal.c.
Referenced by VpSetRoundMode().
#define RRATIONAL_NEGATIVE_P | ( | x | ) | RTEST(rb_funcall((x), '<', 1, INT2FIX(0))) |
Definition at line 89 of file bigdecimal.c.
#define RRATIONAL_ZERO_P | ( | x | ) |
Definition at line 84 of file bigdecimal.c.
#define SAVE | ( | p | ) | PUSH((p)->obj) |
Definition at line 70 of file bigdecimal.c.
#define SIGNED_VALUE_MAX INTPTR_MAX |
Definition at line 41 of file bigdecimal.c.
#define SIGNED_VALUE_MIN INTPTR_MIN |
Definition at line 42 of file bigdecimal.c.
#define StrCmp | ( | x, | |
y | |||
) | strcmp(x,y) |
Definition at line 3486 of file bigdecimal.c.
Referenced by VpAlloc().
#define VpAllocReal | ( | prec | ) | (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(BDIGIT)) |
Definition at line 675 of file bigdecimal.c.
Referenced by VpAlloc().
#define VpReallocReal | ( | ptr, | |
prec | |||
) | (Real *)VpMemRealloc((ptr), offsetof(Real, frac) + (prec) * sizeof(BDIGIT)) |
Definition at line 676 of file bigdecimal.c.
enum op_sw |
Enumerator | |
---|---|
OP_SW_ADD | |
OP_SW_SUB | |
OP_SW_MULT | |
OP_SW_DIV |
Definition at line 3488 of file bigdecimal.c.
void Init_bigdecimal | ( | void | ) |
Definition at line 3245 of file bigdecimal.c.
NORETURN | ( | static void | cannot_be_coerced_into_BigDecimalVALUE, VALUE | ) |
Definition at line 6141 of file bigdecimal.c.
References VpAsgn(), and VpMidRound().
Definition at line 4014 of file bigdecimal.c.
References BASE_FIG, buf, ISDIGIT, ISSPACE, Max, Real::MaxPrec, ne, NULL, PRIsVALUE, rb_eArgError, rb_raise(), rb_str_new2, rb_str_resize(), rb_str_tmp_new(), RSTRING_PTR, StrCmp, strlen(), SZ_INF, SZ_NaN, SZ_NINF, SZ_PINF, VP_EXPORT, VpAllocReal, VpCtoV(), VpGetPrecLimit(), VpSetNaN, VpSetNegInf, VpSetPosInf, and VpSetZero.
Referenced by VpInit(), VpNewRbClass(), VpPower(), and VpSqrt().
Definition at line 4180 of file bigdecimal.c.
References BDIGIT, Real::exponent, Real::frac, Real::MaxPrec, Real::Prec, VpGetSign, VpIsInf, VpIsNaN, VpIsZero, VpSetInf, VpSetNaN, and VpSetSign.
Referenced by VpActiveRound(), VpFrac(), VpPower(), and VpSqrt().
Definition at line 5061 of file bigdecimal.c.
References BASE1, BDIGIT, BIGDECIMAL_NEGATIVE_P, Real::exponent, Real::frac, Real::MaxPrec, Real::Prec, PRIdSIZE, PRIdVALUE, RMPD_COMPONENT_FIGURES, Real::sign, SZ_INF, SZ_NaN, SZ_NINF, val, VpExponent10(), VpGetSign, VpIsDef, VpIsNaN, VpIsNegInf, VpIsPosInf, and VpIsZero.
Definition at line 670 of file bigdecimal.c.
References rb_cBigDecimal, and VpNewRbClass().
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 | ||
) |
Definition at line 5499 of file bigdecimal.c.
Referenced by VpAlloc().
Definition at line 4808 of file bigdecimal.c.
References BDIGIT, BDIGIT_DBL, and VpSetNaN.
Definition at line 5723 of file bigdecimal.c.
References BASE, BDIGIT, Real::exponent, Real::frac, isinf(), isnan, Real::MaxPrec, ne, Real::Prec, SIGNED_VALUE, val, VpSetNaN, VpSetNegInf, VpSetPosInf, VpSetSign, and VpSetZero.
Referenced by VpSqrt().
Definition at line 3755 of file bigdecimal.c.
Referenced by VpMemAlloc(), VpMemRealloc(), and VpSqrt().
Definition at line 5286 of file bigdecimal.c.
References BASE1, BASE_FIG, Real::exponent, Real::frac, VP_EXPORT, and VpHasVal.
Referenced by VpComp().
Definition at line 6236 of file bigdecimal.c.
References Real::exponent, Real::frac, Real::MaxPrec, Min, Real::Prec, VpAsgn(), VpGetSign, VpHasVal, VpSetSign, and VpSetZero.
VP_EXPORT double VpGetDoubleNaN | ( | void | ) |
Definition at line 3714 of file bigdecimal.c.
VP_EXPORT double VpGetDoubleNegInf | ( | void | ) |
Definition at line 3730 of file bigdecimal.c.
VP_EXPORT double VpGetDoubleNegZero | ( | void | ) |
Definition at line 3738 of file bigdecimal.c.
VP_EXPORT double VpGetDoublePosInf | ( | void | ) |
Definition at line 3722 of file bigdecimal.c.
VP_EXPORT size_t VpGetPrecLimit | ( | void | ) |
Definition at line 3598 of file bigdecimal.c.
References rb_thread_current(), and rb_thread_local_aref().
Referenced by VpAlloc(), and VpSetPrecLimit().
VP_EXPORT unsigned short VpGetRoundMode | ( | void | ) |
Definition at line 3633 of file bigdecimal.c.
References rb_thread_current(), and rb_thread_local_aref().
Referenced by VpSetRoundMode().
Definition at line 3926 of file bigdecimal.c.
References BASE, BASE1, BASE_FIG, DBLE_FIG, HALF_BASE, PRIuBDIGIT, VpAlloc(), VpGetDoubleNaN(), VpGetDoubleNegInf(), VpGetDoubleNegZero(), and VpGetDoublePosInf().
VP_EXPORT int VpIsRoundMode | ( | unsigned short | n | ) |
Definition at line 3649 of file bigdecimal.c.
References VP_EXPORT, VP_ROUND_CEIL, VP_ROUND_DOWN, VP_ROUND_FLOOR, VP_ROUND_HALF_DOWN, VP_ROUND_HALF_EVEN, VP_ROUND_HALF_UP, and VP_ROUND_UP.
Referenced by VpSetRoundMode().
Definition at line 6126 of file bigdecimal.c.
References BASE_FIG, BDIGIT, Real::frac, VP_EXPORT, VpExponent, VpHasVal, and VpMidRound().
VP_EXPORT void* VpMemAlloc | ( | size_t | mb | ) |
Definition at line 3509 of file bigdecimal.c.
References VP_EXCEPTION_MEMORY, VP_EXPORT, VpException(), and xmalloc.
VP_EXPORT void* VpMemRealloc | ( | void * | ptr, |
size_t | mb | ||
) |
Definition at line 3523 of file bigdecimal.c.
References VP_EXCEPTION_MEMORY, VP_EXPORT, VpException(), and xrealloc.
Definition at line 5964 of file bigdecimal.c.
References BASE, BASE_FIG, BDIGIT, BIGDECIMAL_NEGATIVE_P, BIGDECIMAL_POSITIVE_P, div, Real::exponent, Real::frac, Real::Prec, VP_ROUND_CEIL, VP_ROUND_DOWN, VP_ROUND_FLOOR, VP_ROUND_HALF_DOWN, VP_ROUND_HALF_EVEN, VP_ROUND_HALF_UP, VP_ROUND_UP, VpGetSign, and VpSetZero.
Referenced by VpActiveRound(), and VpLeftRound().
Definition at line 4679 of file bigdecimal.c.
References BDIGIT, and BDIGIT_DBL.
Definition at line 660 of file bigdecimal.c.
References Real::obj, RTYPEDDATA_DATA, TypedData_Wrap_Struct, VP_EXPORT, and VpAlloc().
Referenced by VpCreateRbObject().
Definition at line 3882 of file bigdecimal.c.
References BASE_FIG, Real::exponent, NULL, Real::Prec, SIGNED_VALUE, VP_EXPORT, and VpIsDef.
Definition at line 3957 of file bigdecimal.c.
VP_EXPORT int VpPower | ( | Real * | y, |
Real * | x, | ||
SIGNED_VALUE | n | ||
) |
Definition at line 6284 of file bigdecimal.c.
References BASE, BASE_FIG, BIGDECIMAL_POSITIVE_P, Real::exponent, Real::frac, Real::MaxPrec, NULL, Real::Prec, PRIdVALUE, PRIuBDIGIT, PRIuSIZE, SIGNED_VALUE, VpAlloc(), VpAsgn(), VpDivd(), VpFree(), VpGetSign, VpIsInf, VpIsNaN, VpIsPosInf, VpIsZero, VpMult(), VpSetInf, VpSetNaN, VpSetOne, VpSetSign, and VpSetZero.
VP_EXPORT size_t VpSetPrecLimit | ( | size_t | n | ) |
Definition at line 3614 of file bigdecimal.c.
References rmpd_set_thread_local_precision_limit, and VpGetPrecLimit().
VP_EXPORT unsigned short VpSetRoundMode | ( | unsigned short | n | ) |
Definition at line 3667 of file bigdecimal.c.
References rmpd_set_thread_local_rounding_mode, VpGetRoundMode(), and VpIsRoundMode().
Definition at line 5855 of file bigdecimal.c.
References BASE, BASE_FIG, BIGDECIMAL_NEGATIVE_P, DBLE_FIG, Real::exponent, f, if(), maxnr, Real::MaxPrec, Min, NULL, PRIdSIZE, SIGNED_VALUE, val, VP_EXCEPTION_OP, VP_EXPORT, VpAddSub(), VpAlloc(), VpAsgn(), VpChangeSign, VpDivd(), VpDtoV(), VpException(), VpFree(), VpIsNaN, VpIsOne, VpIsPosInf, VpIsZero, VpMult(), VpSetNaN, VpSetOne, and VpVtoD().
Definition at line 5303 of file bigdecimal.c.
References BASE1, BDIGIT_DBL, BIGDECIMAL_NEGATIVE_P, Real::frac, Real::Prec, strlen(), SZ_INF, SZ_NaN, SZ_NINF, VP_EXPORT, VpIsNaN, VpIsNegInf, VpIsPosInf, VpIsPosZero, and VpIsZero.
Definition at line 5433 of file bigdecimal.c.
References BASE, BASE1, BASE_FIG, BDIGIT, BIGDECIMAL_NEGATIVE_P, Real::exponent, Real::frac, Real::Prec, strlen(), and VpToSpecialString().
Definition at line 5350 of file bigdecimal.c.
References SZ_INF, SZ_NaN, SZ_NINF, VP_EXPORT, VpIsNaN, VpIsNegInf, VpIsPosInf, VpIsPosZero, and VpIsZero.
Referenced by VpToFString().
Definition at line 5385 of file bigdecimal.c.
References BDIGIT.
VP_EXPORT int VpVtoD | ( | double * | d, |
SIGNED_VALUE * | e, | ||
Real * | m | ||
) |
Definition at line 5659 of file bigdecimal.c.
References BASE, BASE_FIG, DBLE_FIG, div, Real::exponent, f, Real::frac, Min, Real::Prec, SIGNED_VALUE, VP_EXPORT, VpGetDoubleNaN(), VpGetDoubleNegInf(), VpGetDoubleNegZero(), VpGetDoublePosInf(), VpGetSign, VpIsNaN, VpIsNegInf, VpIsNegZero, VpIsPosInf, and VpIsPosZero.
Referenced by VpSqrt().
volatile const double gOne_ABCED9B4_CE73__00400511F31D = 1.0 |
Definition at line 3686 of file bigdecimal.c.
volatile const double gZero_ABCED9B1_CE73__00400511F31D = 0.0 |
Definition at line 3685 of file bigdecimal.c.
VALUE rb_cBigDecimal |
Definition at line 45 of file bigdecimal.c.
Referenced by VpCreateRbObject().
VALUE rb_mBigMath |
Definition at line 46 of file bigdecimal.c.