summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--marshal.c22
-rw-r--r--numeric.c19
3 files changed, 38 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b3b130..1d0185c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Thu Mar 12 18:02:05 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Thu Mar 12 18:09:14 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * marshal.c (div0), numeric.c (infinite_value): new functions to
+ get rid of VC divion by 0 warnings.
* st.c: use st_index_t for indexes instead of int.
diff --git a/marshal.c b/marshal.c
index 8a3a64e..bf4e332 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1201,6 +1201,20 @@ obj_alloc_by_path(const char *path, struct load_arg *arg)
return rb_obj_alloc(klass);
}
+#if defined _MSC_VER && _MSC_VER >= 1300
+#pragma warning(push)
+#pragma warning(disable:4723)
+#endif
+static double
+div0(double x)
+{
+ double t = 0.0;
+ return x / t;
+}
+#if defined _MSC_VER && _MSC_VER >= 1300
+#pragma warning(pop)
+#endif
+
static VALUE
r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
@@ -1292,18 +1306,18 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
case TYPE_FLOAT:
{
- double d, t = 0.0;
+ double d;
VALUE str = r_bytes(arg);
const char *ptr = RSTRING_PTR(str);
if (strcmp(ptr, "nan") == 0) {
- d = t / t;
+ d = div0(0.0);
}
else if (strcmp(ptr, "inf") == 0) {
- d = 1.0 / t;
+ d = div0(+1.0);
}
else if (strcmp(ptr, "-inf") == 0) {
- d = -1.0 / t;
+ d = div0(-1.0);
}
else {
char *e;
diff --git a/numeric.c b/numeric.c
index fc0b717..9af2b14 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2445,6 +2445,20 @@ int_pow(long x, unsigned long y)
return LONG2NUM(z);
}
+#if defined _MSC_VER && _MSC_VER >= 1300
+#pragma warning(push)
+#pragma warning(disable:4723)
+#endif
+static inline double
+infinite_value(void)
+{
+ static const double zero = 0.0;
+ return 1.0 / zero;
+}
+#if defined _MSC_VER && _MSC_VER >= 1300
+#pragma warning(pop)
+#endif
+
/*
* call-seq:
* fix ** other => Numeric
@@ -2460,7 +2474,6 @@ int_pow(long x, unsigned long y)
static VALUE
fix_pow(VALUE x, VALUE y)
{
- static const double zero = 0.0;
long a = FIX2LONG(x);
if (FIXNUM_P(y)) {
@@ -2473,7 +2486,7 @@ fix_pow(VALUE x, VALUE y)
if (b == 1) return x;
if (a == 0) {
if (b > 0) return INT2FIX(0);
- return DBL2NUM(1.0 / zero);
+ return DBL2NUM(infinite_value());
}
if (a == 1) return INT2FIX(1);
if (a == -1) {
@@ -2501,7 +2514,7 @@ fix_pow(VALUE x, VALUE y)
case T_FLOAT:
if (RFLOAT_VALUE(y) == 0.0) return DBL2NUM(1.0);
if (a == 0) {
- return DBL2NUM(RFLOAT_VALUE(y) < 0 ? (1.0 / zero) : 0.0);
+ return DBL2NUM(RFLOAT_VALUE(y) < 0 ? infinite_value() : 0.0);
}
if (a == 1) return DBL2NUM(1.0);
return DBL2NUM(pow((double)a, RFLOAT_VALUE(y)));