math_root_find 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/math_root_find.rb +6 -3
- metadata +3 -3
data/lib/math_root_find.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module SuperMath
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
|
4
4
|
# optimized version of find_root, performs 10000 roots' calculations per sec on Core 2 Duo 2.67
|
5
5
|
def self.find_root(a, b, precision=0.01, allow_oob_roots=false, &blk)
|
@@ -8,8 +8,11 @@ module SuperMath
|
|
8
8
|
while true do
|
9
9
|
# puts "f(#{a},#{(a/precision).truncate})=#{fa}, f(#{b},#{(b/precision).truncate})=#{fb}"
|
10
10
|
raise "Looking for roots out of bounds" if !allow_oob_roots && sa == sb
|
11
|
-
|
12
|
-
return
|
11
|
+
|
12
|
+
return a if (a-b).abs < precision
|
13
|
+
# return a if (a-b).abs < precision || fa.abs <= precision
|
14
|
+
# return b if fb.abs <= precision
|
15
|
+
|
13
16
|
c = (a.to_f + b.to_f) / 2
|
14
17
|
fc = yield(c)
|
15
18
|
sc = fc >= 0 ? 1 : -1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math_root_find
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-11-10 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70278180862080 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70278180862080
|
26
26
|
description: Simple math extension that performs f(x)==0 equation numerical root calculation.
|
27
27
|
Takes a block as an equation and tries to call it the least amount of times.
|
28
28
|
email:
|