mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7126624b4e
commit
5b9afca5e4
7 changed files with 91 additions and 83 deletions
|
@ -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
|
||||
|
|
2
doc/NEWS
2
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
|
||||
|
||||
|
|
5
intern.h
5
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));
|
||||
|
|
3
io.c
3
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);
|
||||
|
|
132
lib/complex.rb
132
lib/complex.rb
|
@ -26,23 +26,72 @@
|
|||
#
|
||||
|
||||
|
||||
#
|
||||
# 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
|
||||
|
|
|
@ -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);
|
||||
|
|
20
numeric.c
20
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue