Skip to content

Commit 09ee3f4

Browse files
authored
Remove unused #define macros (#376)
* Remove unused #define macros * Fix typo in comment * Change BASE and BASE_FIG detection in test helper
1 parent 0f0b4ed commit 09ee3f4

3 files changed

Lines changed: 9 additions & 94 deletions

File tree

ext/bigdecimal/bigdecimal.c

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ bdvalue_nullable(BDVALUE v)
115115
#define HALF_BASE (BASE/2)
116116
#define BASE1 (BASE/10)
117117

118-
#define LOG10_2 0.3010299956639812
119-
120118
#ifndef RRATIONAL_ZERO_P
121119
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(rb_rational_num(x)) && \
122120
FIX2LONG(rb_rational_num(x)) == 0)
@@ -537,7 +535,7 @@ GetBDValueMust(VALUE v)
537535
static inline VALUE
538536
BigDecimal_double_fig(VALUE self)
539537
{
540-
return INT2FIX(VpDblFig());
538+
return INT2FIX(BIGDECIMAL_DOUBLE_FIGURES);
541539
}
542540

543541
/* call-seq:
@@ -852,7 +850,7 @@ BigDecimal_dump(int argc, VALUE *argv, VALUE self)
852850
GUARD_OBJ(v, GetBDValueMust(self));
853851
dump = rb_str_new(0, VpNumOfChars(v.real, "E")+50);
854852
psz = RSTRING_PTR(dump);
855-
snprintf(psz, RSTRING_LEN(dump), "%"PRIuSIZE":", VpPrec(v.real)*VpBaseFig());
853+
snprintf(psz, RSTRING_LEN(dump), "%"PRIuSIZE":", v.real->Prec*VpBaseFig());
856854
len = strlen(psz);
857855
VpToString(v.real, psz+len, RSTRING_LEN(dump)-len, 0, 0);
858856
rb_str_resize(dump, strlen(psz));
@@ -2170,7 +2168,7 @@ BigDecimal_div2(VALUE self, VALUE b, VALUE n)
21702168
VpSetPrecLimit(pl);
21712169
if (!VpIsZero(res.real)) {
21722170
// Remainder value affects rounding result.
2173-
// ROUND_UP cv = 0.1e0 with ix=10 will be:
2171+
// ROUND_UP cv = 0.1e0 with idx=10 will be:
21742172
// 0.1e0 if remainder == 0
21752173
// 0.1000000001e0 if remainder != 0
21762174
size_t idx = roomof(ix, BASE_FIG);
@@ -4416,7 +4414,7 @@ Init_bigdecimal(void)
44164414
* guarantee that two groups could always be multiplied together without
44174415
* overflow.)
44184416
*/
4419-
rb_define_const(rb_cBigDecimal, "BASE", INT2FIX((SIGNED_VALUE)VpBaseVal()));
4417+
rb_define_const(rb_cBigDecimal, "BASE", INT2FIX((SIGNED_VALUE)BASE));
44204418

44214419
/* Exceptions */
44224420

@@ -4635,10 +4633,6 @@ static Real *VpConstPt5; /* constant 0.5 */
46354633
#define maxnr 100UL /* Maximum iterations for calculating sqrt. */
46364634
/* used in VpSqrt() */
46374635

4638-
/* ETC */
4639-
#define MemCmp(x,y,z) memcmp(x,y,z)
4640-
#define StrCmp(x,y) strcmp(x,y)
4641-
46424636
enum op_sw {
46434637
OP_SW_ADD = 1, /* + */
46444638
OP_SW_SUB, /* - */
@@ -4865,15 +4859,6 @@ VpGetDoubleNegZero(void) /* Returns the value of -0 */
48654859
return nzero;
48664860
}
48674861

4868-
#if 0 /* unused */
4869-
VP_EXPORT int
4870-
VpIsNegDoubleZero(double v)
4871-
{
4872-
double z = VpGetDoubleNegZero();
4873-
return MemCmp(&v,&z,sizeof(v))==0;
4874-
}
4875-
#endif
4876-
48774862
VP_EXPORT int
48784863
VpException(unsigned short f, const char *str,int always)
48794864
{
@@ -6977,64 +6962,6 @@ VpDtoV(Real *m, double d)
69776962
return;
69786963
}
69796964

6980-
/*
6981-
* m <- ival
6982-
*/
6983-
#if 0 /* unused */
6984-
VP_EXPORT void
6985-
VpItoV(Real *m, SIGNED_VALUE ival)
6986-
{
6987-
size_t mm, ind_m;
6988-
size_t val, v1, v2, v;
6989-
int isign;
6990-
SIGNED_VALUE ne;
6991-
6992-
if (ival == 0) {
6993-
VpSetZero(m, 1);
6994-
goto Exit;
6995-
}
6996-
isign = 1;
6997-
val = ival;
6998-
if (ival < 0) {
6999-
isign = -1;
7000-
val =(size_t)(-ival);
7001-
}
7002-
ne = 0;
7003-
ind_m = 0;
7004-
mm = m->MaxPrec;
7005-
while (ind_m < mm) {
7006-
m->frac[ind_m] = 0;
7007-
++ind_m;
7008-
}
7009-
ind_m = 0;
7010-
while (val > 0) {
7011-
if (val) {
7012-
v1 = val;
7013-
v2 = 1;
7014-
while (v1 >= BASE) {
7015-
v1 /= BASE;
7016-
v2 *= BASE;
7017-
}
7018-
val = val - v2 * v1;
7019-
v = v1;
7020-
}
7021-
else {
7022-
v = 0;
7023-
}
7024-
m->frac[ind_m] = v;
7025-
++ind_m;
7026-
++ne;
7027-
}
7028-
m->Prec = ind_m - 1;
7029-
m->exponent = ne;
7030-
VpSetSign(m, isign);
7031-
VpNmlz(m);
7032-
7033-
Exit:
7034-
return;
7035-
}
7036-
#endif
7037-
70386965
/*
70396966
* y = SQRT(x), y*y - x =>0
70406967
*/
@@ -7317,7 +7244,7 @@ VpLeftRound(Real *y, unsigned short f, ssize_t nf)
73177244
DECDIG v;
73187245
if (!VpHasVal(y)) return 0; /* Unable to round */
73197246
v = y->frac[0];
7320-
nf -= VpExponent(y) * (ssize_t)BASE_FIG;
7247+
nf -= y->exponent * (ssize_t)BASE_FIG;
73217248
while ((v /= 10) != 0) nf--;
73227249
nf += (ssize_t)BASE_FIG-1;
73237250
return VpMidRound(y, f, nf);

ext/bigdecimal/bigdecimal.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ typedef struct {
196196

197197
#define VpBaseFig() BIGDECIMAL_COMPONENT_FIGURES
198198
#define VpDblFig() BIGDECIMAL_DOUBLE_FIGURES
199-
#define VpBaseVal() BIGDECIMAL_BASE
200199

201200
/* Zero,Inf,NaN (isinf(),isnan() used to check) */
202201
VP_EXPORT double VpGetDoubleNaN(void);
@@ -214,9 +213,6 @@ VP_EXPORT unsigned short VpGetRoundMode(void);
214213
VP_EXPORT unsigned short VpSetRoundMode(unsigned short n);
215214

216215
VP_EXPORT int VpException(unsigned short f,const char *str,int always);
217-
#if 0 /* unused */
218-
VP_EXPORT int VpIsNegDoubleZero(double v);
219-
#endif
220216
VP_EXPORT size_t VpNumOfChars(Real *vp,const char *pszFmt);
221217
VP_EXPORT size_t VpInit(DECDIG BaseVal);
222218
VP_EXPORT Real *VpAlloc(size_t mx, const char *szVal, int strict_p, int exc);
@@ -233,9 +229,6 @@ VP_EXPORT void VpToFString(Real *a, char *buf, size_t bufsize, size_t fFmt, int
233229
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);
234230
VP_EXPORT int VpVtoD(double *d, SIGNED_VALUE *e, Real *m);
235231
VP_EXPORT void VpDtoV(Real *m,double d);
236-
#if 0 /* unused */
237-
VP_EXPORT void VpItoV(Real *m,S_INT ival);
238-
#endif
239232
VP_EXPORT int VpSqrt(Real *y,Real *x);
240233
VP_EXPORT int VpActiveRound(Real *y, Real *x, unsigned short f, ssize_t il);
241234
VP_EXPORT int VpMidRound(Real *y, unsigned short f, ssize_t nf);
@@ -256,10 +249,6 @@ VP_EXPORT Real *VpOne(void);
256249
#define Max(a, b) (((a)>(b))?(a):(b))
257250
#define Min(a, b) (((a)>(b))?(b):(a))
258251

259-
#define VpMaxPrec(a) ((a)->MaxPrec)
260-
#define VpPrec(a) ((a)->Prec)
261-
#define VpGetFlag(a) ((a)->flag)
262-
263252
/* Sign */
264253

265254
/* VpGetSign(a) returns 1,-1 if a>0,a<0 respectively */
@@ -294,7 +283,6 @@ VP_EXPORT Real *VpOne(void);
294283
#define VpSetInf(a,s) (void)(((s)>0)?VpSetPosInf(a):VpSetNegInf(a))
295284
#define VpHasVal(a) (a->frac[0])
296285
#define VpIsOne(a) ((a->Prec==1)&&(a->frac[0]==1)&&(a->exponent==1))
297-
#define VpExponent(a) (a->exponent)
298286
#ifdef BIGDECIMAL_DEBUG
299287
int VpVarCheck(Real * v);
300288
#endif /* BIGDECIMAL_DEBUG */

test/bigdecimal/helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
require 'rbconfig/sizeof'
55

66
module TestBigDecimalBase
7-
if BigDecimal(0)._dump.start_with?('9')
7+
BASE = BigDecimal::BASE
8+
case BASE
9+
when 1000000000
810
SIZEOF_DECDIG = RbConfig::SIZEOF["int32_t"]
9-
BASE = 1_000_000_000
1011
BASE_FIG = 9
11-
else
12+
when 10000
1213
SIZEOF_DECDIG = RbConfig::SIZEOF["int16_t"]
13-
BASE = 10000
1414
BASE_FIG = 4
1515
end
1616

0 commit comments

Comments
 (0)