summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-24 04:31:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-24 04:31:29 +0000
commit3976feed73bf4ec27183824870ee077c2b5b00b1 (patch)
treecb461ab9246a2c8e13d373a8c2d2e6378e4db9cc /numeric.c
parent51fa86ece2d2b0f72c86c70fe1314e412c7a9e68 (diff)
990224
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/numeric.c b/numeric.c
index 804356d99a5..65e27c0bd21 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);