roots 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/roots.rb +9 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa49c39432ae20839016d0beb515b8f623cc9d00
|
4
|
+
data.tar.gz: 41c2a43899fc9f13fa4370bc289ea8f8e6c2f568
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409ff9cda40258bca3e9733a4b0ff240256df9f12e3fd542e872a0765a1fc1607f437df7b998e084c3dfa514cc42ceeeb665eeabf06584ff4a9299950a55778a
|
7
|
+
data.tar.gz: '089bc4812353949dbc022dea855015f8dc813644c9e94de48e691c26b51eb156482751f3a9402361f29542e61897704353f7745d53109675214cb01576df7a80'
|
data/lib/roots.rb
CHANGED
@@ -193,26 +193,25 @@ end
|
|
193
193
|
class Numeric; include Roots end
|
194
194
|
|
195
195
|
module IntRoots
|
196
|
-
def irootn(n)
|
196
|
+
def irootn(n) # Newton's method for nth root
|
197
197
|
return nil if self < 0 && n.even?
|
198
198
|
raise "root n is < 2 or not an Integer" unless n.is_a?(Integer) && n > 1
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
root ^= bitn_mask if (numb = root**n) > num
|
199
|
+
return self if self == 0 || (self == -1 && n.odd?)
|
200
|
+
num = self.abs
|
201
|
+
e, x = n-1, 1 << (num.bit_length-1)/n + 1
|
202
|
+
while (t = (e * x + num / x ** e)/n) < x
|
203
|
+
x = t
|
205
204
|
end
|
206
|
-
|
205
|
+
x *= self < 0 ? -1 : 1
|
207
206
|
end
|
208
|
-
|
207
|
+
|
209
208
|
alias iroot irootn # to provide more syntactic choice
|
210
209
|
|
211
210
|
def iroot2 # Newton's method version used in Ruby for Integer#sqrt
|
212
211
|
return nil if (n = self) < 0
|
213
212
|
return n if n < 2
|
214
213
|
b = n.bit_length
|
215
|
-
x = 1 << (b-1)/2 | n >> (b/2 + 1) # optimum initial root
|
214
|
+
x = 1 << (b-1)/2 | n >> (b/2 + 1) # optimum initial root estimat
|
216
215
|
while (t = n / x) < x; x = ((x + t) >> 1) end
|
217
216
|
x
|
218
217
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jabari Zakiya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: 'For val (real/complex) and root n: val.root(n,[1-n]) and val.roots(n,
|
42
|
-
[opt]); For Integer ival: ival.iroot2, and ival.
|
42
|
+
[opt]); For Integer ival: ival.iroot2, and ival.iroot(n) or ival.irootn(n); Roots.digits_to_show
|
43
43
|
to see/change number of digts to show'
|
44
44
|
email:
|
45
45
|
- jzakiya@gmail.com
|
@@ -50,7 +50,7 @@ files:
|
|
50
50
|
- lib/roots.rb
|
51
51
|
homepage: https://github.com/jzakiya/roots
|
52
52
|
licenses:
|
53
|
-
-
|
53
|
+
- GPL-2.0+
|
54
54
|
metadata: {}
|
55
55
|
post_install_message:
|
56
56
|
rdoc_options: []
|