2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
numeric.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri Aug 13 18:33:09 JST 1993
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#include "ruby.h"
|
2004-06-16 10:21:34 -04:00
|
|
|
#include <ctype.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <math.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <stdio.h>
|
2002-12-19 04:20:20 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD__ < 4
|
1999-08-13 01:45:20 -04:00
|
|
|
#include <floatingpoint.h>
|
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
#include <float.h>
|
|
|
|
#endif
|
|
|
|
|
2003-12-10 21:39:59 -05:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
|
|
|
|
2002-12-24 03:53:56 -05:00
|
|
|
/* use IEEE 64bit values if not defined */
|
|
|
|
#ifndef FLT_RADIX
|
|
|
|
#define FLT_RADIX 2
|
|
|
|
#endif
|
|
|
|
#ifndef FLT_ROUNDS
|
|
|
|
#define FLT_ROUNDS 1
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MIN
|
|
|
|
#define DBL_MIN 2.2250738585072014e-308
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MAX
|
|
|
|
#define DBL_MAX 1.7976931348623157e+308
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MIN_EXP
|
|
|
|
#define DBL_MIN_EXP (-1021)
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MAX_EXP
|
|
|
|
#define DBL_MAX_EXP 1024
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MIN_10_EXP
|
|
|
|
#define DBL_MIN_10_EXP (-307)
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MAX_10_EXP
|
2002-12-24 05:20:29 -05:00
|
|
|
#define DBL_MAX_10_EXP 308
|
2002-12-24 03:53:56 -05:00
|
|
|
#endif
|
|
|
|
#ifndef DBL_DIG
|
|
|
|
#define DBL_DIG 15
|
|
|
|
#endif
|
|
|
|
#ifndef DBL_MANT_DIG
|
|
|
|
#define DBL_MANT_DIG 53
|
|
|
|
#endif
|
2002-12-19 04:20:20 -05:00
|
|
|
#ifndef DBL_EPSILON
|
2002-12-24 03:53:56 -05:00
|
|
|
#define DBL_EPSILON 2.2204460492503131e-16
|
2002-12-19 04:20:20 -05:00
|
|
|
#endif
|
|
|
|
|
2003-07-21 14:48:58 -04:00
|
|
|
static ID id_coerce, id_to_i, id_eq;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cNumeric;
|
|
|
|
VALUE rb_cFloat;
|
|
|
|
VALUE rb_cInteger;
|
|
|
|
VALUE rb_cFixnum;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE rb_eZeroDivError;
|
|
|
|
VALUE rb_eFloatDomainError;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num_zerodiv(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_raise(rb_eZeroDivError, "divided by 0");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.coerce(numeric) => array
|
|
|
|
*
|
|
|
|
* If <i>aNumeric</i> is the same type as <i>num</i>, returns an array
|
|
|
|
* containing <i>aNumeric</i> and <i>num</i>. Otherwise, returns an
|
|
|
|
* array with both <i>aNumeric</i> and <i>num</i> represented as
|
|
|
|
* <code>Float</code> objects. This coercion mechanism is used by
|
|
|
|
* Ruby to handle mixed-type numeric operations: it is intended to
|
|
|
|
* find a compatible common type between the two operands of the operator.
|
|
|
|
*
|
|
|
|
* 1.coerce(2.5) #=> [2.5, 1.0]
|
|
|
|
* 1.2.coerce(3) #=> [3.0, 1.2]
|
|
|
|
* 1.coerce(2) #=> [2, 1]
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_coerce(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (CLASS_OF(x) == CLASS_OF(y))
|
2000-02-17 02:11:22 -05:00
|
|
|
return rb_assoc_new(y, x);
|
|
|
|
return rb_assoc_new(rb_Float(y), rb_Float(x));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
coerce_body(VALUE *x)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2001-08-05 23:05:23 -04:00
|
|
|
return rb_funcall(x[1], id_coerce, 1, x[0]);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
coerce_rescue(VALUE *x)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2003-04-14 05:04:43 -04:00
|
|
|
volatile VALUE v = rb_inspect(x[1]);
|
2003-04-11 02:37:48 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
|
|
|
|
rb_special_const_p(x[1])?
|
2006-08-31 06:47:44 -04:00
|
|
|
RSTRING_PTR(v):
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(x[1]),
|
|
|
|
rb_obj_classname(x[0]));
|
1999-12-06 04:04:03 -05:00
|
|
|
return Qnil; /* dummy */
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
do_coerce(VALUE *x, VALUE *y, int err)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE ary;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE a[2];
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
a[0] = *x; a[1] = *y;
|
2001-07-24 05:07:33 -04:00
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
ary = rb_rescue(coerce_body, (VALUE)a, err?coerce_rescue:0, (VALUE)a);
|
2006-09-02 10:42:08 -04:00
|
|
|
if (TYPE(ary) != T_ARRAY || RARRAY_LEN(ary) != 2) {
|
2002-12-19 04:20:20 -05:00
|
|
|
if (err) {
|
|
|
|
rb_raise(rb_eTypeError, "coerce must return [x, y]");
|
|
|
|
}
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2006-09-02 10:42:08 -04:00
|
|
|
*x = RARRAY_PTR(ary)[0];
|
|
|
|
*y = RARRAY_PTR(ary)[1];
|
2002-12-19 04:20:20 -05:00
|
|
|
return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num_coerce_bin(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2002-12-19 04:20:20 -05:00
|
|
|
do_coerce(&x, &y, Qtrue);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
return rb_funcall(x, rb_frame_this_func(), 1, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num_coerce_cmp(VALUE x, VALUE y)
|
2002-12-19 04:20:20 -05:00
|
|
|
{
|
|
|
|
if (do_coerce(&x, &y, Qfalse))
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
return rb_funcall(x, rb_frame_this_func(), 1, y);
|
2002-12-19 04:20:20 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-07-31 04:42:44 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num_coerce_relop(VALUE x, VALUE y)
|
2003-05-07 23:56:12 -04:00
|
|
|
{
|
|
|
|
VALUE c, x0 = x, y0 = y;
|
|
|
|
|
|
|
|
if (!do_coerce(&x, &y, Qfalse) ||
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
NIL_P(c = rb_funcall(x, rb_frame_this_func(), 1, y))) {
|
2003-05-07 23:56:12 -04:00
|
|
|
rb_cmperr(x0, y0);
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* Trap attempts to add methods to <code>Numeric</code> objects. Always
|
|
|
|
* raises a <code>TypeError</code>
|
|
|
|
*/
|
|
|
|
|
2003-12-01 08:16:09 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_sadded(VALUE x, VALUE name)
|
2003-12-01 08:16:09 -05:00
|
|
|
{
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
/* ruby_frame = ruby_frame->prev; */ /* pop frame for "singleton_method_added" */
|
2003-12-01 08:16:09 -05:00
|
|
|
/* Numerics should be values; singleton_methods should not be added to them */
|
|
|
|
rb_raise(rb_eTypeError,
|
|
|
|
"can't define singleton method \"%s\" for %s",
|
|
|
|
rb_id2name(rb_to_id(name)),
|
|
|
|
rb_obj_classname(x));
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
}
|
|
|
|
|
2004-01-18 09:16:47 -05:00
|
|
|
/* :nodoc: */
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_init_copy(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2001-10-10 04:21:13 -04:00
|
|
|
/* Numerics are immutable values, which should not be copied */
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_raise(rb_eTypeError, "can't copy %s", rb_obj_classname(x));
|
2001-10-10 04:21:13 -04:00
|
|
|
return Qnil; /* not reached */
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* +num => num
|
|
|
|
*
|
|
|
|
* Unary Plus---Returns the receiver's value.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_uplus(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-09 09:38:34 -04:00
|
|
|
* -num => numeric
|
2003-12-27 00:46:46 -05:00
|
|
|
*
|
|
|
|
* Unary Minus---Returns the receiver's value, negated.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_uminus(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE zero;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
zero = INT2FIX(0);
|
2002-12-19 04:20:20 -05:00
|
|
|
do_coerce(&zero, &num, Qtrue);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_funcall(zero, '-', 1, num);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.quo(numeric) => result
|
|
|
|
*
|
|
|
|
* Equivalent to <code>Numeric#/</code>, but overridden in subclasses.
|
|
|
|
*/
|
|
|
|
|
2003-01-23 01:22:50 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_quo(VALUE x, VALUE y)
|
2003-01-23 01:22:50 -05:00
|
|
|
{
|
|
|
|
return rb_funcall(x, '/', 1, y);
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
2005-11-23 09:54:43 -05:00
|
|
|
static VALUE num_floor(VALUE num);
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.div(numeric) => integer
|
|
|
|
*
|
|
|
|
* Uses <code>/</code> to perform division, then converts the result to
|
|
|
|
* an integer. <code>Numeric</code> does not define the <code>/</code>
|
|
|
|
* operator; this is left to subclasses.
|
|
|
|
*/
|
|
|
|
|
2001-07-31 02:24:45 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_div(VALUE x, VALUE y)
|
2001-07-31 02:24:45 -04:00
|
|
|
{
|
2005-11-23 09:54:43 -05:00
|
|
|
return num_floor(rb_funcall(x, '/', 1, y));
|
2001-07-31 02:24:45 -04:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.divmod( aNumeric ) -> anArray
|
|
|
|
*
|
|
|
|
* Returns an array containing the quotient and modulus obtained by
|
|
|
|
* dividing <i>num</i> by <i>aNumeric</i>. If <code>q, r =
|
|
|
|
* x.divmod(y)</code>, then
|
|
|
|
*
|
|
|
|
* q = floor(float(x)/float(y))
|
|
|
|
* x = q*y + r
|
|
|
|
*
|
|
|
|
* The quotient is rounded toward -infinity, as shown in the following table:
|
|
|
|
*
|
|
|
|
* a | b | a.divmod(b) | a/b | a.modulo(b) | a.remainder(b)
|
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
|
|
|
* 13 | 4 | 3, 1 | 3 | 1 | 1
|
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
|
|
|
* 13 | -4 | -4, -3 | -3 | -3 | 1
|
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
|
|
|
* -13 | 4 | -4, 3 | -4 | 3 | -1
|
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
|
|
|
* -13 | -4 | 3, -1 | 3 | -1 | -1
|
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
* 11.5 | 4 | 2, 3.5 | 2.875 | 3.5 | 3.5
|
2003-12-27 00:46:46 -05:00
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
* 11.5 | -4 | -3, -0.5 | -2.875 | -0.5 | 3.5
|
2003-12-27 00:46:46 -05:00
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
* -11.5 | 4 | -3, 0.5 | -2.875 | 0.5 | -3.5
|
2003-12-27 00:46:46 -05:00
|
|
|
* ------+-----+---------------+---------+-------------+---------------
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
* -11.5 | -4 | 2, -3.5 | 2.875 | -3.5 | -3.5
|
2003-12-27 00:46:46 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Examples
|
|
|
|
* 11.divmod(3) #=> [3, 2]
|
|
|
|
* 11.divmod(-3) #=> [-4, -1]
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
* 11.divmod(3.5) #=> [3, 0.5]
|
|
|
|
* (-11).divmod(3.5) #=> [-4, 3.0]
|
|
|
|
* (11.5).divmod(3.5) #=> [3, 1.0]
|
2003-12-27 00:46:46 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_divmod(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-01-23 01:22:50 -05:00
|
|
|
return rb_assoc_new(num_div(x, y), rb_funcall(x, '%', 1, y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.modulo(numeric) => result
|
|
|
|
*
|
|
|
|
* Equivalent to
|
|
|
|
* <i>num</i>.<code>divmod(</code><i>aNumeric</i><code>)[1]</code>.
|
|
|
|
*/
|
|
|
|
|
2000-07-03 01:46:36 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_modulo(VALUE x, VALUE y)
|
2000-07-03 01:46:36 -04:00
|
|
|
{
|
|
|
|
return rb_funcall(x, '%', 1, y);
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.remainder(numeric) => result
|
|
|
|
*
|
|
|
|
* If <i>num</i> and <i>numeric</i> have different signs, returns
|
|
|
|
* <em>mod</em>-<i>numeric</i>; otherwise, returns <em>mod</em>. In
|
|
|
|
* both cases <em>mod</em> is the value
|
|
|
|
* <i>num</i>.<code>modulo(</code><i>numeric</i><code>)</code>. The
|
|
|
|
* differences between <code>remainder</code> and modulo
|
|
|
|
* (<code>%</code>) are shown in the table under <code>Numeric#divmod</code>.
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_remainder(VALUE x, VALUE y)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
VALUE z = rb_funcall(x, '%', 1, y);
|
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
if ((!rb_equal(z, INT2FIX(0))) &&
|
2001-10-29 00:07:26 -05:00
|
|
|
((RTEST(rb_funcall(x, '<', 1, INT2FIX(0))) &&
|
|
|
|
RTEST(rb_funcall(y, '>', 1, INT2FIX(0)))) ||
|
|
|
|
(RTEST(rb_funcall(x, '>', 1, INT2FIX(0))) &&
|
|
|
|
RTEST(rb_funcall(y, '<', 1, INT2FIX(0)))))) {
|
2000-07-06 03:21:26 -04:00
|
|
|
return rb_funcall(z, '-', 1, y);
|
|
|
|
}
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2005-12-07 03:41:59 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.scalar? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>num</i> is an <code>Scalar</code>
|
|
|
|
* (i.e. non <code>Complex</code>).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
num_scalar_p(VALUE num)
|
|
|
|
{
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.integer? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>num</i> is an <code>Integer</code>
|
|
|
|
* (including <code>Fixnum</code> and <code>Bignum</code>).
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_int_p(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.abs => num or numeric
|
|
|
|
*
|
|
|
|
* Returns the absolute value of <i>num</i>.
|
|
|
|
*
|
|
|
|
* 12.abs #=> 12
|
|
|
|
* (-34.56).abs #=> 34.56
|
|
|
|
* -34.56.abs #=> 34.56
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_abs(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) {
|
|
|
|
return rb_funcall(num, rb_intern("-@"), 0);
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.zero? => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>num</i> has a zero value.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_zero_p(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2002-04-24 00:54:16 -04:00
|
|
|
if (rb_equal(num, INT2FIX(0))) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.nonzero? => num or nil
|
|
|
|
*
|
|
|
|
* Returns <i>num</i> if <i>num</i> is not zero, <code>nil</code>
|
|
|
|
* otherwise. This behavior is useful when chaining comparisons:
|
|
|
|
*
|
|
|
|
* a = %w( z Bb bB bb BB a aA Aa AA A )
|
|
|
|
* b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
|
|
|
|
* b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_nonzero_p(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RTEST(rb_funcall(num, rb_intern("zero?"), 0, 0))) {
|
1999-08-13 01:45:20 -04:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.to_int => integer
|
|
|
|
*
|
|
|
|
* Invokes the child class's <code>to_i</code> method to convert
|
|
|
|
* <i>num</i> to an integer.
|
|
|
|
*/
|
|
|
|
|
2002-07-29 02:14:10 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_to_int(VALUE num)
|
2002-07-29 02:14:10 -04:00
|
|
|
{
|
|
|
|
return rb_funcall(num, id_to_i, 0, 0);
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Document-class: Float
|
|
|
|
*
|
|
|
|
* <code>Float</code> objects represent real numbers using the native
|
|
|
|
* architecture's double-precision floating point representation.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_float_new(double d)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
NEWOBJ(flt, struct RFloat);
|
1999-01-19 23:59:39 -05:00
|
|
|
OBJSETUP(flt, rb_cFloat, T_FLOAT);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
flt->value = d;
|
|
|
|
return (VALUE)flt;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.to_s => string
|
|
|
|
*
|
|
|
|
* Returns a string containing a representation of self. As well as a
|
|
|
|
* fixed or exponential form of the number, the call may return
|
|
|
|
* ``<code>NaN</code>'', ``<code>Infinity</code>'', and
|
|
|
|
* ``<code>-Infinity</code>''.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_to_s(VALUE flt)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-08-04 01:28:50 -04:00
|
|
|
char buf[32];
|
1999-08-13 01:45:20 -04:00
|
|
|
double value = RFLOAT(flt)->value;
|
2004-05-07 04:44:24 -04:00
|
|
|
char *p, *e;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
if (isinf(value))
|
|
|
|
return rb_str_new2(value < 0 ? "-Infinity" : "Infinity");
|
|
|
|
else if(isnan(value))
|
|
|
|
return rb_str_new2("NaN");
|
2004-05-07 04:44:24 -04:00
|
|
|
|
2004-05-17 03:14:45 -04:00
|
|
|
sprintf(buf, "%#.15g", value); /* ensure to print decimal point */
|
2004-05-07 04:44:24 -04:00
|
|
|
if (!(e = strchr(buf, 'e'))) {
|
|
|
|
e = buf + strlen(buf);
|
|
|
|
}
|
2004-05-17 03:14:45 -04:00
|
|
|
if (!ISDIGIT(e[-1])) { /* reformat if ended with decimal point (ex 111111111111111.) */
|
|
|
|
sprintf(buf, "%#.14e", value);
|
|
|
|
if (!(e = strchr(buf, 'e'))) {
|
|
|
|
e = buf + strlen(buf);
|
|
|
|
}
|
|
|
|
}
|
2004-05-07 04:44:24 -04:00
|
|
|
p = e;
|
2004-05-17 03:14:45 -04:00
|
|
|
while (p[-1]=='0' && ISDIGIT(p[-2]))
|
|
|
|
p--;
|
|
|
|
memmove(p, e, strlen(e)+1);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2(buf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* MISSING: documentation
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_coerce(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_assoc_new(rb_Float(y), x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* -float => float
|
|
|
|
*
|
|
|
|
* Returns float, negated.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_uminus(VALUE flt)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(-RFLOAT(flt)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* float + other => float
|
|
|
|
*
|
|
|
|
* Returns a new float which is the sum of <code>float</code>
|
|
|
|
* and <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_plus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value + (double)FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value + rb_big2dbl(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value + RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* float + other => float
|
|
|
|
*
|
|
|
|
* Returns a new float which is the difference of <code>float</code>
|
|
|
|
* and <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_minus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value - (double)FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value - rb_big2dbl(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value - RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* float * other => float
|
|
|
|
*
|
2005-04-18 02:38:30 -04:00
|
|
|
* Returns a new float which is the product of <code>float</code>
|
2003-12-23 11:21:17 -05:00
|
|
|
* and <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_mul(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value * (double)FIX2LONG(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value * rb_big2dbl(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value * RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* float / other => float
|
|
|
|
*
|
|
|
|
* Returns a new float which is the result of dividing
|
|
|
|
* <code>float</code> by <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_div(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
long f_y;
|
1998-01-16 07:13:05 -05:00
|
|
|
double d;
|
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
f_y = FIX2LONG(y);
|
|
|
|
return rb_float_new(RFLOAT(x)->value / (double)f_y);
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
d = rb_big2dbl(y);
|
|
|
|
return rb_float_new(RFLOAT(x)->value / d);
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(RFLOAT(x)->value / RFLOAT(y)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
|
2000-07-03 01:46:36 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flodivmod(double x, double y, double *divp, double *modp)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-06 03:21:26 -04:00
|
|
|
double div, mod;
|
1999-01-19 23:59:39 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#ifdef HAVE_FMOD
|
2000-07-03 01:46:36 -04:00
|
|
|
mod = fmod(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
#else
|
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
double z;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-11-27 04:23:38 -05:00
|
|
|
modf(x/y, &z);
|
2001-05-02 00:22:21 -04:00
|
|
|
mod = x - z * y;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
#endif
|
2000-07-06 03:21:26 -04:00
|
|
|
div = (x - mod) / y;
|
|
|
|
if (y*mod < 0) {
|
|
|
|
mod += y;
|
|
|
|
div -= 1.0;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2000-07-06 03:21:26 -04:00
|
|
|
if (modp) *modp = mod;
|
|
|
|
if (divp) *divp = div;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt % other => float
|
|
|
|
* flt.modulo(other) => float
|
|
|
|
*
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 00:06:52 -04:00
|
|
|
* Return the modulo after division of <code>flt</code> by <code>other</code>.
|
2003-12-23 11:21:17 -05:00
|
|
|
*
|
|
|
|
* 6543.21.modulo(137) #=> 104.21
|
|
|
|
* 6543.21.modulo(137.24) #=> 92.9299999999996
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_mod(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
double fy, mod;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-03 01:46:36 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
fy = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
case T_BIGNUM:
|
|
|
|
fy = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
case T_FLOAT:
|
|
|
|
fy = RFLOAT(y)->value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
|
|
|
flodivmod(RFLOAT(x)->value, fy, 0, &mod);
|
|
|
|
return rb_float_new(mod);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.divmod(numeric) => array
|
|
|
|
*
|
|
|
|
* See <code>Numeric#divmod</code>.
|
|
|
|
*/
|
|
|
|
|
2000-01-31 22:12:21 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_divmod(VALUE x, VALUE y)
|
2000-01-31 22:12:21 -05:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
double fy, div, mod, val;
|
2004-11-16 21:27:38 -05:00
|
|
|
volatile VALUE a, b;
|
2000-01-31 22:12:21 -05:00
|
|
|
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
2000-07-03 01:46:36 -04:00
|
|
|
fy = (double)FIX2LONG(y);
|
2000-01-31 22:12:21 -05:00
|
|
|
break;
|
|
|
|
case T_BIGNUM:
|
2000-07-03 01:46:36 -04:00
|
|
|
fy = rb_big2dbl(y);
|
2000-01-31 22:12:21 -05:00
|
|
|
break;
|
|
|
|
case T_FLOAT:
|
2000-07-03 01:46:36 -04:00
|
|
|
fy = RFLOAT(y)->value;
|
2000-01-31 22:12:21 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
2000-07-03 01:46:36 -04:00
|
|
|
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
if (FIXABLE(div)) {
|
|
|
|
val = div;
|
|
|
|
a = LONG2FIX(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a = rb_dbl2big(div);
|
|
|
|
}
|
2004-11-16 21:27:38 -05:00
|
|
|
b = rb_float_new(mod);
|
|
|
|
return rb_assoc_new(a, b);
|
2000-01-31 22:12:21 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
*
|
|
|
|
* flt ** other => float
|
|
|
|
*
|
|
|
|
* Raises <code>float</code> the <code>other</code> power.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_pow(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(pow(RFLOAT(x)->value, (double)FIX2LONG(y)));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(pow(RFLOAT(x)->value, rb_big2dbl(y)));
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(pow(RFLOAT(x)->value, RFLOAT(y)->value));
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.eql?(numeric) => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>num</i> and <i>numeric</i> are the
|
|
|
|
* same type and have equal values.
|
|
|
|
*
|
|
|
|
* 1 == 1.0 #=> true
|
|
|
|
* 1.eql?(1.0) #=> false
|
|
|
|
* (1.0).eql?(1.0) #=> true
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_eql(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (TYPE(x) != TYPE(y)) return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return rb_equal(x, y);
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num <=> other -> 0 or nil
|
|
|
|
*
|
|
|
|
* Returns zero if <i>num</i> equals <i>other</i>, <code>nil</code>
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
|
2002-11-22 04:14:24 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_cmp(VALUE x, VALUE y)
|
2002-11-22 04:14:24 -05:00
|
|
|
{
|
|
|
|
if (x == y) return INT2FIX(0);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_equal(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-07-21 14:48:58 -04:00
|
|
|
if (x == y) return Qtrue;
|
|
|
|
return rb_funcall(y, id_eq, 1, x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt == obj => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> only if <i>obj</i> has the same value
|
|
|
|
* as <i>flt</i>. Contrast this with <code>Float#eql?</code>, which
|
|
|
|
* requires <i>obj</i> to be a <code>Float</code>.
|
|
|
|
*
|
|
|
|
* 1.0 == 1 #=> true
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_eq(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2004-06-04 05:56:25 -04:00
|
|
|
volatile double a, b;
|
2003-04-11 02:37:48 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
2003-04-11 02:37:48 -04:00
|
|
|
b = FIX2LONG(y);
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_BIGNUM:
|
2003-04-11 02:37:48 -04:00
|
|
|
b = rb_big2dbl(y);
|
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
2003-04-11 02:37:48 -04:00
|
|
|
b = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(b)) return Qfalse;
|
2003-04-11 02:37:48 -04:00
|
|
|
break;
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
|
|
|
return num_equal(x, y);
|
|
|
|
}
|
2003-04-11 02:37:48 -04:00
|
|
|
a = RFLOAT(x)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
2003-04-11 02:37:48 -04:00
|
|
|
return (a == b)?Qtrue:Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.hash => integer
|
|
|
|
*
|
|
|
|
* Returns a hash code for this float.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_hash(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
double d;
|
2006-08-29 23:02:35 -04:00
|
|
|
int hash;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
d = RFLOAT(num)->value;
|
2006-09-21 18:52:38 -04:00
|
|
|
hash = rb_memhash(&d, sizeof(d));
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(hash);
|
|
|
|
}
|
|
|
|
|
2002-08-19 01:56:09 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_dbl_cmp(double a, double b)
|
2002-08-19 01:56:09 -04:00
|
|
|
{
|
2003-04-11 02:37:48 -04:00
|
|
|
if (isnan(a) || isnan(b)) return Qnil;
|
2002-08-19 01:56:09 -04:00
|
|
|
if (a == b) return INT2FIX(0);
|
|
|
|
if (a > b) return INT2FIX(1);
|
|
|
|
if (a < b) return INT2FIX(-1);
|
2002-12-19 04:20:20 -05:00
|
|
|
return Qnil;
|
2002-08-19 01:56:09 -04:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt <=> numeric => -1, 0, +1
|
|
|
|
*
|
|
|
|
* Returns -1, 0, or +1 depending on whether <i>flt</i> is less than,
|
|
|
|
* equal to, or greater than <i>numeric</i>. This is the basis for the
|
|
|
|
* tests in <code>Comparable</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_cmp(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
double a, b;
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
a = RFLOAT(x)->value;
|
1998-01-16 07:13:05 -05:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
b = (double)FIX2LONG(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
b = rb_big2dbl(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
1998-01-16 07:19:22 -05:00
|
|
|
b = RFLOAT(y)->value;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-12-19 04:20:20 -05:00
|
|
|
return rb_num_coerce_cmp(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-08-19 01:56:09 -04:00
|
|
|
return rb_dbl_cmp(a, b);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt > other => true or false
|
|
|
|
*
|
|
|
|
* <code>true</code> if <code>flt</code> is greater than <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_gt(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double a, b;
|
|
|
|
|
|
|
|
a = RFLOAT(x)->value;
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
b = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
b = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
b = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(b)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
return (a > b)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt >= other => true or false
|
|
|
|
*
|
|
|
|
* <code>true</code> if <code>flt</code> is greater than
|
|
|
|
* or equal to <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_ge(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double a, b;
|
|
|
|
|
|
|
|
a = RFLOAT(x)->value;
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
b = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
b = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
b = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(b)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
return (a >= b)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt < other => true or false
|
|
|
|
*
|
|
|
|
* <code>true</code> if <code>flt</code> is less than <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_lt(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double a, b;
|
|
|
|
|
|
|
|
a = RFLOAT(x)->value;
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
b = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
b = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
b = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(b)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
return (a < b)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt <= other => true or false
|
|
|
|
*
|
|
|
|
* <code>true</code> if <code>flt</code> is less than
|
|
|
|
* or equal to <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_le(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double a, b;
|
|
|
|
|
|
|
|
a = RFLOAT(x)->value;
|
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
b = (double)FIX2LONG(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
b = rb_big2dbl(y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
b = RFLOAT(y)->value;
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(b)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-07-25 03:08:14 -04:00
|
|
|
if (isnan(a)) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
return (a <= b)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.eql?(obj) => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> only if <i>obj</i> is a
|
|
|
|
* <code>Float</code> with the same value as <i>flt</i>. Contrast this
|
|
|
|
* with <code>Float#==</code>, which performs type conversions.
|
|
|
|
*
|
|
|
|
* 1.0.eql?(1) #=> false
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_eql(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-04-11 02:37:48 -04:00
|
|
|
if (TYPE(y) == T_FLOAT) {
|
|
|
|
double a = RFLOAT(x)->value;
|
|
|
|
double b = RFLOAT(y)->value;
|
|
|
|
|
|
|
|
if (isnan(a) || isnan(b)) return Qfalse;
|
|
|
|
if (a == b) return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.to_f => flt
|
|
|
|
*
|
|
|
|
* As <code>flt</code> is already a float, returns <i>self</i>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_to_f(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-06 03:21:26 -04:00
|
|
|
return num;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.abs => float
|
|
|
|
*
|
|
|
|
* Returns the absolute value of <i>flt</i>.
|
|
|
|
*
|
|
|
|
* (-34.56).abs #=> 34.56
|
|
|
|
* -34.56.abs #=> 34.56
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_abs(VALUE flt)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
double val = fabs(RFLOAT(flt)->value);
|
|
|
|
return rb_float_new(val);
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.zero? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>flt</i> is 0.0.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_zero_p(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
if (RFLOAT(num)->value == 0.0) {
|
|
|
|
return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2000-07-06 03:21:26 -04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.nan? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>flt</i> is an invalid IEEE floating
|
|
|
|
* point number.
|
|
|
|
*
|
|
|
|
* a = -1.0 #=> -1.0
|
|
|
|
* a.nan? #=> false
|
|
|
|
* a = 0.0/0.0 #=> NaN
|
|
|
|
* a.nan? #=> true
|
|
|
|
*/
|
|
|
|
|
2002-06-04 03:34:19 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_is_nan_p(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
2003-04-11 02:37:48 -04:00
|
|
|
double value = RFLOAT(num)->value;
|
2000-07-06 03:21:26 -04:00
|
|
|
|
2003-04-11 02:37:48 -04:00
|
|
|
return isnan(value) ? Qtrue : Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.infinite? -> nil, -1, +1
|
|
|
|
*
|
|
|
|
* Returns <code>nil</code>, -1, or +1 depending on whether <i>flt</i>
|
|
|
|
* is finite, -infinity, or +infinity.
|
|
|
|
*
|
|
|
|
* (0.0).infinite? #=> nil
|
|
|
|
* (-1.0/0.0).infinite? #=> -1
|
|
|
|
* (+1.0/0.0).infinite? #=> 1
|
|
|
|
*/
|
|
|
|
|
2002-06-04 03:34:19 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_is_infinite_p(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
2003-04-11 02:37:48 -04:00
|
|
|
double value = RFLOAT(num)->value;
|
2000-07-06 03:21:26 -04:00
|
|
|
|
2003-04-11 02:37:48 -04:00
|
|
|
if (isinf(value)) {
|
|
|
|
return INT2FIX( value < 0 ? -1 : 1 );
|
|
|
|
}
|
2000-07-06 03:21:26 -04:00
|
|
|
|
2003-04-11 02:37:48 -04:00
|
|
|
return Qnil;
|
2000-07-06 03:21:26 -04:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.finite? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>flt</i> is a valid IEEE floating
|
|
|
|
* point number (it is not infinite, and <code>nan?</code> is
|
|
|
|
* <code>false</code>).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-06-04 03:34:19 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_is_finite_p(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
2003-04-11 02:37:48 -04:00
|
|
|
double value = RFLOAT(num)->value;
|
2000-07-06 03:21:26 -04:00
|
|
|
|
2003-04-21 08:26:08 -04:00
|
|
|
#if HAVE_FINITE
|
|
|
|
if (!finite(value))
|
|
|
|
return Qfalse;
|
|
|
|
#else
|
2003-04-11 02:37:48 -04:00
|
|
|
if (isinf(value) || isnan(value))
|
|
|
|
return Qfalse;
|
2003-04-21 08:26:08 -04:00
|
|
|
#endif
|
|
|
|
|
2003-04-11 02:37:48 -04:00
|
|
|
return Qtrue;
|
2000-07-06 03:21:26 -04:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.floor => integer
|
|
|
|
*
|
|
|
|
* Returns the largest integer less than or equal to <i>flt</i>.
|
|
|
|
*
|
|
|
|
* 1.2.floor #=> 1
|
|
|
|
* 2.0.floor #=> 2
|
|
|
|
* (-1.2).floor #=> -2
|
|
|
|
* (-2.0).floor #=> -2
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_floor(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double f = floor(RFLOAT(num)->value);
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (!FIXABLE(f)) {
|
|
|
|
return rb_dbl2big(f);
|
|
|
|
}
|
|
|
|
val = f;
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(val);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.ceil => integer
|
|
|
|
*
|
|
|
|
* Returns the smallest <code>Integer</code> greater than or equal to
|
|
|
|
* <i>flt</i>.
|
|
|
|
*
|
|
|
|
* 1.2.ceil #=> 2
|
|
|
|
* 2.0.ceil #=> 2
|
|
|
|
* (-1.2).ceil #=> -1
|
|
|
|
* (-2.0).ceil #=> -2
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_ceil(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double f = ceil(RFLOAT(num)->value);
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (!FIXABLE(f)) {
|
|
|
|
return rb_dbl2big(f);
|
|
|
|
}
|
|
|
|
val = f;
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(val);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.round => integer
|
|
|
|
*
|
|
|
|
* Rounds <i>flt</i> to the nearest integer. Equivalent to:
|
|
|
|
*
|
|
|
|
* def round
|
|
|
|
* return floor(self+0.5) if self > 0.0
|
|
|
|
* return ceil(self-0.5) if self < 0.0
|
|
|
|
* return 0.0
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* 1.5.round #=> 2
|
|
|
|
* (-1.5).round #=> -2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_round(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
double f = RFLOAT(num)->value;
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (f > 0.0) f = floor(f+0.5);
|
|
|
|
if (f < 0.0) f = ceil(f-0.5);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (!FIXABLE(f)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_dbl2big(f);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
val = f;
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* flt.to_i => integer
|
|
|
|
* flt.to_int => integer
|
|
|
|
* flt.truncate => integer
|
|
|
|
*
|
|
|
|
* Returns <i>flt</i> truncated to an <code>Integer</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
flo_truncate(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-06 03:21:26 -04:00
|
|
|
double f = RFLOAT(num)->value;
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (f > 0.0) f = floor(f);
|
|
|
|
if (f < 0.0) f = ceil(f);
|
|
|
|
|
|
|
|
if (!FIXABLE(f)) {
|
|
|
|
return rb_dbl2big(f);
|
|
|
|
}
|
|
|
|
val = f;
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.floor => integer
|
|
|
|
*
|
|
|
|
* Returns the largest integer less than or equal to <i>num</i>.
|
|
|
|
* <code>Numeric</code> implements this by converting <i>anInteger</i>
|
|
|
|
* to a <code>Float</code> and invoking <code>Float#floor</code>.
|
|
|
|
*
|
|
|
|
* 1.floor #=> 1
|
|
|
|
* (-1).floor #=> -1
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_floor(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-06 03:21:26 -04:00
|
|
|
return flo_floor(rb_Float(num));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.ceil => integer
|
|
|
|
*
|
|
|
|
* Returns the smallest <code>Integer</code> greater than or equal to
|
|
|
|
* <i>num</i>. Class <code>Numeric</code> achieves this by converting
|
|
|
|
* itself to a <code>Float</code> then invoking
|
|
|
|
* <code>Float#ceil</code>.
|
|
|
|
*
|
|
|
|
* 1.ceil #=> 1
|
|
|
|
* 1.2.ceil #=> 2
|
|
|
|
* (-1.2).ceil #=> -1
|
|
|
|
* (-1.0).ceil #=> -1
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_ceil(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2000-07-06 03:21:26 -04:00
|
|
|
return flo_ceil(rb_Float(num));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.round => integer
|
|
|
|
*
|
|
|
|
* Rounds <i>num</i> to the nearest integer. <code>Numeric</code>
|
|
|
|
* implements this by converting itself to a
|
|
|
|
* <code>Float</code> and invoking <code>Float#round</code>.
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_round(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
return flo_round(rb_Float(num));
|
2000-06-12 03:48:31 -04:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.truncate => integer
|
|
|
|
*
|
|
|
|
* Returns <i>num</i> truncated to an integer. <code>Numeric</code>
|
|
|
|
* implements this by converting its value to a float and invoking
|
|
|
|
* <code>Float#truncate</code>.
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_truncate(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
return flo_truncate(rb_Float(num));
|
2000-06-12 03:48:31 -04:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* num.step(limit, step ) {|i| block } => num
|
|
|
|
*
|
|
|
|
* Invokes <em>block</em> with the sequence of numbers starting at
|
|
|
|
* <i>num</i>, incremented by <i>step</i> on each call. The loop
|
|
|
|
* finishes when the value to be passed to the block is greater than
|
|
|
|
* <i>limit</i> (if <i>step</i> is positive) or less than
|
|
|
|
* <i>limit</i> (if <i>step</i> is negative). If all the arguments are
|
|
|
|
* integers, the loop operates using an integer counter. If any of the
|
|
|
|
* arguments are floating point numbers, all are converted to floats,
|
|
|
|
* and the loop is executed <i>floor(n + n*epsilon)+ 1</i> times,
|
|
|
|
* where <i>n = (limit - num)/step</i>. Otherwise, the loop
|
|
|
|
* starts at <i>num</i>, uses either the <code><</code> or
|
|
|
|
* <code>></code> operator to compare the counter against
|
|
|
|
* <i>limit</i>, and increments itself using the <code>+</code>
|
|
|
|
* operator.
|
|
|
|
*
|
|
|
|
* 1.step(10, 2) { |i| print i, " " }
|
|
|
|
* Math::E.step(Math::PI, 0.2) { |f| print f, " " }
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 1 3 5 7 9
|
|
|
|
* 2.71828182845905 2.91828182845905 3.11828182845905
|
|
|
|
*/
|
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
num_step(int argc, VALUE *argv, VALUE from)
|
2002-04-24 00:54:16 -04:00
|
|
|
{
|
|
|
|
VALUE to, step;
|
|
|
|
|
2006-08-19 22:47:13 -04:00
|
|
|
RETURN_ENUMERATOR(from, argc, argv);
|
2003-01-08 01:05:08 -05:00
|
|
|
if (argc == 1) {
|
|
|
|
to = argv[0];
|
2002-04-24 00:54:16 -04:00
|
|
|
step = INT2FIX(1);
|
|
|
|
}
|
2003-01-08 01:05:08 -05:00
|
|
|
else {
|
|
|
|
if (argc == 2) {
|
|
|
|
to = argv[0];
|
|
|
|
step = argv[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
|
|
|
}
|
|
|
|
if (rb_equal(step, INT2FIX(0))) {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 01:47:45 -05:00
|
|
|
rb_raise(rb_eArgError, "step can't be 0");
|
2003-01-08 01:05:08 -05:00
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) {
|
|
|
|
long i, end, diff;
|
|
|
|
|
|
|
|
i = FIX2LONG(from);
|
|
|
|
end = FIX2LONG(to);
|
|
|
|
diff = FIX2LONG(step);
|
|
|
|
|
|
|
|
if (diff > 0) {
|
|
|
|
while (i <= end) {
|
2002-08-21 11:47:54 -04:00
|
|
|
rb_yield(LONG2FIX(i));
|
2002-04-24 00:54:16 -04:00
|
|
|
i += diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (i >= end) {
|
2002-08-21 11:47:54 -04:00
|
|
|
rb_yield(LONG2FIX(i));
|
2002-04-24 00:54:16 -04:00
|
|
|
i += diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-24 01:08:04 -04:00
|
|
|
else if (TYPE(from) == T_FLOAT || TYPE(to) == T_FLOAT || TYPE(step) == T_FLOAT) {
|
2003-05-08 05:45:52 -04:00
|
|
|
const double epsilon = DBL_EPSILON;
|
2002-04-24 01:08:04 -04:00
|
|
|
double beg = NUM2DBL(from);
|
|
|
|
double end = NUM2DBL(to);
|
|
|
|
double unit = NUM2DBL(step);
|
2002-05-01 05:41:50 -04:00
|
|
|
double n = (end - beg)/unit;
|
2003-05-08 05:45:52 -04:00
|
|
|
double err = (fabs(beg) + fabs(end) + fabs(end-beg)) / fabs(unit) * epsilon;
|
2002-05-01 05:41:50 -04:00
|
|
|
long i;
|
2002-04-24 00:54:16 -04:00
|
|
|
|
2003-05-08 05:45:52 -04:00
|
|
|
if (err>0.5) err=0.5;
|
|
|
|
n = floor(n + err) + 1;
|
2002-05-01 05:41:50 -04:00
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
rb_yield(rb_float_new(i*unit+beg));
|
2002-04-24 01:08:04 -04:00
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
}
|
|
|
|
else {
|
2002-04-24 01:08:04 -04:00
|
|
|
VALUE i = from;
|
|
|
|
ID cmp;
|
|
|
|
|
|
|
|
if (RTEST(rb_funcall(step, '>', 1, INT2FIX(0)))) {
|
|
|
|
cmp = '>';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmp = '<';
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
if (RTEST(rb_funcall(i, cmp, 1, to))) break;
|
|
|
|
rb_yield(i);
|
|
|
|
i = rb_funcall(i, '+', 1, step);
|
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
}
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
SIGNED_VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2long(VALUE val)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (NIL_P(val)) {
|
2002-07-29 02:14:10 -04:00
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIXNUM_P(val)) return FIX2LONG(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
switch (TYPE(val)) {
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RFLOAT(val)->value <= (double)LONG_MAX
|
|
|
|
&& RFLOAT(val)->value >= (double)LONG_MIN) {
|
2006-07-11 02:47:09 -04:00
|
|
|
return (SIGNED_VALUE)(RFLOAT(val)->value);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
1999-08-13 01:45:20 -04:00
|
|
|
char buf[24];
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sprintf(buf, "%-.10g", RFLOAT(val)->value);
|
2006-09-16 21:42:28 -04:00
|
|
|
if ((s = strchr(buf, ' ')) != 0) *s = '\0';
|
2001-10-02 00:31:23 -04:00
|
|
|
rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_big2long(val);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
2000-11-14 02:10:31 -05:00
|
|
|
val = rb_to_int(val);
|
1999-01-19 23:59:39 -05:00
|
|
|
return NUM2LONG(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2ulong(VALUE val)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (TYPE(val) == T_BIGNUM) {
|
|
|
|
return rb_big2ulong(val);
|
|
|
|
}
|
2006-07-11 02:47:09 -04:00
|
|
|
return (VALUE)rb_num2long(val);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-07-11 02:47:09 -04:00
|
|
|
#if SIZEOF_INT < SIZEOF_VALUE
|
2003-05-30 09:28:10 -04:00
|
|
|
static void
|
2006-07-11 02:47:09 -04:00
|
|
|
check_int(SIGNED_VALUE num)
|
2003-05-30 09:28:10 -04:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
if (num < INT_MIN) {
|
|
|
|
s = "small";
|
|
|
|
}
|
|
|
|
else if (num > INT_MAX) {
|
|
|
|
s = "big";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-11 02:47:09 -04:00
|
|
|
#if LONG_LONG_VALUE
|
|
|
|
rb_raise(rb_eRangeError, "integer %lld too %s to convert to `int'", num, s);
|
|
|
|
#else
|
2003-05-30 09:28:10 -04:00
|
|
|
rb_raise(rb_eRangeError, "integer %ld too %s to convert to `int'", num, s);
|
2006-07-11 02:47:09 -04:00
|
|
|
#endif
|
2003-05-30 09:28:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-07-11 02:47:09 -04:00
|
|
|
check_uint(VALUE num)
|
2003-05-30 09:28:10 -04:00
|
|
|
{
|
2003-08-28 04:35:43 -04:00
|
|
|
if (num > UINT_MAX) {
|
2006-07-11 02:47:09 -04:00
|
|
|
#if LONG_LONG_VALUE
|
|
|
|
rb_raise(rb_eRangeError, "integer %llu too big to convert to `unsigned int'", num);
|
|
|
|
#else
|
2003-08-28 04:35:43 -04:00
|
|
|
rb_raise(rb_eRangeError, "integer %lu too big to convert to `unsigned int'", num);
|
2006-07-11 02:47:09 -04:00
|
|
|
#endif
|
2003-05-30 09:28:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
long
|
2006-07-11 02:47:09 -04:00
|
|
|
rb_num2int(VALUE val)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
long num = rb_num2long(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-05-30 09:28:10 -04:00
|
|
|
check_int(num);
|
2003-12-01 03:42:53 -05:00
|
|
|
return num;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
long
|
2006-07-11 02:47:09 -04:00
|
|
|
rb_fix2int(VALUE val)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
|
|
|
|
|
2003-05-30 09:28:10 -04:00
|
|
|
check_int(num);
|
2003-12-01 03:42:53 -05:00
|
|
|
return num;
|
2003-05-30 09:28:10 -04:00
|
|
|
}
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
unsigned long
|
2006-07-11 02:47:09 -04:00
|
|
|
rb_num2uint(VALUE val)
|
2003-05-30 09:28:10 -04:00
|
|
|
{
|
|
|
|
unsigned long num = rb_num2ulong(val);
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) {
|
|
|
|
check_uint(num);
|
|
|
|
}
|
|
|
|
return num;
|
2003-05-30 09:28:10 -04:00
|
|
|
}
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
unsigned long
|
2006-07-11 02:47:09 -04:00
|
|
|
rb_fix2uint(VALUE val)
|
2003-05-30 09:28:10 -04:00
|
|
|
{
|
2003-12-01 03:42:53 -05:00
|
|
|
unsigned long num;
|
2003-05-30 09:28:10 -04:00
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
if (!FIXNUM_P(val)) {
|
|
|
|
return rb_num2uint(val);
|
|
|
|
}
|
|
|
|
num = FIX2ULONG(val);
|
|
|
|
if (FIX2LONG(val) > 0) {
|
|
|
|
check_uint(num);
|
|
|
|
}
|
|
|
|
return num;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
#else
|
2003-12-01 03:42:53 -05:00
|
|
|
long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2int(VALUE val)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
return rb_num2long(val);
|
|
|
|
}
|
|
|
|
|
2003-12-01 03:42:53 -05:00
|
|
|
long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_fix2int(VALUE val)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
return FIX2INT(val);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2fix(VALUE val)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
long v;
|
|
|
|
|
|
|
|
if (FIXNUM_P(val)) return val;
|
|
|
|
|
|
|
|
v = rb_num2long(val);
|
|
|
|
if (!FIXABLE(v))
|
2002-05-28 14:11:07 -04:00
|
|
|
rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v);
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(v);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-03-14 01:23:46 -05:00
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
long long.
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-03-15 03:51:31 -05:00
|
|
|
LONG_LONG
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2ll(VALUE val)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
|
|
|
if (NIL_P(val)) {
|
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion from nil");
|
|
|
|
}
|
|
|
|
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
long long.
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-03-15 03:51:31 -05:00
|
|
|
if (FIXNUM_P(val)) return (LONG_LONG)FIX2LONG(val);
|
2002-03-14 01:23:46 -05:00
|
|
|
|
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
|
|
|
if (RFLOAT(val)->value <= (double)LLONG_MAX
|
|
|
|
&& RFLOAT(val)->value >= (double)LLONG_MIN) {
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
long long.
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-03-15 03:51:31 -05:00
|
|
|
return (LONG_LONG)(RFLOAT(val)->value);
|
2002-03-14 01:23:46 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
char buf[24];
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
sprintf(buf, "%-.10g", RFLOAT(val)->value);
|
2006-09-16 21:42:28 -04:00
|
|
|
if ((s = strchr(buf, ' ')) != 0) *s = '\0';
|
2002-03-14 01:23:46 -05:00
|
|
|
rb_raise(rb_eRangeError, "float %s out of range of long long", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_big2ll(val);
|
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion from string");
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
|
|
|
|
case T_TRUE:
|
|
|
|
case T_FALSE:
|
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion from boolean");
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
|
|
|
|
default:
|
|
|
|
val = rb_to_int(val);
|
|
|
|
return NUM2LL(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
long long.
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-03-15 03:51:31 -05:00
|
|
|
unsigned LONG_LONG
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_num2ull(VALUE val)
|
2002-03-14 01:23:46 -05:00
|
|
|
{
|
|
|
|
if (TYPE(val) == T_BIGNUM) {
|
|
|
|
return rb_big2ull(val);
|
|
|
|
}
|
* bignum.c, intern.h (rb_ull2big, rb_ll2big, rb_ull2inum, rb_ll2inum,
big2ull, rb_big2ull, rb_big2ll): use LONG_LONG macro instead of
long long.
* numeric.c, intern.h, ruby.h (rb_num2ll, rb_num2ull): ditto.
* ruby.h: use _I64_MAX and _I64_MIN if they are defined (for VC++).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-03-15 03:51:31 -05:00
|
|
|
return (unsigned LONG_LONG)rb_num2ll(val);
|
2002-03-14 01:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LONG_LONG */
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Integer
|
|
|
|
*
|
|
|
|
* <code>Integer</code> is the basis for the two concrete classes that
|
|
|
|
* hold whole numbers, <code>Bignum</code> and <code>Fixnum</code>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.to_i => int
|
|
|
|
* int.to_int => int
|
|
|
|
* int.floor => int
|
|
|
|
* int.ceil => int
|
|
|
|
* int.round => int
|
|
|
|
* int.truncate => int
|
|
|
|
*
|
|
|
|
* As <i>int</i> is already an <code>Integer</code>, all these
|
|
|
|
* methods simply return the receiver.
|
|
|
|
*/
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_to_i(VALUE num)
|
2000-07-06 03:21:26 -04:00
|
|
|
{
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.integer? -> true
|
|
|
|
*
|
|
|
|
* Always returns <code>true</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_int_p(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2006-09-21 02:09:26 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.odd? -> true or false
|
2006-12-31 10:02:22 -05:00
|
|
|
*
|
2006-09-21 02:09:26 -04:00
|
|
|
* Returns <code>true</code> if <i>int</i> is an odd number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
int_odd_p(VALUE num)
|
|
|
|
{
|
|
|
|
if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) {
|
2006-12-31 10:02:22 -05:00
|
|
|
return Qtrue;
|
2006-09-21 02:09:26 -04:00
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.even? -> true or false
|
2006-12-31 10:02:22 -05:00
|
|
|
*
|
2006-09-21 02:09:26 -04:00
|
|
|
* Returns <code>true</code> if <i>int</i> is an even number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
int_even_p(VALUE num)
|
|
|
|
{
|
|
|
|
if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) {
|
2006-12-31 10:02:22 -05:00
|
|
|
return Qtrue;
|
2006-09-21 02:09:26 -04:00
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fixnum.next => integer
|
|
|
|
* fixnum.succ => integer
|
|
|
|
*
|
|
|
|
* Returns the <code>Integer</code> equal to <i>int</i> + 1.
|
|
|
|
*
|
|
|
|
* 1.next #=> 2
|
|
|
|
* (-1).next #=> 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fix_succ(VALUE num)
|
|
|
|
{
|
|
|
|
long i = FIX2LONG(num) + 1;
|
|
|
|
return LONG2NUM(i);
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.next => integer
|
|
|
|
* int.succ => integer
|
|
|
|
*
|
|
|
|
* Returns the <code>Integer</code> equal to <i>int</i> + 1.
|
|
|
|
*
|
|
|
|
* 1.next #=> 2
|
|
|
|
* (-1).next #=> 0
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_succ(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-03-22 02:26:42 -05:00
|
|
|
if (FIXNUM_P(num)) {
|
|
|
|
long i = FIX2LONG(num) + 1;
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(i);
|
2002-03-22 02:26:42 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
return rb_funcall(num, '+', 1, INT2FIX(1));
|
|
|
|
}
|
|
|
|
|
2007-01-29 23:27:04 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.pred => integer
|
|
|
|
*
|
|
|
|
* Returns the <code>Integer</code> equal to <i>int</i> - 1.
|
|
|
|
*
|
|
|
|
* 1.pred #=> 0
|
|
|
|
* (-1).pred #=> -2
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
int_pred(VALUE num)
|
|
|
|
{
|
|
|
|
if (FIXNUM_P(num)) {
|
|
|
|
long i = FIX2LONG(num) - 1;
|
|
|
|
return LONG2NUM(i);
|
|
|
|
}
|
|
|
|
return rb_funcall(num, '-', 1, INT2FIX(1));
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.chr => string
|
|
|
|
*
|
|
|
|
* Returns a string containing the ASCII character represented by the
|
|
|
|
* receiver's value.
|
|
|
|
*
|
|
|
|
* 65.chr #=> "A"
|
|
|
|
* 230.chr #=> "\346"
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_chr(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
long i = NUM2LONG(num);
|
|
|
|
|
|
|
|
if (i < 0 || 0xff < i)
|
2002-05-28 14:11:07 -04:00
|
|
|
rb_raise(rb_eRangeError, "%ld out of char range", i);
|
1999-01-19 23:59:39 -05:00
|
|
|
c = i;
|
|
|
|
return rb_str_new(&c, 1);
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Document-class: Fixnum
|
|
|
|
*
|
|
|
|
* A <code>Fixnum</code> holds <code>Integer</code> values that can be
|
|
|
|
* represented in a native machine word (minus 1 bit). If any operation
|
|
|
|
* on a <code>Fixnum</code> exceeds this range, the value is
|
|
|
|
* automatically converted to a <code>Bignum</code>.
|
|
|
|
*
|
|
|
|
* <code>Fixnum</code> objects have immediate value. This means that
|
|
|
|
* when they are assigned or passed as parameters, the actual object is
|
|
|
|
* passed, rather than a reference to that object. Assignment does not
|
|
|
|
* alias <code>Fixnum</code> objects. There is effectively only one
|
|
|
|
* <code>Fixnum</code> object instance for any given integer value, so,
|
|
|
|
* for example, you cannot add a singleton method to a
|
|
|
|
* <code>Fixnum</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Fixnum.induced_from(obj) => fixnum
|
|
|
|
*
|
|
|
|
* Convert <code>obj</code> to a Fixnum. Works with numeric parameters.
|
|
|
|
* Also works with Symbols, but this is deprecated.
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_fix_induced_from(VALUE klass, VALUE x)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
return rb_num2fix(x);
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Integer.induced_from(obj) => fixnum, bignum
|
|
|
|
*
|
|
|
|
* Convert <code>obj</code> to an Integer.
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_int_induced_from(VALUE klass, VALUE x)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
switch (TYPE(x)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_BIGNUM:
|
|
|
|
return x;
|
|
|
|
case T_FLOAT:
|
2002-07-29 02:14:10 -04:00
|
|
|
return rb_funcall(x, id_to_i, 0);
|
1999-08-13 01:45:20 -04:00
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, "failed to convert %s into Integer",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(x));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Float.induced_from(obj) => float
|
|
|
|
*
|
|
|
|
* Convert <code>obj</code> to a float.
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_flo_induced_from(VALUE klass, VALUE x)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
switch (TYPE(x)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_funcall(x, rb_intern("to_f"), 0);
|
|
|
|
case T_FLOAT:
|
|
|
|
return x;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eTypeError, "failed to convert %s into Float",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(x));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* -fix => integer
|
|
|
|
*
|
|
|
|
* Negates <code>fix</code> (which might return a Bignum).
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_uminus(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(-FIX2LONG(num));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_fix2str(VALUE x, int base)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-04-14 02:54:27 -04:00
|
|
|
extern const char ruby_digitmap[];
|
2006-07-11 02:47:09 -04:00
|
|
|
char buf[SIZEOF_VALUE*CHAR_BIT + 2], *b = buf + sizeof buf;
|
2002-01-11 04:18:54 -05:00
|
|
|
long val = FIX2LONG(x);
|
2003-04-14 02:54:27 -04:00
|
|
|
int neg = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-04-14 02:54:27 -04:00
|
|
|
if (base < 2 || 36 < base) {
|
|
|
|
rb_raise(rb_eArgError, "illegal radix %d", base);
|
|
|
|
}
|
|
|
|
if (val == 0) {
|
|
|
|
return rb_str_new2("0");
|
|
|
|
}
|
2002-01-11 04:18:54 -05:00
|
|
|
if (val < 0) {
|
|
|
|
val = -val;
|
2003-04-14 02:54:27 -04:00
|
|
|
neg = 1;
|
|
|
|
}
|
|
|
|
*--b = '\0';
|
|
|
|
do {
|
|
|
|
*--b = ruby_digitmap[(int)(val % base)];
|
|
|
|
} while (val /= base);
|
|
|
|
if (neg) {
|
|
|
|
*--b = '-';
|
2002-01-11 04:18:54 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-04-14 02:54:27 -04:00
|
|
|
return rb_str_new2(b);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.to_s( base=10 ) -> aString
|
|
|
|
*
|
|
|
|
* Returns a string containing the representation of <i>fix</i> radix
|
|
|
|
* <i>base</i> (between 2 and 36).
|
|
|
|
*
|
|
|
|
* 12345.to_s #=> "12345"
|
|
|
|
* 12345.to_s(2) #=> "11000000111001"
|
|
|
|
* 12345.to_s(8) #=> "30071"
|
|
|
|
* 12345.to_s(10) #=> "12345"
|
|
|
|
* 12345.to_s(16) #=> "3039"
|
|
|
|
* 12345.to_s(36) #=> "9ix"
|
|
|
|
*
|
|
|
|
*/
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_to_s(int argc, VALUE *argv, VALUE x)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-11-19 00:03:03 -05:00
|
|
|
VALUE b;
|
|
|
|
int base;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "01", &b);
|
|
|
|
if (argc == 0) base = 10;
|
|
|
|
else base = NUM2INT(b);
|
|
|
|
|
|
|
|
return rb_fix2str(x, base);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix + numeric => numeric_result
|
|
|
|
*
|
|
|
|
* Performs addition: the class of the resulting object depends on
|
|
|
|
* the class of <code>numeric</code> and on the magnitude of the
|
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_plus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
|
|
|
long a, b, c;
|
|
|
|
VALUE r;
|
|
|
|
|
|
|
|
a = FIX2LONG(x);
|
|
|
|
b = FIX2LONG(y);
|
|
|
|
c = a + b;
|
2006-09-04 16:10:45 -04:00
|
|
|
r = LONG2NUM(c);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_big_plus(y, x);
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new((double)FIX2LONG(x) + RFLOAT(y)->value);
|
2005-08-03 03:09:48 -04:00
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix - numeric => numeric_result
|
|
|
|
*
|
|
|
|
* Performs subtraction: the class of the resulting object depends on
|
|
|
|
* the class of <code>numeric</code> and on the magnitude of the
|
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_minus(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
|
|
|
long a, b, c;
|
|
|
|
VALUE r;
|
|
|
|
|
|
|
|
a = FIX2LONG(x);
|
|
|
|
b = FIX2LONG(y);
|
|
|
|
c = a - b;
|
2006-09-04 16:10:45 -04:00
|
|
|
r = LONG2NUM(c);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
x = rb_int2big(FIX2LONG(x));
|
|
|
|
return rb_big_minus(x, y);
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new((double)FIX2LONG(x) - RFLOAT(y)->value);
|
2005-08-03 03:09:48 -04:00
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix * numeric => numeric_result
|
|
|
|
*
|
|
|
|
* Performs multiplication: the class of the resulting object depends on
|
|
|
|
* the class of <code>numeric</code> and on the magnitude of the
|
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_mul(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
2005-12-27 00:40:04 -05:00
|
|
|
#ifdef __HP_cc
|
|
|
|
/* avoids an optimization bug of HP aC++/ANSI C B3910B A.06.05 [Jul 25 2005] */
|
|
|
|
volatile
|
|
|
|
#endif
|
2006-09-14 04:23:28 -04:00
|
|
|
SIGNED_VALUE a, b;
|
|
|
|
#if SIZEOF_VALUE * 2 <= SIZEOF_LONG_LONG
|
|
|
|
LONG_LONG d;
|
|
|
|
#else
|
|
|
|
SIGNED_VALUE c;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE r;
|
2006-09-14 04:23:28 -04:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
a = FIX2LONG(x);
|
|
|
|
b = FIX2LONG(y);
|
2006-09-14 04:23:28 -04:00
|
|
|
|
|
|
|
#if SIZEOF_VALUE * 2 <= SIZEOF_LONG_LONG
|
|
|
|
d = (LONG_LONG)a * b;
|
|
|
|
if (FIXABLE(d)) return LONG2FIX(d);
|
|
|
|
return rb_ll2inum(d);
|
|
|
|
#else
|
2006-09-20 09:41:55 -04:00
|
|
|
# define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_VALUE*CHAR_BIT-1)/2))
|
2006-09-14 04:23:28 -04:00
|
|
|
/*tests if N*N would overflow*/
|
2006-09-16 21:42:28 -04:00
|
|
|
# define FIT_SQRT_LONG(n) (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX))
|
2006-09-14 04:23:28 -04:00
|
|
|
if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b))
|
|
|
|
return LONG2FIX(a*b);
|
1999-01-19 23:59:39 -05:00
|
|
|
c = a * b;
|
2002-08-21 11:47:54 -04:00
|
|
|
r = LONG2FIX(c);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-09-14 04:23:28 -04:00
|
|
|
if (a == 0) return x;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIX2LONG(r) != c || c/a != b) {
|
|
|
|
r = rb_big_mul(rb_int2big(a), rb_int2big(b));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return r;
|
2006-09-14 04:23:28 -04:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_big_mul(y, x);
|
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new((double)FIX2LONG(x) * RFLOAT(y)->value);
|
2005-08-03 03:09:48 -04:00
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-03 01:46:36 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fixdivmod(long x, long y, long *divp, long *modp)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
long div, mod;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-07-03 01:46:36 -04:00
|
|
|
if (y == 0) rb_num_zerodiv();
|
|
|
|
if (y < 0) {
|
|
|
|
if (x < 0)
|
|
|
|
div = -x / -y;
|
|
|
|
else
|
|
|
|
div = - (x / -y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-07-03 01:46:36 -04:00
|
|
|
else {
|
|
|
|
if (x < 0)
|
|
|
|
div = - (-x / y);
|
|
|
|
else
|
|
|
|
div = x / y;
|
|
|
|
}
|
|
|
|
mod = x - div*y;
|
2000-07-06 03:21:26 -04:00
|
|
|
if ((mod < 0 && y > 0) || (mod > 0 && y < 0)) {
|
|
|
|
mod += y;
|
|
|
|
div -= 1;
|
|
|
|
}
|
2000-07-03 01:46:36 -04:00
|
|
|
if (divp) *divp = div;
|
|
|
|
if (modp) *modp = mod;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.quo(numeric) => float
|
|
|
|
*
|
|
|
|
* Returns the floating point result of dividing <i>fix</i> by
|
|
|
|
* <i>numeric</i>.
|
|
|
|
*
|
|
|
|
* 654321.quo(13731) #=> 47.6528293642124
|
|
|
|
* 654321.quo(13731.24) #=> 47.6519964693647
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-01-23 01:22:50 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_quo(VALUE x, VALUE y)
|
2003-01-23 01:22:50 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
|
|
|
return rb_float_new((double)FIX2LONG(x) / (double)FIX2LONG(y));
|
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_float_new((double)FIX2LONG(y) / rb_big2dbl(y));
|
|
|
|
case T_FLOAT:
|
|
|
|
return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
2003-01-23 01:22:50 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
2005-10-05 12:15:16 -04:00
|
|
|
fix_divide(VALUE x, VALUE y, int flo)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
2000-07-03 01:46:36 -04:00
|
|
|
long div;
|
|
|
|
|
|
|
|
fixdivmod(FIX2LONG(x), FIX2LONG(y), &div, 0);
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2NUM(div);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
x = rb_int2big(FIX2LONG(x));
|
|
|
|
return rb_big_div(x, y);
|
|
|
|
case T_FLOAT:
|
2005-10-05 12:15:16 -04:00
|
|
|
if (flo) {
|
|
|
|
return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
long div = (double)FIX2LONG(x) / RFLOAT(y)->value;
|
|
|
|
return LONG2NUM(div);
|
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2005-10-05 12:15:16 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix / numeric => numeric_result
|
|
|
|
*
|
|
|
|
* Performs division: the class of the resulting object depends on
|
|
|
|
* the class of <code>numeric</code> and on the magnitude of the
|
|
|
|
* result.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fix_div(VALUE x, VALUE y)
|
|
|
|
{
|
|
|
|
return fix_divide(x, y, Qtrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.div(numeric) => numeric_result
|
|
|
|
*
|
|
|
|
* Performs integer division: returns integer value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fix_idiv(VALUE x, VALUE y)
|
|
|
|
{
|
|
|
|
return fix_divide(x, y, Qfalse);
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix % other => Numeric
|
|
|
|
* fix.modulo(other) => Numeric
|
|
|
|
*
|
|
|
|
* Returns <code>fix</code> modulo <code>other</code>.
|
|
|
|
* See <code>Numeric.divmod</code> for more information.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_mod(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
if (FIXNUM_P(y)) {
|
|
|
|
long mod;
|
|
|
|
|
|
|
|
fixdivmod(FIX2LONG(x), FIX2LONG(y), 0, &mod);
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2NUM(mod);
|
2000-07-03 01:46:36 -04:00
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
x = rb_int2big(FIX2LONG(x));
|
|
|
|
return rb_big_modulo(x, y);
|
|
|
|
case T_FLOAT:
|
|
|
|
{
|
|
|
|
double mod;
|
|
|
|
|
|
|
|
flodivmod((double)FIX2LONG(x), RFLOAT(y)->value, 0, &mod);
|
|
|
|
return rb_float_new(mod);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.divmod(numeric) => array
|
|
|
|
*
|
|
|
|
* See <code>Numeric#divmod</code>.
|
|
|
|
*/
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_divmod(VALUE x, VALUE y)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
if (FIXNUM_P(y)) {
|
|
|
|
long div, mod;
|
|
|
|
|
|
|
|
fixdivmod(FIX2LONG(x), FIX2LONG(y), &div, &mod);
|
|
|
|
|
2002-08-21 11:47:54 -04:00
|
|
|
return rb_assoc_new(LONG2NUM(div), LONG2NUM(mod));
|
2000-07-03 01:46:36 -04:00
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
x = rb_int2big(FIX2LONG(x));
|
|
|
|
return rb_big_divmod(x, y);
|
|
|
|
case T_FLOAT:
|
|
|
|
{
|
|
|
|
double div, mod;
|
|
|
|
volatile VALUE a, b;
|
|
|
|
|
|
|
|
flodivmod((double)FIX2LONG(x), RFLOAT(y)->value, &div, &mod);
|
|
|
|
a = rb_float_new(div);
|
|
|
|
b = rb_float_new(mod);
|
|
|
|
return rb_assoc_new(a, b);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix ** other => Numeric
|
|
|
|
*
|
|
|
|
* Raises <code>fix</code> to the <code>other</code> power, which may
|
|
|
|
* be negative or fractional.
|
|
|
|
*
|
|
|
|
* 2 ** 3 #=> 8
|
|
|
|
* 2 ** -1 #=> 0.5
|
|
|
|
* 2 ** 0.5 #=> 1.4142135623731
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_pow(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
long a, b;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
b = FIX2LONG(y);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (b == 0) return INT2FIX(1);
|
1999-08-13 01:45:20 -04:00
|
|
|
if (b == 1) return x;
|
1999-01-19 23:59:39 -05:00
|
|
|
a = FIX2LONG(x);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (b > 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_big_pow(rb_int2big(a), y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(pow((double)a, (double)b));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-03 03:09:48 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
x = rb_int2big(FIX2LONG(x));
|
|
|
|
return rb_big_pow(x, y);
|
|
|
|
case T_FLOAT:
|
|
|
|
return rb_float_new(pow((double)FIX2LONG(x), RFLOAT(y)->value));
|
|
|
|
default:
|
|
|
|
return rb_num_coerce_bin(x, y);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix == other
|
|
|
|
*
|
|
|
|
* Return <code>true</code> if <code>fix</code> equals <code>other</code>
|
|
|
|
* numerically.
|
|
|
|
*
|
|
|
|
* 1 == 2 #=> false
|
|
|
|
* 1 == 1.0 #=> true
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_equal(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-02-21 08:30:17 -05:00
|
|
|
if (x == y) return Qtrue;
|
|
|
|
if (FIXNUM_P(y)) return Qfalse;
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_big_eq(y, x);
|
|
|
|
case T_FLOAT:
|
|
|
|
return (double)FIX2LONG(x) == RFLOAT(y)->value ? Qtrue : Qfalse;
|
|
|
|
default:
|
1998-01-16 07:13:05 -05:00
|
|
|
return num_equal(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix <=> numeric => -1, 0, +1
|
|
|
|
*
|
|
|
|
* Comparison---Returns -1, 0, or +1 depending on whether <i>fix</i> is
|
|
|
|
* less than, equal to, or greater than <i>numeric</i>. This is the
|
|
|
|
* basis for the tests in <code>Comparable</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_cmp(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-02-21 03:53:15 -05:00
|
|
|
if (x == y) return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (FIXNUM_P(y)) {
|
2007-02-21 03:53:15 -05:00
|
|
|
if (FIX2LONG(x) > FIX2LONG(y)) return INT2FIX(1);
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(-1);
|
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return rb_big_cmp(rb_int2big(FIX2LONG(x)), y);
|
|
|
|
case T_FLOAT:
|
|
|
|
return rb_dbl_cmp((double)FIX2LONG(x), RFLOAT(y)->value);
|
|
|
|
default:
|
2002-12-19 04:20:20 -05:00
|
|
|
return rb_num_coerce_cmp(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix > other => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the value of <code>fix</code> is
|
|
|
|
* greater than that of <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_gt(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
2007-02-21 03:53:15 -05:00
|
|
|
if (FIX2LONG(x) > FIX2LONG(y)) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) > 0 ? Qtrue : Qfalse;
|
|
|
|
case T_FLOAT:
|
|
|
|
return (double)FIX2LONG(x) > RFLOAT(y)->value ? Qtrue : Qfalse;
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix >= other => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the value of <code>fix</code> is
|
|
|
|
* greater than or equal to that of <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_ge(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
2007-02-21 03:53:15 -05:00
|
|
|
if (FIX2LONG(x) >= FIX2LONG(y)) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) >= 0 ? Qtrue : Qfalse;
|
|
|
|
case T_FLOAT:
|
|
|
|
return (double)FIX2LONG(x) >= RFLOAT(y)->value ? Qtrue : Qfalse;
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix < other => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the value of <code>fix</code> is
|
|
|
|
* less than that of <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_lt(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
2007-02-21 03:53:15 -05:00
|
|
|
if (FIX2LONG(x) < FIX2LONG(y)) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) < 0 ? Qtrue : Qfalse;
|
|
|
|
case T_FLOAT:
|
|
|
|
return (double)FIX2LONG(x) < RFLOAT(y)->value ? Qtrue : Qfalse;
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix <= other => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the value of <code>fix</code> is
|
|
|
|
* less thanor equal to that of <code>other</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_le(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (FIXNUM_P(y)) {
|
2007-02-21 03:53:15 -05:00
|
|
|
if (FIX2LONG(x) <= FIX2LONG(y)) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2005-08-12 04:13:28 -04:00
|
|
|
switch (TYPE(y)) {
|
|
|
|
case T_BIGNUM:
|
|
|
|
return FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(x)), y)) <= 0 ? Qtrue : Qfalse;
|
|
|
|
case T_FLOAT:
|
|
|
|
return (double)FIX2LONG(x) <= RFLOAT(y)->value ? Qtrue : Qfalse;
|
|
|
|
default:
|
2003-07-31 04:42:44 -04:00
|
|
|
return rb_num_coerce_relop(x, y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ~fix => integer
|
|
|
|
*
|
|
|
|
* One's complement: returns a number where each bit is flipped.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_rev(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
long val = FIX2LONG(num);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
val = ~val;
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix & other => integer
|
|
|
|
*
|
|
|
|
* Bitwise AND.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_and(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (TYPE(y) == T_BIGNUM) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_big_and(y, x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
val = FIX2LONG(x) & NUM2LONG(y);
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix | other => integer
|
|
|
|
*
|
|
|
|
* Bitwise OR.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_or(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (TYPE(y) == T_BIGNUM) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_big_or(y, x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
val = FIX2LONG(x) | NUM2LONG(y);
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix ^ other => integer
|
|
|
|
*
|
|
|
|
* Bitwise EXCLUSIVE OR.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_xor(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
long val;
|
|
|
|
|
|
|
|
if (TYPE(y) == T_BIGNUM) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_big_xor(y, x);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
val = FIX2LONG(x) ^ NUM2LONG(y);
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
static VALUE fix_rshift(VALUE, VALUE);
|
2002-06-10 06:06:12 -04:00
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix << count => integer
|
|
|
|
*
|
|
|
|
* Shifts _fix_ left _count_ positions (right if _count_ is negative).
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_lshift(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-07-03 01:46:36 -04:00
|
|
|
long val, width;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
val = NUM2LONG(x);
|
2000-07-03 01:46:36 -04:00
|
|
|
width = NUM2LONG(y);
|
2002-06-10 06:06:12 -04:00
|
|
|
if (width < 0)
|
2002-08-21 11:47:54 -04:00
|
|
|
return fix_rshift(x, LONG2FIX(-width));
|
1998-01-16 07:13:05 -05:00
|
|
|
if (width > (sizeof(VALUE)*CHAR_BIT-1)
|
1999-01-19 23:59:39 -05:00
|
|
|
|| ((unsigned long)val)>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) {
|
|
|
|
return rb_big_lshift(rb_int2big(val), y);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
val = val << width;
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix >> count => integer
|
|
|
|
*
|
2005-11-01 08:04:35 -05:00
|
|
|
* Shifts _fix_ right _count_ positions (left if _count_ is negative).
|
2003-12-23 11:21:17 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_rshift(VALUE x, VALUE y)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
long i, val;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
i = NUM2LONG(y);
|
1999-12-06 04:04:03 -05:00
|
|
|
if (i < 0)
|
2002-08-21 11:47:54 -04:00
|
|
|
return fix_lshift(x, LONG2FIX(-i));
|
2000-07-03 01:46:36 -04:00
|
|
|
if (i == 0) return x;
|
2002-06-10 06:06:12 -04:00
|
|
|
val = FIX2LONG(x);
|
2000-07-03 01:46:36 -04:00
|
|
|
if (i >= sizeof(long)*CHAR_BIT-1) {
|
2002-06-10 06:06:12 -04:00
|
|
|
if (val < 0) return INT2FIX(-1);
|
2000-07-03 01:46:36 -04:00
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
2002-06-10 06:06:12 -04:00
|
|
|
val = RSHIFT(val, i);
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix[n] => 0, 1
|
|
|
|
*
|
|
|
|
* Bit Reference---Returns the <em>n</em>th bit in the binary
|
|
|
|
* representation of <i>fix</i>, where <i>fix</i>[0] is the least
|
|
|
|
* significant bit.
|
|
|
|
*
|
|
|
|
* a = 0b11001100101010
|
|
|
|
* 30.downto(0) do |n| print a[n] end
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 0000000000000000011001100101010
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_aref(VALUE fix, VALUE idx)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
long val = FIX2LONG(fix);
|
2002-08-13 05:21:18 -04:00
|
|
|
long i;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-10-29 00:07:26 -05:00
|
|
|
if (TYPE(idx) == T_BIGNUM) {
|
2002-08-13 05:21:18 -04:00
|
|
|
idx = rb_big_norm(idx);
|
|
|
|
if (!FIXNUM_P(idx)) {
|
|
|
|
if (!RBIGNUM(idx)->sign || val >= 0)
|
|
|
|
return INT2FIX(0);
|
|
|
|
return INT2FIX(1);
|
|
|
|
}
|
2001-10-29 00:07:26 -05:00
|
|
|
}
|
2002-08-13 05:21:18 -04:00
|
|
|
i = NUM2LONG(idx);
|
2001-10-29 00:07:26 -05:00
|
|
|
|
2002-08-13 05:21:18 -04:00
|
|
|
if (i < 0) return INT2FIX(0);
|
|
|
|
if (sizeof(VALUE)*CHAR_BIT-1 < i) {
|
|
|
|
if (val < 0) return INT2FIX(1);
|
1998-01-16 07:13:05 -05:00
|
|
|
return INT2FIX(0);
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
2002-08-13 05:21:18 -04:00
|
|
|
if (val & (1L<<i))
|
|
|
|
return INT2FIX(1);
|
|
|
|
return INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.to_f -> float
|
|
|
|
*
|
|
|
|
* Converts <i>fix</i> to a <code>Float</code>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_to_f(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
double val;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
val = (double)FIX2LONG(num);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.abs -> aFixnum
|
|
|
|
*
|
|
|
|
* Returns the absolute value of <i>fix</i>.
|
|
|
|
*
|
|
|
|
* -12345.abs #=> 12345
|
|
|
|
* 12345.abs #=> 12345
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_abs(VALUE fix)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
long i = FIX2LONG(fix);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (i < 0) i = -i;
|
|
|
|
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2NUM(i);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.id2name -> string or nil
|
|
|
|
*
|
|
|
|
* Returns the name of the object whose symbol id is <i>fix</i>. If
|
|
|
|
* there is no symbol in the symbol table with this value, returns
|
|
|
|
* <code>nil</code>. <code>id2name</code> has nothing to do with the
|
|
|
|
* <code>Object.id</code> method. See also <code>Fixnum#to_sym</code>,
|
|
|
|
* <code>String#intern</code>, and class <code>Symbol</code>.
|
|
|
|
*
|
|
|
|
* symbol = :@inst_var #=> :@inst_var
|
|
|
|
* id = symbol.to_i #=> 9818
|
|
|
|
* id.id2name #=> "@inst_var"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_id2name(VALUE fix)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const char *name = rb_id2name(FIX2UINT(fix));
|
1999-01-19 23:59:39 -05:00
|
|
|
if (name) return rb_str_new2(name);
|
1998-01-16 07:13:05 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.to_sym -> aSymbol
|
|
|
|
*
|
|
|
|
* Returns the symbol whose integer value is <i>fix</i>. See also
|
|
|
|
* <code>Fixnum#id2name</code>.
|
|
|
|
*
|
|
|
|
* fred = :fred.to_i
|
|
|
|
* fred.id2name #=> "fred"
|
|
|
|
* fred.to_sym #=> :fred
|
|
|
|
*/
|
|
|
|
|
2002-11-03 06:04:35 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_to_sym(VALUE fix)
|
2002-11-03 06:04:35 -05:00
|
|
|
{
|
|
|
|
ID id = FIX2UINT(fix);
|
|
|
|
|
|
|
|
if (rb_id2name(id)) {
|
|
|
|
return ID2SYM(id);
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.size -> fixnum
|
|
|
|
*
|
|
|
|
* Returns the number of <em>bytes</em> in the machine representation
|
|
|
|
* of a <code>Fixnum</code>.
|
|
|
|
*
|
|
|
|
* 1.size #=> 4
|
|
|
|
* -1.size #=> 4
|
|
|
|
* 2147483647.size #=> 4
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_size(VALUE fix)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return INT2FIX(sizeof(long));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.upto(limit) {|i| block } => int
|
|
|
|
*
|
|
|
|
* Iterates <em>block</em>, passing in integer values from <i>int</i>
|
|
|
|
* up to and including <i>limit</i>.
|
|
|
|
*
|
|
|
|
* 5.upto(10) { |i| print i, " " }
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 5 6 7 8 9 10
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_upto(VALUE from, VALUE to)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-02-03 04:15:42 -05:00
|
|
|
RETURN_ENUMERATOR(from, 1, &to);
|
2002-04-24 00:54:16 -04:00
|
|
|
if (FIXNUM_P(from) && FIXNUM_P(to)) {
|
|
|
|
long i, end;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
end = FIX2LONG(to);
|
|
|
|
for (i = FIX2LONG(from); i <= end; i++) {
|
2002-08-21 11:47:54 -04:00
|
|
|
rb_yield(LONG2FIX(i));
|
2002-04-24 00:54:16 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
else {
|
2003-05-07 23:56:12 -04:00
|
|
|
VALUE i = from, c;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-05-07 23:56:12 -04:00
|
|
|
while (!(c = rb_funcall(i, '>', 1, to))) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_yield(i);
|
|
|
|
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
|
|
|
}
|
2003-05-07 23:56:12 -04:00
|
|
|
if (NIL_P(c)) rb_cmperr(i, to);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.downto(limit) {|i| block } => int
|
|
|
|
*
|
|
|
|
* Iterates <em>block</em>, passing decreasing values from <i>int</i>
|
|
|
|
* down to and including <i>limit</i>.
|
|
|
|
*
|
|
|
|
* 5.downto(1) { |n| print n, ".. " }
|
|
|
|
* print " Liftoff!\n"
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 5.. 4.. 3.. 2.. 1.. Liftoff!
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_downto(VALUE from, VALUE to)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-02-03 04:15:42 -05:00
|
|
|
RETURN_ENUMERATOR(from, 1, &to);
|
2002-04-24 00:54:16 -04:00
|
|
|
if (FIXNUM_P(from) && FIXNUM_P(to)) {
|
|
|
|
long i, end;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
end = FIX2LONG(to);
|
|
|
|
for (i=FIX2LONG(from); i >= end; i--) {
|
2002-08-21 11:47:54 -04:00
|
|
|
rb_yield(LONG2FIX(i));
|
2002-04-24 00:54:16 -04:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
2003-05-07 23:56:12 -04:00
|
|
|
VALUE i = from, c;
|
2002-04-24 00:54:16 -04:00
|
|
|
|
2003-05-07 23:56:12 -04:00
|
|
|
while (!(c = rb_funcall(i, '<', 1, to))) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_yield(i);
|
|
|
|
i = rb_funcall(i, '-', 1, INT2FIX(1));
|
|
|
|
}
|
2003-05-07 23:56:12 -04:00
|
|
|
if (NIL_P(c)) rb_cmperr(i, to);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2003-12-27 00:46:46 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* int.times {|i| block } => int
|
|
|
|
*
|
|
|
|
* Iterates block <i>int</i> times, passing in values from zero to
|
|
|
|
* <i>int</i> - 1.
|
|
|
|
*
|
|
|
|
* 5.times do |i|
|
|
|
|
* print i, " "
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* 0 1 2 3 4
|
|
|
|
*/
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE yarv_invoke_Integer_times_special_block(VALUE);
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
int_dotimes(VALUE num)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE val;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
RETURN_ENUMERATOR(num, 0, 0);
|
|
|
|
if((val = yarv_invoke_Integer_times_special_block(num)) != Qundef){
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FIXNUM_P(num)) {
|
|
|
|
long i, end;
|
|
|
|
|
|
|
|
end = FIX2LONG(num);
|
|
|
|
for (i=0; i<end; i++) {
|
|
|
|
rb_yield(LONG2FIX(i));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE i = INT2FIX(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
for (;;) {
|
|
|
|
if (!RTEST(rb_funcall(i, '<', 1, num))) break;
|
|
|
|
rb_yield(i);
|
|
|
|
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
return num;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-23 11:21:17 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.zero? => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>fix</i> is zero.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
fix_zero_p(VALUE num)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
if (FIX2LONG(num) == 0) {
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-09-21 02:09:26 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.odd? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>fix</i> is an odd number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fix_odd_p(VALUE num)
|
|
|
|
{
|
|
|
|
if (num & 2) {
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* fix.even? -> true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>fix</i> is an even number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fix_even_p(VALUE num)
|
|
|
|
{
|
|
|
|
if (num & 2) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_Numeric(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-01 05:42:38 -04:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD__ < 4
|
1999-08-13 01:45:20 -04:00
|
|
|
/* allow divide by zero -- Inf */
|
|
|
|
fpsetmask(fpgetmask() & ~(FP_X_DZ|FP_X_INV|FP_X_OFL));
|
2003-12-20 10:45:15 -05:00
|
|
|
#elif defined(_UNICOSMP)
|
|
|
|
/* Turn off floating point exceptions for divide by zero, etc. */
|
|
|
|
_set_Creg(0, 0);
|
2005-01-10 19:46:35 -05:00
|
|
|
#elif defined(__BORLANDC__)
|
|
|
|
/* Turn off floating point exceptions for overflow, etc. */
|
|
|
|
_control87(MCW_EM, MCW_EM);
|
1999-08-13 01:45:20 -04:00
|
|
|
#endif
|
2001-08-05 23:05:23 -04:00
|
|
|
id_coerce = rb_intern("coerce");
|
|
|
|
id_to_i = rb_intern("to_i");
|
2003-07-21 14:48:58 -04:00
|
|
|
id_eq = rb_intern("==");
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError);
|
2000-05-01 05:42:38 -04:00
|
|
|
rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cNumeric = rb_define_class("Numeric", rb_cObject);
|
|
|
|
|
2003-12-01 08:16:09 -05:00
|
|
|
rb_define_method(rb_cNumeric, "singleton_method_added", num_sadded, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_include_module(rb_cNumeric, rb_mComparable);
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1);
|
2003-04-03 00:25:00 -05:00
|
|
|
rb_define_method(rb_cNumeric, "coerce", num_coerce, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
|
2002-11-22 04:14:24 -05:00
|
|
|
rb_define_method(rb_cNumeric, "<=>", num_cmp, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
|
2003-01-23 01:22:50 -05:00
|
|
|
rb_define_method(rb_cNumeric, "quo", num_quo, 1);
|
|
|
|
rb_define_method(rb_cNumeric, "div", num_div, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cNumeric, "divmod", num_divmod, 1);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cNumeric, "modulo", num_modulo, 1);
|
2000-07-04 00:17:26 -04:00
|
|
|
rb_define_method(rb_cNumeric, "remainder", num_remainder, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cNumeric, "abs", num_abs, 0);
|
2002-07-29 02:14:10 -04:00
|
|
|
rb_define_method(rb_cNumeric, "to_int", num_to_int, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2005-12-07 03:41:59 -05:00
|
|
|
rb_define_method(rb_cNumeric, "scalar?", num_scalar_p, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cNumeric, "floor", num_floor, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "ceil", num_ceil, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "round", num_round, 0);
|
|
|
|
rb_define_method(rb_cNumeric, "truncate", num_truncate, 0);
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_define_method(rb_cNumeric, "step", num_step, -1);
|
2000-07-06 03:21:26 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cInteger = rb_define_class("Integer", rb_cNumeric);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cInteger);
|
2001-08-29 02:28:51 -04:00
|
|
|
rb_undef_method(CLASS_OF(rb_cInteger), "new");
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
|
2006-09-21 02:09:26 -04:00
|
|
|
rb_define_method(rb_cInteger, "odd?", int_odd_p, 0);
|
|
|
|
rb_define_method(rb_cInteger, "even?", int_even_p, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cInteger, "upto", int_upto, 1);
|
|
|
|
rb_define_method(rb_cInteger, "downto", int_downto, 1);
|
|
|
|
rb_define_method(rb_cInteger, "times", int_dotimes, 0);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_include_module(rb_cInteger, rb_mPrecision);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cInteger, "succ", int_succ, 0);
|
|
|
|
rb_define_method(rb_cInteger, "next", int_succ, 0);
|
2007-01-29 23:27:04 -05:00
|
|
|
rb_define_method(rb_cInteger, "pred", int_pred, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cInteger, "chr", int_chr, 0);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cInteger, "to_i", int_to_i, 0);
|
2000-11-13 00:39:35 -05:00
|
|
|
rb_define_method(rb_cInteger, "to_int", int_to_i, 0);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cInteger, "floor", int_to_i, 0);
|
|
|
|
rb_define_method(rb_cInteger, "ceil", int_to_i, 0);
|
|
|
|
rb_define_method(rb_cInteger, "round", int_to_i, 0);
|
|
|
|
rb_define_method(rb_cInteger, "truncate", int_to_i, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_cFixnum = rb_define_class("Fixnum", rb_cInteger);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_include_module(rb_cFixnum, rb_mPrecision);
|
|
|
|
rb_define_singleton_method(rb_cFixnum, "induced_from", rb_fix_induced_from, 1);
|
|
|
|
rb_define_singleton_method(rb_cInteger, "induced_from", rb_int_induced_from, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2001-11-19 00:03:03 -05:00
|
|
|
rb_define_method(rb_cFixnum, "to_s", fix_to_s, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "id2name", fix_id2name, 0);
|
2002-11-03 06:04:35 -05:00
|
|
|
rb_define_method(rb_cFixnum, "to_sym", fix_to_sym, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "-@", fix_uminus, 0);
|
|
|
|
rb_define_method(rb_cFixnum, "+", fix_plus, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "-", fix_minus, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "*", fix_mul, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "/", fix_div, 1);
|
2005-10-05 12:15:16 -04:00
|
|
|
rb_define_method(rb_cFixnum, "div", fix_idiv, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cFixnum, "%", fix_mod, 1);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cFixnum, "modulo", fix_mod, 1);
|
2000-07-03 01:46:36 -04:00
|
|
|
rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1);
|
2003-01-23 01:22:50 -05:00
|
|
|
rb_define_method(rb_cFixnum, "quo", fix_quo, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cFixnum, "**", fix_pow, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "abs", fix_abs, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "==", fix_equal, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "<=>", fix_cmp, 1);
|
|
|
|
rb_define_method(rb_cFixnum, ">", fix_gt, 1);
|
|
|
|
rb_define_method(rb_cFixnum, ">=", fix_ge, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "<", fix_lt, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "<=", fix_le, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "~", fix_rev, 0);
|
|
|
|
rb_define_method(rb_cFixnum, "&", fix_and, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "|", fix_or, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "^", fix_xor, 1);
|
|
|
|
rb_define_method(rb_cFixnum, "[]", fix_aref, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "<<", fix_lshift, 1);
|
|
|
|
rb_define_method(rb_cFixnum, ">>", fix_rshift, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0);
|
|
|
|
rb_define_method(rb_cFixnum, "size", fix_size, 0);
|
|
|
|
rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0);
|
2006-09-21 11:36:17 -04:00
|
|
|
rb_define_method(rb_cFixnum, "odd?", fix_odd_p, 0);
|
|
|
|
rb_define_method(rb_cFixnum, "even?", fix_even_p, 0);
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_define_method(rb_cFixnum, "succ", fix_succ, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_cFloat = rb_define_class("Float", rb_cNumeric);
|
|
|
|
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cFloat);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_undef_method(CLASS_OF(rb_cFloat), "new");
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_singleton_method(rb_cFloat, "induced_from", rb_flo_induced_from, 1);
|
|
|
|
rb_include_module(rb_cFloat, rb_mPrecision);
|
|
|
|
|
2002-12-24 03:53:56 -05:00
|
|
|
rb_define_const(rb_cFloat, "ROUNDS", INT2FIX(FLT_ROUNDS));
|
|
|
|
rb_define_const(rb_cFloat, "RADIX", INT2FIX(FLT_RADIX));
|
|
|
|
rb_define_const(rb_cFloat, "MANT_DIG", INT2FIX(DBL_MANT_DIG));
|
|
|
|
rb_define_const(rb_cFloat, "DIG", INT2FIX(DBL_DIG));
|
|
|
|
rb_define_const(rb_cFloat, "MIN_EXP", INT2FIX(DBL_MIN_EXP));
|
|
|
|
rb_define_const(rb_cFloat, "MAX_EXP", INT2FIX(DBL_MAX_EXP));
|
|
|
|
rb_define_const(rb_cFloat, "MIN_10_EXP", INT2FIX(DBL_MIN_10_EXP));
|
|
|
|
rb_define_const(rb_cFloat, "MAX_10_EXP", INT2FIX(DBL_MAX_10_EXP));
|
|
|
|
rb_define_const(rb_cFloat, "MIN", rb_float_new(DBL_MIN));
|
|
|
|
rb_define_const(rb_cFloat, "MAX", rb_float_new(DBL_MAX));
|
|
|
|
rb_define_const(rb_cFloat, "EPSILON", rb_float_new(DBL_EPSILON));
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cFloat, "to_s", flo_to_s, 0);
|
|
|
|
rb_define_method(rb_cFloat, "coerce", flo_coerce, 1);
|
|
|
|
rb_define_method(rb_cFloat, "-@", flo_uminus, 0);
|
|
|
|
rb_define_method(rb_cFloat, "+", flo_plus, 1);
|
|
|
|
rb_define_method(rb_cFloat, "-", flo_minus, 1);
|
|
|
|
rb_define_method(rb_cFloat, "*", flo_mul, 1);
|
|
|
|
rb_define_method(rb_cFloat, "/", flo_div, 1);
|
|
|
|
rb_define_method(rb_cFloat, "%", flo_mod, 1);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cFloat, "modulo", flo_mod, 1);
|
2000-01-31 22:12:21 -05:00
|
|
|
rb_define_method(rb_cFloat, "divmod", flo_divmod, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cFloat, "**", flo_pow, 1);
|
|
|
|
rb_define_method(rb_cFloat, "==", flo_eq, 1);
|
|
|
|
rb_define_method(rb_cFloat, "<=>", flo_cmp, 1);
|
|
|
|
rb_define_method(rb_cFloat, ">", flo_gt, 1);
|
|
|
|
rb_define_method(rb_cFloat, ">=", flo_ge, 1);
|
|
|
|
rb_define_method(rb_cFloat, "<", flo_lt, 1);
|
|
|
|
rb_define_method(rb_cFloat, "<=", flo_le, 1);
|
|
|
|
rb_define_method(rb_cFloat, "eql?", flo_eql, 1);
|
|
|
|
rb_define_method(rb_cFloat, "hash", flo_hash, 0);
|
|
|
|
rb_define_method(rb_cFloat, "to_f", flo_to_f, 0);
|
|
|
|
rb_define_method(rb_cFloat, "abs", flo_abs, 0);
|
|
|
|
rb_define_method(rb_cFloat, "zero?", flo_zero_p, 0);
|
|
|
|
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cFloat, "to_i", flo_truncate, 0);
|
2002-07-29 02:14:10 -04:00
|
|
|
rb_define_method(rb_cFloat, "to_int", flo_truncate, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cFloat, "floor", flo_floor, 0);
|
|
|
|
rb_define_method(rb_cFloat, "ceil", flo_ceil, 0);
|
|
|
|
rb_define_method(rb_cFloat, "round", flo_round, 0);
|
2000-07-06 03:21:26 -04:00
|
|
|
rb_define_method(rb_cFloat, "truncate", flo_truncate, 0);
|
2000-06-12 03:48:31 -04:00
|
|
|
|
|
|
|
rb_define_method(rb_cFloat, "nan?", flo_is_nan_p, 0);
|
|
|
|
rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);
|
|
|
|
rb_define_method(rb_cFloat, "finite?", flo_is_finite_p, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|