File tree Expand file tree Collapse file tree 4 files changed +12
-3
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 4 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ Compatibility:
25
25
* Fix ` rb_str_locktmp() ` and ` rb_str_unlocktmp() ` to raise ` FrozenError ` when string argument is frozen (#3752 , @andrykonchin ).
26
26
* Fix Struct setters to raise ` FrozenError ` when a struct is frozen (#3850 , @andrykonchin ).
27
27
* Fix ` Struct#initialize ` when mixed positional and keyword arguments (#3855 , @andrykonchin ).
28
+ * Fix ` Integer.sqrt ` for large values (#3872 , @tompng ).
28
29
29
30
Performance:
30
31
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -350,7 +350,17 @@ def self.try_convert(obj)
350
350
def self . sqrt ( n )
351
351
n = Primitive . rb_to_int ( n )
352
352
raise Math ::DomainError if n . negative?
353
- Math . sqrt ( n ) . floor
353
+ return Math . sqrt ( n ) . floor if n < 0xfffffffffffff
354
+
355
+ shift = n . bit_length / 4
356
+ x = sqrt ( n >> ( 2 * shift ) ) << shift
357
+ x = ( x + n / x ) / 2
358
+ xx = x * x
359
+ while xx > n
360
+ xx -= 2 * x - 1
361
+ x -= 1
362
+ end
363
+ x
354
364
end
355
365
356
366
private def upto_internal ( val )
Original file line number Diff line number Diff line change 11
11
exclude :test_floor , "<-100000000000000000000> expected but was <0>."
12
12
exclude :test_pow , "FloatDomainError: Infinity"
13
13
exclude :test_round , "<300> expected but was <200>."
14
- exclude :test_square_root , "10**33."
You can’t perform that action at this time.
0 commit comments