eymiha_math 0.1.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.
- data/gem_package.rb +31 -0
- data/lib/approximately_equals.rb +31 -0
- data/lib/eymiha_math.rb +5 -0
- data/lib/rectify.rb +33 -0
- data/rakefile.rb +2 -0
- data/test/tc_approximately_equals.rb +15 -0
- data/test/tc_rectify.rb +29 -0
- metadata +52 -0
data/gem_package.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class GemPackage
|
2
|
+
|
3
|
+
attr_reader :name, :version, :files
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@name = 'eymiha_math'
|
7
|
+
@version = '0.1.0'
|
8
|
+
@files = FileList[
|
9
|
+
'*.rb',
|
10
|
+
'lib/*',
|
11
|
+
'test/*',
|
12
|
+
'html/**/*'
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def fill_spec(s)
|
17
|
+
s.name = name
|
18
|
+
s.version = version
|
19
|
+
s.summary = "Eymiha basic math extensions"
|
20
|
+
s.files = files.to_a
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.autorequire = name
|
23
|
+
s.has_rdoc = true
|
24
|
+
s.rdoc_options << "--all"
|
25
|
+
s.author = "Dave Anderson"
|
26
|
+
s.email = "dave@eymiha.com"
|
27
|
+
s.homepage = "http://www.eymiha.com"
|
28
|
+
s.rubyforge_project = "cori"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Approminately equals returns true when values are close enough, within some
|
2
|
+
# distance epsilon above or below the given value.
|
3
|
+
|
4
|
+
# Adds the approximately equals operation to Numeric and its progeny.
|
5
|
+
class Numeric
|
6
|
+
|
7
|
+
# The initial default distance from a Numeric below which it is considered
|
8
|
+
# to be approximately equal to a another Numeric.
|
9
|
+
@@epsilon = 0.0000000001
|
10
|
+
|
11
|
+
# The default distance from a Numeric below which it is considered to be
|
12
|
+
# approximately equal to a another Numeric.
|
13
|
+
def Numeric.epsilon
|
14
|
+
@@epsilon
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sets the default distance for approximately equals comparisons.
|
18
|
+
def Numeric.epsilon=(epsilon)
|
19
|
+
@@epsilon = epsilon.abs
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns true if the difference between the instance and the given Numeric
|
23
|
+
# is less than the given distance.
|
24
|
+
def approximately_equals?(value,epsilon=@@epsilon)
|
25
|
+
(self - value).abs < epsilon
|
26
|
+
end
|
27
|
+
|
28
|
+
alias =~ approximately_equals?
|
29
|
+
|
30
|
+
end
|
31
|
+
|
data/lib/eymiha_math.rb
ADDED
data/lib/rectify.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Rectification maps values to an interval treated either as a cycle or a
|
2
|
+
# cutoff.
|
3
|
+
|
4
|
+
# Adds recticiation to Numerics and their progeny
|
5
|
+
class Numeric
|
6
|
+
|
7
|
+
# Treats the interval between low and high as a cycle, returning the result
|
8
|
+
# of wrapping the instance around this interval.
|
9
|
+
def wrap_rectify(high=1,low=0)
|
10
|
+
if (high != low)
|
11
|
+
low,high = high,low if low > high
|
12
|
+
diff = high-low
|
13
|
+
self-diff*((self-low)/diff).floor
|
14
|
+
else
|
15
|
+
low
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Treats the low and high as limits, returning low or high if the instance
|
20
|
+
# is respectively below or above these values, or the instance if between
|
21
|
+
# the two.
|
22
|
+
def cut_rectify(high=1,low=0)
|
23
|
+
low,high = high,low if low > high
|
24
|
+
if (self < low)
|
25
|
+
low
|
26
|
+
elsif (self > high)
|
27
|
+
high
|
28
|
+
else
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'approximately_equals'
|
4
|
+
|
5
|
+
class TC_approximately_equals < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_approximately_equals
|
8
|
+
assert(!(1 =~ 1.001))
|
9
|
+
assert(1 =~ 1.000000000000001)
|
10
|
+
assert(1.approximately_equals?(1.001,0.01))
|
11
|
+
Numeric.epsilon = 0.01
|
12
|
+
assert(1 =~ 1.001)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/tc_rectify.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'rectify'
|
4
|
+
|
5
|
+
class TC_rectify < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_wrap_rectify
|
8
|
+
assert(0.5.wrap_rectify(1) == 0.5)
|
9
|
+
assert(5.5.wrap_rectify(1) =~ 0.5)
|
10
|
+
assert(-7.25.wrap_rectify(2) =~ 0.75)
|
11
|
+
assert(-7.25.wrap_rectify(2,0.5) =~ 1.75)
|
12
|
+
assert(-7.25.wrap_rectify(0.5,2) =~ 1.75)
|
13
|
+
assert(2.wrap_rectify(0.5,2) == 0.5)
|
14
|
+
assert(0.5.wrap_rectify(0.5,2) == 0.5)
|
15
|
+
assert(0.5.wrap_rectify(0,0) == 0)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_cut_rectify
|
19
|
+
assert(0.5.cut_rectify(1) == 0.5)
|
20
|
+
assert(5.5.cut_rectify(1) == 1)
|
21
|
+
assert(-7.25.cut_rectify(2) == 0)
|
22
|
+
assert(-7.25.cut_rectify(2,0.5) == 0.5)
|
23
|
+
assert(-7.25.cut_rectify(0.5,2) == 0.5)
|
24
|
+
assert(2.cut_rectify(0.5,2) == 2)
|
25
|
+
assert(0.5.cut_rectify(0.5,2) == 0.5)
|
26
|
+
assert(0.5.cut_rectify(0,0) == 0)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: eymiha_math
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-05-10 00:00:00 -04:00
|
8
|
+
summary: Eymiha basic math extensions
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: dave@eymiha.com
|
12
|
+
homepage: http://www.eymiha.com
|
13
|
+
rubyforge_project: cori
|
14
|
+
description:
|
15
|
+
autorequire: eymiha_math
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Dave Anderson
|
31
|
+
files:
|
32
|
+
- gem_package.rb
|
33
|
+
- rakefile.rb
|
34
|
+
- lib/approximately_equals.rb
|
35
|
+
- lib/eymiha_math.rb
|
36
|
+
- lib/rectify.rb
|
37
|
+
- test/tc_approximately_equals.rb
|
38
|
+
- test/tc_rectify.rb
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options:
|
42
|
+
- --all
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies: []
|
52
|
+
|