ruby/util.h: DECIMAL_SIZE_OF_BITS
* include/ruby/util.h (DECIMAL_SIZE_OF_BITS): a preprocessor constant macro to approximate decimal representation size of n-bits integer. * iseq.c (register_label): use DECIMAL_SIZE_OF_BITS for better approximation. * ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto. * common.mk (iseq.o), ext/bigdecimal/depend (bigdecimal.o): add dependency to ruby/util.h for DECIMAL_SIZE_OF_BITS. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0e9cad9a8e
commit
5e9b7bacc3
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Sun Jan 12 09:21:35 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* include/ruby/util.h (DECIMAL_SIZE_OF_BITS): a preprocessor
|
||||||
|
constant macro to approximate decimal representation size of n-bits
|
||||||
|
integer.
|
||||||
|
|
||||||
|
* iseq.c (register_label): use DECIMAL_SIZE_OF_BITS for better
|
||||||
|
approximation.
|
||||||
|
|
||||||
|
* ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto.
|
||||||
|
|
||||||
|
* common.mk (iseq.o), ext/bigdecimal/depend (bigdecimal.o): add
|
||||||
|
dependency to ruby/util.h for DECIMAL_SIZE_OF_BITS.
|
||||||
|
|
||||||
Fri Jan 10 16:27:20 2014 Yuki Yugui Sonoda <yugui@google.com>
|
Fri Jan 10 16:27:20 2014 Yuki Yugui Sonoda <yugui@google.com>
|
||||||
|
|
||||||
* vm_exec.c (cfp): Avoid generating invalid binary for
|
* vm_exec.c (cfp): Avoid generating invalid binary for
|
||||||
|
@ -786,7 +786,9 @@ compile.$(OBJEXT): {$(VPATH)}compile.c {$(VPATH)}iseq.h \
|
|||||||
{$(VPATH)}internal.h {$(VPATH)}vm_opts.h
|
{$(VPATH)}internal.h {$(VPATH)}vm_opts.h
|
||||||
iseq.$(OBJEXT): {$(VPATH)}iseq.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
|
iseq.$(OBJEXT): {$(VPATH)}iseq.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
|
||||||
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \
|
$(RUBY_H_INCLUDES) $(VM_CORE_H_INCLUDES) {$(VPATH)}insns.inc \
|
||||||
{$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}internal.h {$(VPATH)}vm_opts.h {$(VPATH)}ruby_atomic.h {$(VPATH)}eval_intern.h
|
{$(VPATH)}insns_info.inc {$(VPATH)}node_name.inc {$(VPATH)}internal.h \
|
||||||
|
{$(VPATH)}vm_opts.h {$(VPATH)}ruby_atomic.h {$(VPATH)}eval_intern.h \
|
||||||
|
{$(VPATH)}util.h
|
||||||
vm.$(OBJEXT): {$(VPATH)}vm.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
|
vm.$(OBJEXT): {$(VPATH)}vm.c {$(VPATH)}gc.h {$(VPATH)}iseq.h \
|
||||||
{$(VPATH)}eval_intern.h $(RUBY_H_INCLUDES) $(ENCODING_H_INCLUDES) \
|
{$(VPATH)}eval_intern.h $(RUBY_H_INCLUDES) $(ENCODING_H_INCLUDES) \
|
||||||
$(VM_CORE_H_INCLUDES) {$(VPATH)}vm_method.c {$(VPATH)}vm_eval.c \
|
$(VM_CORE_H_INCLUDES) {$(VPATH)}vm_method.c {$(VPATH)}vm_eval.c \
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
# define BIGDECIMAL_ENABLE_VPRINT 1
|
# define BIGDECIMAL_ENABLE_VPRINT 1
|
||||||
#endif
|
#endif
|
||||||
#include "bigdecimal.h"
|
#include "bigdecimal.h"
|
||||||
|
#include "ruby/util.h"
|
||||||
|
|
||||||
#ifndef BIGDECIMAL_DEBUG
|
#ifndef BIGDECIMAL_DEBUG
|
||||||
# define NDEBUG
|
# define NDEBUG
|
||||||
@ -2919,7 +2920,7 @@ get_vp_value:
|
|||||||
RB_GC_GUARD(vn) = SSIZET2NUM(n);
|
RB_GC_GUARD(vn) = SSIZET2NUM(n);
|
||||||
expo = VpExponent10(vx);
|
expo = VpExponent10(vx);
|
||||||
if (expo < 0 || expo >= 3) {
|
if (expo < 0 || expo >= 3) {
|
||||||
char buf[SIZEOF_VALUE * CHAR_BIT / 3 + 4];
|
char buf[DECIMAL_SIZE_OF_BITS(SIZEOF_VALUE * CHAR_BIT) + 4];
|
||||||
snprintf(buf, sizeof(buf), "1E%"PRIdVALUE, -expo);
|
snprintf(buf, sizeof(buf), "1E%"PRIdVALUE, -expo);
|
||||||
x = BigDecimal_mult2(x, ToValue(VpCreateRbObject(1, buf)), vn);
|
x = BigDecimal_mult2(x, ToValue(VpCreateRbObject(1, buf)), vn);
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers)
|
bigdecimal.o: bigdecimal.c bigdecimal.h $(HDRS) $(ruby_headers) $(hdrdir)/ruby/util.h
|
||||||
|
@ -47,6 +47,9 @@ extern "C" {
|
|||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_BEGIN
|
RUBY_SYMBOL_EXPORT_BEGIN
|
||||||
|
|
||||||
|
#define DECIMAL_SIZE_OF_BITS(n) (((n) * 3010 + 9998) / 9999)
|
||||||
|
/* an approximation of ceil(n * log10(2)), upto 65536 at least */
|
||||||
|
|
||||||
#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
|
#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
|
||||||
unsigned long ruby_scan_oct(const char *, size_t, size_t *);
|
unsigned long ruby_scan_oct(const char *, size_t, size_t *);
|
||||||
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
|
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
|
||||||
|
3
iseq.c
3
iseq.c
@ -10,6 +10,7 @@
|
|||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
|
#include "ruby/util.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "eval_intern.h"
|
#include "eval_intern.h"
|
||||||
|
|
||||||
@ -1612,7 +1613,7 @@ static VALUE
|
|||||||
register_label(struct st_table *table, unsigned long idx)
|
register_label(struct st_table *table, unsigned long idx)
|
||||||
{
|
{
|
||||||
VALUE sym;
|
VALUE sym;
|
||||||
char buff[8 + (sizeof(idx) * CHAR_BIT * 32 / 100)];
|
char buff[7 + DECIMAL_SIZE_OF_BITS(sizeof(idx) * CHAR_BIT)];
|
||||||
|
|
||||||
snprintf(buff, sizeof(buff), "label_%lu", idx);
|
snprintf(buff, sizeof(buff), "label_%lu", idx);
|
||||||
sym = ID2SYM(rb_intern(buff));
|
sym = ID2SYM(rb_intern(buff));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user