summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-19 16:28:53 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-19 16:28:53 +0000
commit8302aa5f951e85984899d73fafa6bef2f23deddd (patch)
treee2d91c7eaadad662053210ef286ded8d89601f26 /ext/bigdecimal
parentb809254c8ce37ac996a7e0b2a9f27387cf7ee704 (diff)
merge revision(s) 44569:44572,44576:44579,44581,44590:44594,44607,44608,44614,44615:
iseq.c: linear search * iseq.c (iseq_type_from_id): linear search instead of hash lookup for small fixed number keys. ------------------------------------------------------------------------ r44570 | nobu | 2014-01-12 17:11:32 +0900 (Sun, 12 Jan 2014) | 4 lines tcltklib.c: create_ip_exc format argument * ext/tk/tcltklib.c (create_ip_exc): format argument must not be a dynamic string, not to contain unescaped %. ------------------------------------------------------------------------ r44571 | nobu | 2014-01-12 17:11:34 +0900 (Sun, 12 Jan 2014) | 5 lines stubs.c: library name strings * ext/tk/stubs.c (ruby_open_tcl_dll, ruby_open_tk_dll): make library names by string literal concatenation at compilation time, not by sprintf() at runtime. ------------------------------------------------------------------------ r44572 | nobu | 2014-01-12 17:11:36 +0900 (Sun, 12 Jan 2014) | 1 line ext: use rb_sprintf() and rb_vsprintf() with PRIsVALUE * ext/bigdecimal/bigdecimal.c (CLASS_NAME): macro to wrap depending on PRIsVALUE for 1.9. [Backport #9406] * ext/bigdecimal/bigdecimal.c (DECIMAL_SIZE_OF_BITS): fallback definition for 2.1 or older. [ruby-core:59750] [Backport #9406] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index a5ddd6b7c6..9601d1c70f 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -102,6 +102,20 @@ bigzero_p(VALUE x)
# define RRATIONAL_NEGATIVE_P(x) RTEST(rb_funcall((x), '<', 1, INT2FIX(0)))
#endif
+#ifndef DECIMAL_SIZE_OF_BITS
+#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
+/* an approximation of ceil(n * log10(2)), upto 65536 at least */
+#endif
+
+#ifdef PRIsVALUE
+# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
+# define RB_OBJ_STRING(obj) (obj)
+#else
+# define PRIsVALUE "s"
+# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
+# define RB_OBJ_STRING(obj) StringValueCStr(obj)
+#endif
+
/*
* ================== Ruby Interface part ==========================
*/
@@ -262,8 +276,8 @@ SomeOneMayDoIt:
unable_to_coerce_without_prec:
if (must) {
rb_raise(rb_eArgError,
- "%s can't be coerced into BigDecimal without a precision",
- rb_obj_classname(v));
+ "%"PRIsVALUE" can't be coerced into BigDecimal without a precision",
+ RB_OBJ_CLASSNAME(v));
}
return NULL;
}
@@ -2195,8 +2209,8 @@ retry:
/* fall through */
default:
rb_raise(rb_eTypeError,
- "wrong argument type %s (expected scalar Numeric)",
- rb_obj_classname(vexp));
+ "wrong argument type %"PRIsVALUE" (expected scalar Numeric)",
+ RB_OBJ_CLASSNAME(vexp));
}
if (VpIsZero(x)) {
@@ -2451,8 +2465,8 @@ BigDecimal_new(int argc, VALUE *argv)
case T_RATIONAL:
if (NIL_P(nFig)) {
rb_raise(rb_eArgError,
- "can't omit precision for a %s.",
- rb_class2name(CLASS_OF(iniValue)));
+ "can't omit precision for a %"PRIsVALUE".",
+ RB_OBJ_CLASSNAME(iniValue));
}
return GetVpValueWithPrec(iniValue, mf, 1);