From 3976feed73bf4ec27183824870ee077c2b5b00b1 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 24 Feb 1999 04:31:29 +0000 Subject: 990224 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 804356d99a..65e27c0bd2 100644 --- a/numeric.c +++ b/numeric.c @@ -25,7 +25,8 @@ VALUE rb_cFloat; VALUE rb_cInteger; VALUE rb_cFixnum; -VALUE rb_eZeroDiv; +VALUE rb_eZeroDivError; +VALUE rb_eFloatDomainError; ID rb_frame_last_func(); VALUE rb_float_new(); @@ -34,7 +35,7 @@ double rb_big2dbl(); void rb_num_zerodiv() { - rb_raise(rb_eZeroDiv, "divided by 0"); + rb_raise(rb_eZeroDivError, "divided by 0"); } static VALUE @@ -188,13 +189,17 @@ flo_to_s(flt) { char buf[24]; char *s; - - sprintf(buf, "%-.10g", RFLOAT(flt)->value); + double value = RFLOAT(flt)->value; + + if (isinf(value)) + return rb_str_new2(value < 0 ? "-Infinity" : "Infinity"); + else if(isnan(value)) + return rb_str_new2("NaN"); + else + sprintf(buf, "%-.10g", 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) { + if (strchr(s, '.') == 0) { int len = strlen(buf); char *ind = strchr(buf, 'e'); @@ -686,6 +691,11 @@ rb_num2long(val) rb_raise(rb_eTypeError, "no implicit conversion from string"); return Qnil; /* not reached */ + case T_TRUE: + case T_FALSE: + rb_raise(rb_eTypeError, "no implicit conversion from boolean"); + return Qnil; /* not reached */ + default: val = rb_rescue(to_integer, val, fail_to_integer, val); if (!rb_obj_is_kind_of(val, rb_cInteger)) { @@ -1405,12 +1415,13 @@ Init_Numeric() { #ifdef __FreeBSD__ /* allow divide by zero -- Inf */ - fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV)); + fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL)); #endif coerce = rb_intern("coerce"); to_i = rb_intern("to_i"); - rb_eZeroDiv = rb_define_class("ZeroDivisionError", rb_eStandardError); + rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError); + rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eStandardError); rb_cNumeric = rb_define_class("Numeric", rb_cObject); rb_include_module(rb_cNumeric, rb_mComparable); -- cgit v1.2.3