[macruby-changes] [MacRuby/MacRuby] 9130bd: fix an overflow by multiplying

GitHub noreply at github.com
Tue May 15 07:21:16 PDT 2012


  Branch: refs/heads/master
  Home:   https://github.com/MacRuby/MacRuby
  Commit: 9130bd366d5dd62aa847a8cef8a02c1c3f82f4d2
      https://github.com/MacRuby/MacRuby/commit/9130bd366d5dd62aa847a8cef8a02c1c3f82f4d2
  Author: Watson <watson1978 at gmail.com>
  Date:   2012-05-15 (Tue, 15 May 2012)

  Changed paths:
    M kernel.c

  Log Message:
  -----------
  fix an overflow by multiplying

if multiply Fixnum value between about half of max of long type (32bit), calculated value is broken.

Test Script
----
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

a = 2147483648
b = 2147483647

assert_equal(4611686016279904256, a * b)
assert_equal(-4611686016279904256, (-a) * b)
assert_equal(-4611686016279904256, a * (-b))
assert_equal(4611686016279904256, (-a) * (-b))





More information about the macruby-changes mailing list