summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-31 08:42:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-31 08:42:44 +0000
commit5b9afca5e435f37c7affce56e81e6bc20a5d8b3c (patch)
tree2c833c1b565733ed271fd9071f68150d40142923
parent7126624b4effe49919e35224054cc48e86716f39 (diff)
* numeric.c (rb_num_coerce_relop): export function.
* marshal.c (w_object): check has been dropped. "_dump must return string." [ruby-dev:21024] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--doc/NEWS2
-rw-r--r--intern.h5
-rw-r--r--io.c3
-rw-r--r--lib/complex.rb132
-rw-r--r--marshal.c3
-rw-r--r--numeric.c20
7 files changed, 91 insertions, 83 deletions
diff --git a/ChangeLog b/ChangeLog
index fb708da334..ee2e88c665 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,10 @@ Thu Jul 31 12:36:11 2003 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* bin/erb, lib/erb.rb: add explicit trim mode.
+Thu Jul 31 04:59:10 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (rb_num_coerce_relop): export function.
+
Thu Jul 31 00:17:19 2003 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/ftp.rb (return_code): obsolete.
@@ -22,6 +26,11 @@ Thu Jul 31 00:17:19 2003 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/ftp.rb (last_response): new method.
+Wed Jul 30 23:55:44 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * marshal.c (w_object): check has been dropped. "_dump must return
+ string." [ruby-dev:21024]
+
Wed Jul 30 22:35:19 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/mkmf.rb (dir_config): allow multiple directories separated
diff --git a/doc/NEWS b/doc/NEWS
index d190193e1b..22e1ca0a68 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -3,7 +3,7 @@ This file is not actively maintained. See ChangeLog for recent changes.
: -W option
new option to specify warning level. -W0 to shut up warnings, -W1 for normal level,
- -W3 for verbose level. -w equals to -W1.
+ -W2 for verbose level. -w equals to -W1.
: Marshal to use marshal_dump and marshal_load
diff --git a/intern.h b/intern.h
index bd8c9725ba..e94077e70a 100644
--- a/intern.h
+++ b/intern.h
@@ -268,8 +268,8 @@ VALUE rb_io_print _((int, VALUE*, VALUE));
VALUE rb_io_puts _((int, VALUE*, VALUE));
VALUE rb_file_open _((const char*, const char*));
VALUE rb_gets _((void));
-void rb_write_deferr _((const char*));
-void rb_write_deferr2 _((const char*, long));
+void rb_write_error _((const char*));
+void rb_write_error2 _((const char*, long));
/* marshal.c */
VALUE rb_marshal_dump _((VALUE, VALUE));
VALUE rb_marshal_load _((VALUE));
@@ -277,6 +277,7 @@ VALUE rb_marshal_load _((VALUE));
void rb_num_zerodiv _((void));
VALUE rb_num_coerce_bin _((VALUE, VALUE));
VALUE rb_num_coerce_cmp _((VALUE, VALUE));
+VALUE rb_num_coerce_relop _((VALUE, VALUE));
VALUE rb_float_new _((double));
VALUE rb_num2fix _((VALUE));
VALUE rb_fix2str _((VALUE, int));
diff --git a/io.c b/io.c
index 454d0926b0..aba4dc22cd 100644
--- a/io.c
+++ b/io.c
@@ -95,6 +95,7 @@ VALUE rb_eEOFError;
VALUE rb_eIOError;
VALUE rb_stdin, rb_stdout, rb_stderr;
+VALUE rb_deferr; /* rescue VIM plugin */
static VALUE orig_stdout, orig_stderr;
VALUE rb_output_fs;
@@ -4128,7 +4129,7 @@ Init_IO()
rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter);
orig_stdout = rb_stdout;
- orig_stderr = rb_stderr;
+ rb_deferr = orig_stderr = rb_stderr;
/* variables to be removed in 1.8.1 */
rb_define_hooked_variable("$defout", &rb_stdout, 0, defout_setter);
diff --git a/lib/complex.rb b/lib/complex.rb
index 9b5419ba61..9300f391e8 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -27,22 +27,71 @@
#
+# Numeric is a built-in class on which Fixnum, Bignum, etc., are based. Here
+# some methods are added so that all number types can be treated to some extent
+# as Complex numbers.
+#
+class Numeric
+ #
+ # Returns a Complex number <tt>(0,<i>self</i>)</tt>.
+ #
+ def im
+ Complex(0, self)
+ end
+
+ #
+ # The real part of a complex number, i.e. <i>self</i>.
+ #
+ def real
+ self
+ end
+
+ #
+ # The imaginary part of a complex number, i.e. 0.
+ #
+ def image
+ 0
+ end
+ alias imag image
+
+ #
+ # See Complex#arg.
+ #
+ def arg
+ if self >= 0
+ return 0
+ else
+ return Math::PI
+ end
+ end
+ alias angle arg
+
+ #
+ # See Complex#polar.
+ #
+ def polar
+ return abs, arg
+ end
+
+ #
+ # See Complex#conjugate (short answer: returns <i>self</i>).
+ #
+ def conjugate
+ self
+ end
+ alias conj conjugate
+end
+
+
+#
# Creates a Complex number. +a+ and +b+ should be Numeric. The result will be
# <tt>a+bi</tt>.
#
def Complex(a, b = 0)
- if a.kind_of?(Complex) and b == 0
- a
- elsif b.kind_of?(Complex)
- if a.kind_of?(Complex)
- Complex(a.real-b.image, a.image + b.real)
- else
- Complex(a-b.image, b.real)
- end
- elsif b == 0 and defined? Complex::Unify
+ if b == 0 and (a.kind_of?(Complex) or defined? Complex::Unify)
a
else
- Complex.new!(a, b)
+ Complex.new( a.real-b.imag, a.imag+b.real )
end
end
@@ -361,61 +410,6 @@ class Complex < Numeric
end
-#
-# Numeric is a built-in class on which Fixnum, Bignum, etc., are based. Here
-# some methods are added so that all number types can be treated to some extent
-# as Complex numbers.
-#
-class Numeric
- #
- # Returns a Complex number <tt>(0,<i>self</i>)</tt>.
- #
- def im
- Complex(0, self)
- end
-
- #
- # The real part of a complex number, i.e. <i>self</i>.
- #
- def real
- self
- end
-
- #
- # The imaginary part of a complex number, i.e. 0.
- #
- def image
- 0
- end
- alias imag image
-
- #
- # See Complex#arg.
- #
- def arg
- if self >= 0
- return 0
- else
- return Math::PI
- end
- end
- alias angle arg
-
- #
- # See Complex#polar.
- #
- def polar
- return abs, arg
- end
-
- #
- # See Complex#conjugate (short answer: returns <i>self</i>).
- #
- def conjugate
- self
- end
- alias conj conjugate
-end
module Math
@@ -538,7 +532,7 @@ module Math
end
def acos(z)
- if Complex.generic?(z)
+ if Complex.generic?(z) and z >= -1 and z <= 1
acos!(z)
else
-1.0.im * log( z + 1.0.im * sqrt(1.0-z*z) )
@@ -546,7 +540,7 @@ module Math
end
def asin(z)
- if Complex.generic?(z)
+ if Complex.generic?(z) and z >= -1 and z <= 1
asin!(z)
else
-1.0.im * log( 1.0.im * z + sqrt(1.0-z*z) )
@@ -570,7 +564,7 @@ module Math
end
def acosh(z)
- if Complex.generic?(z)
+ if Complex.generic?(z) and z >= 1
acosh!(z)
else
log( z + sqrt(z*z-1.0) )
@@ -586,7 +580,7 @@ module Math
end
def atanh(z)
- if Complex.generic?(z)
+ if Complex.generic?(z) and z >= -1 and z <= 1
atanh!(z)
else
log( (1.0+z) / (1.0-z) ) / 2.0
diff --git a/marshal.c b/marshal.c
index eeed643d7b..c5f68bd1e8 100644
--- a/marshal.c
+++ b/marshal.c
@@ -493,6 +493,9 @@ w_object(obj, arg, limit)
VALUE v;
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
+ if (TYPE(v) != T_STRING) {
+ rb_raise(rb_eTypeError, "_dump() must return string");
+ }
w_class(TYPE_USERDEF, obj, arg);
w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg);
if (ivtbl) w_ivar(ivtbl, &c_arg);
diff --git a/numeric.c b/numeric.c
index f9eb35c884..d9278f06ba 100644
--- a/numeric.c
+++ b/numeric.c
@@ -144,8 +144,8 @@ rb_num_coerce_cmp(x, y)
return Qnil;
}
-static VALUE
-num_coerce_relop(x, y)
+VALUE
+rb_num_coerce_relop(x, y)
VALUE x, y;
{
VALUE c, x0 = x, y0 = y;
@@ -620,7 +620,7 @@ flo_gt(x, y)
break;
default:
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
if (isnan(a) || isnan(b)) return Qfalse;
return (a > b)?Qtrue:Qfalse;
@@ -647,7 +647,7 @@ flo_ge(x, y)
break;
default:
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
if (isnan(a) || isnan(b)) return Qfalse;
return (a >= b)?Qtrue:Qfalse;
@@ -674,7 +674,7 @@ flo_lt(x, y)
break;
default:
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
if (isnan(a) || isnan(b)) return Qfalse;
return (a < b)?Qtrue:Qfalse;
@@ -701,7 +701,7 @@ flo_le(x, y)
break;
default:
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
if (isnan(a) || isnan(b)) return Qfalse;
return (a <= b)?Qtrue:Qfalse;
@@ -1501,7 +1501,7 @@ fix_gt(x, y)
return Qfalse;
}
else {
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
}
@@ -1516,7 +1516,7 @@ fix_ge(x, y)
return Qfalse;
}
else {
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
}
@@ -1531,7 +1531,7 @@ fix_lt(x, y)
return Qfalse;
}
else {
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
}
@@ -1546,7 +1546,7 @@ fix_le(x, y)
return Qfalse;
}
else {
- return num_coerce_relop(x, y);
+ return rb_num_coerce_relop(x, y);
}
}