summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-01 07:34:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-01 07:34:58 +0000
commit9b0dd20cbb3d0077c374509eb230adba84ed5488 (patch)
tree2a7936d597eff812a4e3fa896de7439b884a75f8 /numeric.c
parent2344efc3835c3226fa06a85e6f3b1871415b8ad1 (diff)
990201
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/numeric.c b/numeric.c
index 2562a7778e..5a4d4930ac 100644
--- a/numeric.c
+++ b/numeric.c
@@ -183,10 +183,10 @@ static VALUE
flo_to_s(flt)
VALUE flt;
{
- char buf[32];
+ char buf[24];
- sprintf(buf, "%g", RFLOAT(flt)->value);
- if (strchr(buf, '.') == 0) {
+ snprintf(buf, 24, "%.10g", RFLOAT(flt)->value);
+ if (strchr(buf, '.') == 0 && strcmp(buf, "Inf") != 0) {
int len = strlen(buf);
char *ind = strchr(buf, 'e');
@@ -704,7 +704,7 @@ rb_num2int(val)
long num = rb_num2long(val);
if (num < INT_MIN || INT_MAX < num) {
- rb_raise(rb_eArgError, "integer %d too big to convert to `int'.", num);
+ rb_raise(rb_eArgError, "integer %d too big to convert to `int'", num);
}
return (int)num;
}
@@ -716,7 +716,7 @@ rb_fix2int(val)
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
if (num < INT_MIN || INT_MAX < num) {
- rb_raise(rb_eArgError, "integer %d too big to convert to `int'.", num);
+ rb_raise(rb_eArgError, "integer %d too big to convert to `int'", num);
}
return (int)num;
}
@@ -781,7 +781,7 @@ static VALUE
rb_fix_induced_from(klass, x)
VALUE klass, x;
{
- return rb_funcall(x, rb_intern("to_i"), 0);
+ return rb_num2fix(x);
}
static VALUE
@@ -818,7 +818,7 @@ rb_fix2str(x, base)
else if (base == 8) fmt[2] = 'o';
else rb_fatal("fixnum cannot treat base %d", base);
- sprintf(buf, fmt, FIX2LONG(x));
+ snprintf(buf, 22, fmt, FIX2LONG(x));
return rb_str_new2(buf);
}