ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce
@ 2021-03-19  0:37 gaojun
  2021-03-19  1:01 ` [ruby-core:102923] " gaojun
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gaojun @ 2021-03-19  0:37 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been reported by gaojun (Jun Gao).

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102923] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
@ 2021-03-19  1:01 ` gaojun
  2021-03-19  1:05 ` [ruby-core:102924] " hanmac
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gaojun @ 2021-03-19  1:01 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by gaojun (Jun Gao).


Some more interesting samples:
``` ruby
3.0.0 :001 > [0,-2305843009213693953,-2305843009213693953].inject(:+)
 => 13835058055282163710 
3.0.0 :002 > [-2305843009213693953,-2305843009213693953].inject(:+)
 => -4611686018427387906 
3.0.0 :003 > [-2305843009213693953,-2305843009213693953,0].inject(:+)
 => -4611686018427387906 
```


----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90987

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102924] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
  2021-03-19  1:01 ` [ruby-core:102923] " gaojun
@ 2021-03-19  1:05 ` hanmac
  2021-03-19  3:22 ` [ruby-core:102925] " marcandre-ruby-core
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hanmac @ 2021-03-19  1:05 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by Hanmac (Hans Mackowiak).


more interesting samples:

```ruby
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
#=> 11529215046068469757
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(&:+)
#=> -6917529027641081859
```

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90988

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102925] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
  2021-03-19  1:01 ` [ruby-core:102923] " gaojun
  2021-03-19  1:05 ` [ruby-core:102924] " hanmac
@ 2021-03-19  3:22 ` marcandre-ruby-core
  2021-03-19  3:34 ` [ruby-core:102926] " marcandre-ruby-core
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre-ruby-core @ 2021-03-19  3:22 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by marcandre (Marc-Andre Lafortune).

Assignee set to marcandre (Marc-Andre Lafortune)

Right, there's a `ULONG2NUM` that seem to assume the subtotal is always positive...
I'll make a PR for this

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90989

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102926] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
                   ` (2 preceding siblings ...)
  2021-03-19  3:22 ` [ruby-core:102925] " marcandre-ruby-core
@ 2021-03-19  3:34 ` marcandre-ruby-core
  2021-03-19  3:38 ` [ruby-core:102927] " akr
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre-ruby-core @ 2021-03-19  3:34 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by marcandre (Marc-Andre Lafortune).

Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED

Removing the letter 'U' fixes it...

https://github.com/ruby/ruby/pull/4288

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90990

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102927] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
                   ` (3 preceding siblings ...)
  2021-03-19  3:34 ` [ruby-core:102926] " marcandre-ruby-core
@ 2021-03-19  3:38 ` akr
  2021-03-19  4:40 ` [ruby-core:102928] " marcandre-ruby-core
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: akr @ 2021-03-19  3:38 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by akr (Akira Tanaka).


marcandre (Marc-Andre Lafortune) wrote in #note-3:
> Right, there's a `ULONG2NUM` that seem to assume the subtotal is always positive...
> I'll make a PR for this

nobu changed it from LONG2NUM to ULONG2NUM at
https://github.com/ruby/ruby/commit/6bb70c11b344dee0739c6fb7bbf0ea124b5225b6



----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90991

* Author: gaojun (Jun Gao)
* Status: Open
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102928] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
                   ` (4 preceding siblings ...)
  2021-03-19  3:38 ` [ruby-core:102927] " akr
@ 2021-03-19  4:40 ` marcandre-ruby-core
  2021-03-20  7:31 ` [ruby-core:102958] " nagachika00
  2021-04-02  7:01 ` [ruby-core:103168] " naruse
  7 siblings, 0 replies; 9+ messages in thread
From: marcandre-ruby-core @ 2021-03-19  4:40 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by marcandre (Marc-Andre Lafortune).


akr (Akira Tanaka) wrote in #note-5:
> nobu changed it from LONG2NUM to ULONG2NUM at
> https://github.com/ruby/ruby/commit/6bb70c11b344dee0739c6fb7bbf0ea124b5225b6

Thanks.
The other changes were for counts (always positive) and most were considered as integers. In the `inject` case, the values can be any fixnum, including negative ones, so that change was a bug. Now fixed.

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-90993

* Author: gaojun (Jun Gao)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:102958] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
                   ` (5 preceding siblings ...)
  2021-03-19  4:40 ` [ruby-core:102928] " marcandre-ruby-core
@ 2021-03-20  7:31 ` nagachika00
  2021-04-02  7:01 ` [ruby-core:103168] " naruse
  7 siblings, 0 replies; 9+ messages in thread
From: nagachika00 @ 2021-03-20  7:31 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE, 3.0: REQUIRED

ruby_2_7 364c8595884808315aaec9605bf2423963ed81c0 merged revision(s) a85ed626f18d1014d09fb37eb0a703976c3d2b53.

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-91022

* Author: gaojun (Jun Gao)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE, 3.0: REQUIRED
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:103168] [Ruby master Bug#17731] Integer downflow with inject/reduce
  2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
                   ` (6 preceding siblings ...)
  2021-03-20  7:31 ` [ruby-core:102958] " nagachika00
@ 2021-04-02  7:01 ` naruse
  7 siblings, 0 replies; 9+ messages in thread
From: naruse @ 2021-04-02  7:01 UTC (permalink / raw
  To: ruby-core

Issue #17731 has been updated by naruse (Yui NARUSE).

Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE, 3.0: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE, 3.0: DONE

ruby_3_0 855401da495117fcf5d258fe43b71010abc43d9a merged revision(s) a85ed626f18d1014d09fb37eb0a703976c3d2b53.

----------------------------------------
Bug #17731: Integer downflow with inject/reduce
https://bugs.ruby-lang.org/issues/17731#change-91241

* Author: gaojun (Jun Gao)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* Backport: 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE, 3.0: DONE
----------------------------------------
Test case:
[-2305843009213693953,-2305843009213693953,-2305843009213693953].inject(:+)
or
([-2**61-1] * 3).inject(:+)

Expected Result:
-6917529027641081859

Actual Result:
11529215046068469757

Some clues:
* Downflow seems not happen if there are only two elements in Array
* The sample above works fine in https://try.ruby-lang.org/
* [-2305843009213693953,-2305843009213693953,-2305843009213693953].sum  can get the correct result
* ([-2**61] * 3).inject(:+) can get the correct result

Affected Versions:
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
* ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
* ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-02  7:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-19  0:37 [ruby-core:102922] [Ruby master Bug#17731] Integer downflow with inject/reduce gaojun
2021-03-19  1:01 ` [ruby-core:102923] " gaojun
2021-03-19  1:05 ` [ruby-core:102924] " hanmac
2021-03-19  3:22 ` [ruby-core:102925] " marcandre-ruby-core
2021-03-19  3:34 ` [ruby-core:102926] " marcandre-ruby-core
2021-03-19  3:38 ` [ruby-core:102927] " akr
2021-03-19  4:40 ` [ruby-core:102928] " marcandre-ruby-core
2021-03-20  7:31 ` [ruby-core:102958] " nagachika00
2021-04-02  7:01 ` [ruby-core:103168] " naruse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).