1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* marshal.c (div0), numeric.c (infinite_value): new functions to

get rid of VC divion by 0 warnings.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-03-12 09:09:15 +00:00
parent 1c6ca1eec5
commit 080525aa68
3 changed files with 38 additions and 8 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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)));