Skip to content

Commit

Permalink
* numeric.c (rb_num_coerce_relop): export function.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matz committed Jul 31, 2003
1 parent 7126624 commit 5b9afca
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 83 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Thu Jul 31 12:36:11 2003 Masatoshi SEKI <[email protected]>

* bin/erb, lib/erb.rb: add explicit trim mode.

Thu Jul 31 04:59:10 2003 Yukihiro Matsumoto <[email protected]>

* numeric.c (rb_num_coerce_relop): export function.

Thu Jul 31 00:17:19 2003 Shugo Maeda <[email protected]>

* lib/net/ftp.rb (return_code): obsolete.
Expand All @@ -22,6 +26,11 @@ Thu Jul 31 00:17:19 2003 Shugo Maeda <[email protected]>

* lib/net/ftp.rb (last_response): new method.

Wed Jul 30 23:55:44 2003 Yukihiro Matsumoto <[email protected]>

* marshal.c (w_object): check has been dropped. "_dump must return
string." [ruby-dev:21024]

Wed Jul 30 22:35:19 2003 Nobuyoshi Nakada <[email protected]>

* lib/mkmf.rb (dir_config): allow multiple directories separated
Expand Down
2 changes: 1 addition & 1 deletion doc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,16 @@ 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));
/* numeric.c */
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));
Expand Down
3 changes: 2 additions & 1 deletion io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
132 changes: 63 additions & 69 deletions lib/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -361,61 +410,6 @@ def inspect
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
Expand Down Expand Up @@ -538,15 +532,15 @@ def log10(z)
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) )
end
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) )
Expand All @@ -570,7 +564,7 @@ def atan2(y,x)
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) )
Expand All @@ -586,7 +580,7 @@ def asinh(z)
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
Expand Down
3 changes: 3 additions & 0 deletions marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1501,7 +1501,7 @@ fix_gt(x, y)
return Qfalse;
}
else {
return num_coerce_relop(x, y);
return rb_num_coerce_relop(x, y);
}
}

Expand All @@ -1516,7 +1516,7 @@ fix_ge(x, y)
return Qfalse;
}
else {
return num_coerce_relop(x, y);
return rb_num_coerce_relop(x, y);
}
}

Expand All @@ -1531,7 +1531,7 @@ fix_lt(x, y)
return Qfalse;
}
else {
return num_coerce_relop(x, y);
return rb_num_coerce_relop(x, y);
}
}

Expand All @@ -1546,7 +1546,7 @@ fix_le(x, y)
return Qfalse;
}
else {
return num_coerce_relop(x, y);
return rb_num_coerce_relop(x, y);
}
}

Expand Down

0 comments on commit 5b9afca

Please sign in to comment.