eymiha_math 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/gem_package.rb CHANGED
@@ -4,10 +4,10 @@ class GemPackage
4
4
 
5
5
  def initialize
6
6
  @name = 'eymiha_math'
7
- @version = '0.1.1'
7
+ @version = '1.0.0'
8
8
  @files = FileList[
9
9
  '*.rb',
10
- 'lib/*',
10
+ 'lib/**/*',
11
11
  'test/*',
12
12
  'html/**/*'
13
13
  ]
@@ -0,0 +1,324 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Numeric</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Numeric</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/eymiha/math/approximately_equals_rb.html">
59
+ lib/eymiha/math/approximately_equals.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/eymiha/math/fraction_rb.html">
63
+ lib/eymiha/math/fraction.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/eymiha/math/rectify_rb.html">
67
+ lib/eymiha/math/rectify.rb
68
+ </a>
69
+ <br />
70
+ </td>
71
+ </tr>
72
+
73
+ <tr class="top-aligned-row">
74
+ <td><strong>Parent:</strong></td>
75
+ <td>
76
+ Object
77
+ </td>
78
+ </tr>
79
+ </table>
80
+ </div>
81
+ <!-- banner header -->
82
+
83
+ <div id="bodyContent">
84
+
85
+
86
+
87
+ <div id="contextContent">
88
+
89
+ <div id="description">
90
+ <p>
91
+ Behavior added to <a href="Numeric.html">Numeric</a> by eymiha_math.
92
+ </p>
93
+
94
+ </div>
95
+
96
+
97
+ </div>
98
+
99
+ <div id="method-list">
100
+ <h3 class="section-bar">Methods</h3>
101
+
102
+ <div class="name-list">
103
+ <a href="#M000004">=~</a>&nbsp;&nbsp;
104
+ <a href="#M000003">approximately_equals?</a>&nbsp;&nbsp;
105
+ <a href="#M000010">at_least</a>&nbsp;&nbsp;
106
+ <a href="#M000009">at_most</a>&nbsp;&nbsp;
107
+ <a href="#M000008">cut_rectify</a>&nbsp;&nbsp;
108
+ <a href="#M000001">epsilon</a>&nbsp;&nbsp;
109
+ <a href="#M000002">epsilon=</a>&nbsp;&nbsp;
110
+ <a href="#M000006">round_to_nearest</a>&nbsp;&nbsp;
111
+ <a href="#M000005">with_fraction</a>&nbsp;&nbsp;
112
+ <a href="#M000007">wrap_rectify</a>&nbsp;&nbsp;
113
+ </div>
114
+ </div>
115
+
116
+ </div>
117
+
118
+
119
+ <!-- if includes -->
120
+
121
+ <div id="section">
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+ <!-- if method_list -->
131
+ <div id="methods">
132
+ <h3 class="section-bar">Public Class methods</h3>
133
+
134
+ <div id="method-M000001" class="method-detail">
135
+ <a name="M000001"></a>
136
+
137
+ <div class="method-heading">
138
+ <a href="Numeric.src/M000001.html" target="Code" class="method-signature"
139
+ onclick="popupCode('Numeric.src/M000001.html');return false;">
140
+ <span class="method-name">epsilon</span><span class="method-args">()</span>
141
+ </a>
142
+ </div>
143
+
144
+ <div class="method-description">
145
+ <p>
146
+ The default distance from a <a href="Numeric.html">Numeric</a> below which
147
+ it is considered to be approximately equal to a another <a
148
+ href="Numeric.html">Numeric</a>.
149
+ </p>
150
+ </div>
151
+ </div>
152
+
153
+ <div id="method-M000002" class="method-detail">
154
+ <a name="M000002"></a>
155
+
156
+ <div class="method-heading">
157
+ <a href="Numeric.src/M000002.html" target="Code" class="method-signature"
158
+ onclick="popupCode('Numeric.src/M000002.html');return false;">
159
+ <span class="method-name">epsilon=</span><span class="method-args">(epsilon)</span>
160
+ </a>
161
+ </div>
162
+
163
+ <div class="method-description">
164
+ <p>
165
+ Sets the default distance for approximately equals comparisons.
166
+ </p>
167
+ </div>
168
+ </div>
169
+
170
+ <h3 class="section-bar">Public Instance methods</h3>
171
+
172
+ <div id="method-M000004" class="method-detail">
173
+ <a name="M000004"></a>
174
+
175
+ <div class="method-heading">
176
+ <span class="method-name">=~</span><span class="method-args">(value,epsilon=@@epsilon)</span>
177
+ </div>
178
+
179
+ <div class="method-description">
180
+ <p>
181
+ Alias for approximately_equals?
182
+ </p>
183
+ </div>
184
+ </div>
185
+
186
+ <div id="method-M000003" class="method-detail">
187
+ <a name="M000003"></a>
188
+
189
+ <div class="method-heading">
190
+ <a href="Numeric.src/M000003.html" target="Code" class="method-signature"
191
+ onclick="popupCode('Numeric.src/M000003.html');return false;">
192
+ <span class="method-name">approximately_equals?</span><span class="method-args">(value,epsilon=@@epsilon)</span>
193
+ </a>
194
+ </div>
195
+
196
+ <div class="method-description">
197
+ <p>
198
+ returns true if the difference between the instance and the given <a
199
+ href="Numeric.html">Numeric</a> is less than the given distance.
200
+ </p>
201
+ </div>
202
+ </div>
203
+
204
+ <div id="method-M000010" class="method-detail">
205
+ <a name="M000010"></a>
206
+
207
+ <div class="method-heading">
208
+ <a href="Numeric.src/M000010.html" target="Code" class="method-signature"
209
+ onclick="popupCode('Numeric.src/M000010.html');return false;">
210
+ <span class="method-name">at_least</span><span class="method-args">(low=0)</span>
211
+ </a>
212
+ </div>
213
+
214
+ <div class="method-description">
215
+ <p>
216
+ Constrains a value to a lower limit.
217
+ </p>
218
+ </div>
219
+ </div>
220
+
221
+ <div id="method-M000009" class="method-detail">
222
+ <a name="M000009"></a>
223
+
224
+ <div class="method-heading">
225
+ <a href="Numeric.src/M000009.html" target="Code" class="method-signature"
226
+ onclick="popupCode('Numeric.src/M000009.html');return false;">
227
+ <span class="method-name">at_most</span><span class="method-args">(high=0)</span>
228
+ </a>
229
+ </div>
230
+
231
+ <div class="method-description">
232
+ <p>
233
+ Constrains a value to an upper limit.
234
+ </p>
235
+ </div>
236
+ </div>
237
+
238
+ <div id="method-M000008" class="method-detail">
239
+ <a name="M000008"></a>
240
+
241
+ <div class="method-heading">
242
+ <a href="Numeric.src/M000008.html" target="Code" class="method-signature"
243
+ onclick="popupCode('Numeric.src/M000008.html');return false;">
244
+ <span class="method-name">cut_rectify</span><span class="method-args">(high=1,low=0)</span>
245
+ </a>
246
+ </div>
247
+
248
+ <div class="method-description">
249
+ <p>
250
+ Treats the low and high as limits, returning low or high if the instance is
251
+ respectively below or above these values, or the instance if between the
252
+ two.
253
+ </p>
254
+ </div>
255
+ </div>
256
+
257
+ <div id="method-M000006" class="method-detail">
258
+ <a name="M000006"></a>
259
+
260
+ <div class="method-heading">
261
+ <a href="Numeric.src/M000006.html" target="Code" class="method-signature"
262
+ onclick="popupCode('Numeric.src/M000006.html');return false;">
263
+ <span class="method-name">round_to_nearest</span><span class="method-args">(denominator=1)</span>
264
+ </a>
265
+ </div>
266
+
267
+ <div class="method-description">
268
+ <p>
269
+ Returns a numeric value such that any remainder is evenly divided by the
270
+ given denominator.
271
+ </p>
272
+ </div>
273
+ </div>
274
+
275
+ <div id="method-M000005" class="method-detail">
276
+ <a name="M000005"></a>
277
+
278
+ <div class="method-heading">
279
+ <a href="Numeric.src/M000005.html" target="Code" class="method-signature"
280
+ onclick="popupCode('Numeric.src/M000005.html');return false;">
281
+ <span class="method-name">with_fraction</span><span class="method-args">(denominator=1,separator='-',show_zero=false)</span>
282
+ </a>
283
+ </div>
284
+
285
+ <div class="method-description">
286
+ <p>
287
+ Renders a numeric value as a whole number and a fraction with a given
288
+ denominator, separated with a given separator, and optionally showing
289
+ fractions with a numerator of zero.
290
+ </p>
291
+ </div>
292
+ </div>
293
+
294
+ <div id="method-M000007" class="method-detail">
295
+ <a name="M000007"></a>
296
+
297
+ <div class="method-heading">
298
+ <a href="Numeric.src/M000007.html" target="Code" class="method-signature"
299
+ onclick="popupCode('Numeric.src/M000007.html');return false;">
300
+ <span class="method-name">wrap_rectify</span><span class="method-args">(high=1,low=0)</span>
301
+ </a>
302
+ </div>
303
+
304
+ <div class="method-description">
305
+ <p>
306
+ Treats the interval between low and high as a cycle, returning the result
307
+ of wrapping the instance around this interval.
308
+ </p>
309
+ </div>
310
+ </div>
311
+
312
+
313
+ </div>
314
+
315
+
316
+ </div>
317
+
318
+
319
+ <div id="validator-badges">
320
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
321
+ </div>
322
+
323
+ </body>
324
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>epsilon (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/approximately_equals.rb, line 21</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Numeric</span>.<span class="ruby-identifier">epsilon</span>
15
+ <span class="ruby-ivar">@@epsilon</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>epsilon= (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/approximately_equals.rb, line 26</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Numeric</span>.<span class="ruby-identifier">epsilon=</span>(<span class="ruby-identifier">epsilon</span>)
15
+ <span class="ruby-ivar">@@epsilon</span> = <span class="ruby-identifier">epsilon</span>.<span class="ruby-identifier">abs</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>approximately_equals? (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/approximately_equals.rb, line 32</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">approximately_equals?</span>(<span class="ruby-identifier">value</span>,<span class="ruby-identifier">epsilon</span>=<span class="ruby-ivar">@@epsilon</span>)
15
+ (<span class="ruby-keyword kw">self</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">value</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">epsilon</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>with_fraction (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/fraction.rb, line 16</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_fraction</span>(<span class="ruby-identifier">denominator</span>=<span class="ruby-value">1</span>,<span class="ruby-identifier">separator</span>=<span class="ruby-value str">'-'</span>,<span class="ruby-identifier">show_zero</span>=<span class="ruby-keyword kw">false</span>)
15
+ <span class="ruby-identifier">sign</span> = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">0</span>
16
+ <span class="ruby-identifier">unsigned</span> = <span class="ruby-keyword kw">self</span><span class="ruby-operator">*</span><span class="ruby-identifier">sign</span>
17
+ <span class="ruby-identifier">whole</span> = (((<span class="ruby-identifier">unsigned</span><span class="ruby-operator">*</span><span class="ruby-identifier">denominator</span>).<span class="ruby-identifier">round</span>)<span class="ruby-operator">/</span><span class="ruby-identifier">denominator</span>).<span class="ruby-identifier">floor</span>
18
+ <span class="ruby-identifier">numerator</span> = ((<span class="ruby-identifier">unsigned</span><span class="ruby-operator">-</span><span class="ruby-identifier">whole</span>)<span class="ruby-operator">*</span><span class="ruby-identifier">denominator</span>).<span class="ruby-identifier">round</span>
19
+ <span class="ruby-node">&quot;#{sign*whole}#{(numerator != 0)||show_zero ?
20
+ &quot;#{separator}#{numerator}/#{denominator}&quot; : &quot;&quot;}&quot;</span>
21
+ <span class="ruby-keyword kw">end</span></pre>
22
+ </body>
23
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>round_to_nearest (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/fraction.rb, line 27</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">round_to_nearest</span>(<span class="ruby-identifier">denominator</span>=<span class="ruby-value">1</span>)
15
+ ((<span class="ruby-keyword kw">self</span><span class="ruby-operator">*</span><span class="ruby-identifier">denominator</span>).<span class="ruby-identifier">round</span>)<span class="ruby-operator">/</span>(<span class="ruby-value">1.0</span><span class="ruby-operator">*</span><span class="ruby-identifier">denominator</span>)
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>wrap_rectify (Numeric)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/eymiha/math/rectify.rb, line 18</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wrap_rectify</span>(<span class="ruby-identifier">high</span>=<span class="ruby-value">1</span>,<span class="ruby-identifier">low</span>=<span class="ruby-value">0</span>)
15
+ <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">high</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">low</span>)
16
+ <span class="ruby-identifier">low</span>,<span class="ruby-identifier">high</span> = <span class="ruby-identifier">high</span>,<span class="ruby-identifier">low</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">low</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">high</span>
17
+ <span class="ruby-identifier">diff</span> = <span class="ruby-identifier">high</span><span class="ruby-operator">-</span><span class="ruby-identifier">low</span>
18
+ <span class="ruby-keyword kw">self</span><span class="ruby-operator">-</span><span class="ruby-identifier">diff</span><span class="ruby-operator">*</span>((<span class="ruby-keyword kw">self</span><span class="ruby-operator">-</span><span class="ruby-identifier">low</span>)<span class="ruby-operator">/</span><span class="ruby-identifier">diff</span>).<span class="ruby-identifier">floor</span>
19
+ <span class="ruby-keyword kw">else</span>
20
+ <span class="ruby-identifier">low</span>
21
+ <span class="ruby-keyword kw">end</span>
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>