diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-05 10:27:34 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-05 10:27:34 +0000 |
commit | 9b64dfe3b8f0343ebf97ae80d3a4ec3f4bd115b3 (patch) | |
tree | 7acd7b77321fdbc63149b47fde3bace6f7733614 /numeric.c | |
parent | 06d4e3b42d836b762c29cdc9dc7181caf14dcdec (diff) |
990205
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -184,11 +184,14 @@ flo_to_s(flt) VALUE flt; { char buf[24]; - - snprintf(buf, 24, "%.10g", RFLOAT(flt)->value); - if (strchr(buf, '.') == 0 && - strcmp(buf, "Inf") != 0 && - strcmp(buf, "NaN") != 0) { + char *s; + + sprintf(buf, "%-.10g", RFLOAT(flt)->value); + if (s = strchr(buf, ' ')) *s = '\0'; + s = buf; if (s[0] == '-') s++; + if (strchr(s, '.') == 0 && + strcmp(s, "Inf") != 0 && + strcmp(s, "NaN") != 0) { int len = strlen(buf); char *ind = strchr(buf, 'e'); @@ -276,14 +279,11 @@ flo_div(x, y) switch (TYPE(y)) { case T_FIXNUM: f_y = FIX2LONG(y); - if (f_y == 0) rb_num_zerodiv(); return rb_float_new(RFLOAT(x)->value / (double)f_y); case T_BIGNUM: d = rb_big2dbl(y); - if (d == 0.0) rb_num_zerodiv(); return rb_float_new(RFLOAT(x)->value / d); case T_FLOAT: - if (RFLOAT(y)->value == 0.0) rb_num_zerodiv(); return rb_float_new(RFLOAT(x)->value / RFLOAT(y)->value); default: return rb_num_coerce_bin(x, y); @@ -668,8 +668,12 @@ rb_num2long(val) return (long)(RFLOAT(val)->value); } else { - rb_raise(rb_eTypeError, "float %g out of rang of integer", - RFLOAT(val)->value); + char buf[24]; + char *s; + + sprintf(buf, "%-.10g", RFLOAT(val)->value); + if (s = strchr(buf, ' ')) *s = '\0'; + rb_raise(rb_eTypeError, "float %s out of rang of integer", buf); } case T_BIGNUM: |