summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
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 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);