卜部昌平
6911b4bc82
test_cdhash: refactor change class
...
It is now strange to test Complex in a class named Rational_Test.
2021-05-12 10:30:46 +09:00
卜部昌平
cc0dc67bbb
cdhash_cmp: can also take complex
...
There are complex literals `123i`, which can also be a case condition.
2021-05-12 10:30:46 +09:00
卜部昌平
d0e6c6e682
cdhash_cmp: rational literals with fractions
...
Nobu kindly pointed out that rational literals can have fractions.
2021-05-12 10:30:46 +09:00
卜部昌平
2bc293e899
cdhash_cmp: can take rational literals
...
Rational literals are those integers suffixed with `r`. They tend to
be a part of more complex expressions like `123/456r`, but in theory
they can live alone. When such "bare" rational literals are passed to
case-when branch, we have to take care of them. Fixes [Bug #17854 ]
2021-05-12 10:30:46 +09:00
Nobuyoshi Nakada
a55eb9a2af
Make reciprocal properly of non-integral rational [Bug #17572 ]
2021-01-23 10:30:59 +09:00
Yusuke Endoh
c1bebbb2ee
test/ruby/test_rational.rb: Prevent "assigned but unused variable"
2020-10-28 00:27:56 +09:00
Kenta Murata
69837229d7
rational.c: convert a numerator to rational before calling fdiv in Kernel.Rational() ( #3702 )
...
This makes `Rational(BigDecimal(1), 60) == Rational(1, 60)`.
[Bug #16518 ]
2020-10-26 18:43:30 +09:00
Kenta Murata
d23d5c3130
rational.c: try converting by to_int in Rational() ( #3684 )
...
[Bug #12485 ]
2020-10-22 17:59:52 +09:00
Nobuyoshi Nakada
3e7d002118
Check exception flag as a bool [Bug #15987 ]
2019-07-11 20:04:29 +09:00
nobu
62c17a2f21
No TypeError at nil if exception: false
...
[ruby-core:91021] [Bug #15525 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-12 05:02:58 +00:00
nobu
17e9667fe9
refine parse_rat
...
* rational.c (read_num): return the exponent instead of the
divisor, to get rid of huge bignums.
* rational.c (parse_rat): subtract exponents instead of reduction
of powers.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-08 02:25:44 +00:00
mame
85bcd2b35f
bignum.c: Bignum#fdiv avoids double division when divisor is bignum
...
`Rational(int, bignum).to_f` sometimes returned a wrong result because
`Bignum#div` casted its divisor to double. [Bug #14637 ] [ruby-core:86330]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-04 14:02:59 +00:00
mrkn
0dc74b94c2
Add exception:
keyword in Kernel#Rational()
...
Support `exception:` keyword argument in `Kernel#Rational()`.
If `exception:` is `false`, `Kernel#Rational()` returns `nil` if the given
value cannot be interpreted as a rational value.
The default value of `exception:` is `true`.
This is part of [Feature #12732 ].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15 07:19:46 +00:00
mrkn
fe2a6f65b1
Support two to_r
-responding args in Rational()
...
* rational.c (nurat_s_convert): call `to_r` to convert non-Numeric
objects also if argc == 2 in Rational().
* test/ruby/test_rational.rb: add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-27 16:45:09 +00:00
nobu
4704a0dc3b
test for r62555
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-24 02:48:09 +00:00
nobu
f954caea43
rational.c: segfault on Rational exponent
...
* rational.c (read_num): fix segfault on Rational() with positive
but less than the length of fractional part exponent. should be
negated to convert to divisor which is a reciprocal.
[ruby-core:85783] [Bug #14547 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-24 02:08:36 +00:00
nobu
3f7221ad3d
force fixable
...
* complex.c (nucomp_hash): force hash values fixable.
[ruby-core:85224] [Bug #14420 ]
* rational.c (nurat_hash): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-30 05:48:28 +00:00
yui-knk
c786db207a
Fix a typo
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24 00:12:53 +00:00
nobu
42c98194b3
freeze Complex and Rational
...
* complex.c (nucomp_s_new_internal, nucomp_loader): Complex
instances are always frozen now. [Feature #13983 ]
* rational.c (nurat_s_new_internal, nurat_loader): Rational
instances are always frozen now. [Feature #13983 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-19 10:58:08 +00:00
nobu
a2ac0982cd
rational.c: float denom
...
* rational.c (parse_rat): allow float as a denominator as well as
a numerator. [ruby-core:79104] [Bug #13134 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 03:35:29 +00:00
nobu
62fb6147cd
rational.c: read_num
...
* rational.c (read_num): use rb_int_parse_cstr to parse integer
parts, and make String#to_r consistent with #to_i and #to_f.
[ruby-core:80098] [Bug #13105 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 03:32:16 +00:00
nobu
a441e89c78
test_rational.rb: invalid exponent
...
* test/ruby/test_rational.rb (test_parse): more checks for invalid
exponent. [ruby-core:80098] [Bug #13105 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 03:05:34 +00:00
nobu
1a6f2391ea
test_rational.rb: duplicate assertions
...
* test/ruby/test_rational.rb (test_parse): remove duplicate
assertions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 02:02:47 +00:00
nobu
b296e29035
rational.c: zero division
...
* rational.c (read_rat_nos): denominator cannot be 0, raise zero
division in that case.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 01:53:52 +00:00
nobu
c8d3020463
test_rational.rb: shorten
...
* test/ruby/test_rational.rb (test_parse): reduce repeated
arguments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-16 00:43:07 +00:00
nobu
2e2063fe16
rational.c: infinity in power
...
* rational.c (nurat_expt): return 0 due to overflow.
[ruby-core:79686] [Bug #13242 ]:
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 23:49:40 +00:00
nobu
06010b2b05
rational.c: infinity in power
...
* rational.c (nurat_expt): return Infinity due to overflow.
[ruby-core:79686] [Bug #13242 ]:
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-22 23:28:26 +00:00
nobu
4c02194216
test_rational.rb: messages
...
* test/ruby/test_rational.rb (test_parse): add messages to
assertions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-16 02:56:28 +00:00
nobu
994d13b98f
rational.c: memory leak in gcd
...
* rational.c (rb_gcd_gmp): fix memory leak. patched by KISHIMOTO,
Makoto <ksmakoto AT dd.iij4u.or.jp> in [ruby-dev:49934].
[Bug #13089 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-30 08:01:34 +00:00
nobu
1778ed59e7
numeric.c: reduce fdiv
...
* numeric.c (rb_int_fdiv_double): reduce first for more precise
result. [ruby-core:78886] [Bug #13078 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-28 04:40:58 +00:00
mrkn
f72be814d9
internal.h: change the default rounding mode to half-up
...
* internal.h (ROUND_DEFAULT): changed to RUBY_NUM_ROUND_HALF_UP.
[Bug #12958 ] [ruby-core:78204]
* test/ruby/test_integer.rb: fix assertions for the above change.
* test/ruby/test_rational.rb: ditto.
* test/test_mathn.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-10 02:36:16 +00:00
nobu
716610ae56
get rid of ambiguous parentheses warnings
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-29 16:06:54 +00:00
nobu
631dde2572
round-down
...
* numeric.c (round_half_down, int_round_half_down): support
round-down mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-25 06:28:00 +00:00
nobu
e41ebc50dc
rational.c: check load
...
* rational.c (nurat_loader, nurat_marshal_load): check if loading
values are Integer. [ruby-core:78071] [Bug #12918 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 07:26:14 +00:00
nobu
dfe91fcd08
numeric.c: round to nearest even
...
* numeric.c (flo_round, int_round): support round-to-nearest-even
semantics of IEEE 754 to match sprintf behavior, and add `half:`
optional keyword argument for the old behavior.
[ruby-core:76273] [Bug #12548 ]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:49:39 +00:00
nobu
3bda73868f
refine assertions
...
* test/ruby/test_complex.rb, test/ruby/test_rational.rb: refine
assertions for descriptive messages.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-24 01:34:06 +00:00
mrkn
94468b4ea5
numeric.c, complex.c: Add finite? and infinite? consistent with Float
...
* numeric.c (num_finite_p, num_infinite_p): Add Numeric#finite? and
Numeric#infinite? [Feature #12039 ] [ruby-core:73618]
* complex.c (rb_complex_finite_p): Add Complex#finite?
* complex.c (rb_complex_infinite_p): Add Complex#infinite?
* test/ruby/test_bignum.rb: Add test for Integer#finite? and
Integer#infinite?
* test/ruby/test_fixnum.rb: ditto.
* test/ruby/test_rational.rb: Add test for Rational#finite? and
Rational#infinite?
* test/ruby/test_complex.rb: Add test for Complex#finite? and
Complex#infinite?
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-17 14:53:00 +00:00
nobu
a7955b31c0
hash method values
...
* test/ruby/test_{complex,range,rational,struct}.rb (test_hash):
hash values should be an Integer, not only a Fixnum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-21 18:06:04 +00:00
akr
449fbfd4d4
Use Integer instead of Fixnum and Bignum.
...
* object.c, numeric.c, enum.c, ext/-test-/bignum/mul.c,
lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rexml/xpath_parser.rb,
lib/rubygems/specification.rb, lib/uri/generic.rb,
bootstraptest/test_eval.rb, basictest/test.rb,
test/-ext-/bignum/test_big2str.rb, test/-ext-/bignum/test_div.rb,
test/-ext-/bignum/test_mul.rb, test/-ext-/bignum/test_str2big.rb,
test/csv/test_data_converters.rb, test/date/test_date.rb,
test/json/test_json_generate.rb, test/minitest/test_minitest_mock.rb,
test/openssl/test_cipher.rb, test/rexml/test_jaxen.rb,
test/ruby/test_array.rb, test/ruby/test_basicinstructions.rb,
test/ruby/test_bignum.rb, test/ruby/test_case.rb,
test/ruby/test_class.rb, test/ruby/test_complex.rb,
test/ruby/test_enum.rb, test/ruby/test_eval.rb,
test/ruby/test_iseq.rb, test/ruby/test_literal.rb,
test/ruby/test_math.rb, test/ruby/test_module.rb,
test/ruby/test_numeric.rb, test/ruby/test_range.rb,
test/ruby/test_rational.rb, test/ruby/test_refinement.rb,
test/ruby/test_rubyvm.rb, test/ruby/test_struct.rb,
test/ruby/test_variable.rb, test/rubygems/test_gem_specification.rb,
test/thread/test_queue.rb: Use Integer instead of Fixnum and Bignum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-17 13:15:57 +00:00
nobu
404bf57aaf
assertions.rb: set default internal encoding
...
* test/lib/test/unit/assertions.rb (assert_raise_with_message):
set default internal encoding to the excpected message, which
affects String#inspect in messages.
* test/lib/test/unit/assertions.rb (assert_warning): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-09 01:25:11 +00:00
nobu
c7f815eed8
test/ruby: suppress runtime warnings
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-19 07:58:09 +00:00
nobu
41f4317f45
test/ruby: suppress parser warnings
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-19 07:48:02 +00:00
naruse
3e92b635fb
Add frozen_string_literal: false for all files
...
When you change this to true, you may need to add more tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
nobu
78f7e342d1
test_rational.rb: fix default external
...
* test/ruby/test_rational.rb (test_conv): fix default external
encoding, which affects inspect results.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-12 04:48:36 +00:00
nobu
7a0981facc
test_rational.rb: r51828
...
* test/ruby/test_rational.rb (test_conv): test for r51828,
encoding of exception message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-12 01:29:32 +00:00
nobu
932e916b9e
numeric.c: Numeric#positive? and Numeric#negative?
...
* numeric.c (num_positive_p, num_negative_p): add methods
Numeric#positive? and Numeric#negative?.
[ruby-core:69173] [Feature #11151 ]
* numeric.c (flo_positive_p, flo_negative_p): specialiazed
functions for Float.
* complex.c (Init_Complex): Complex do not have positive? and
negative? methods
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-17 06:01:47 +00:00
hsbt
e7bcea3831
* test/ruby/test_complex.rb: removed unreachable code.
...
* test/ruby/test_rational.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-27 00:58:16 +00:00
hsbt
618dadaaaa
* test/ruby/test_complex.rb: cherry-picked working assertions from r47251.
...
* test/ruby/test_rational.rb: cherry-picked working assertions from r47263.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-26 13:30:35 +00:00
hsbt
a3a6c69656
* test/ruby/test_complex.rb: removed needless conditions.
...
* test/ruby/test_rational.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-24 03:45:03 +00:00
hsbt
6d67a48876
* test/ruby/test_rational.rb: fixed indent.
...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-24 02:47:59 +00:00