doc/api/ruby/classes/String.src/M000022.html in ruby-vpi-20.0.0 vs doc/api/ruby/classes/String.src/M000022.html in ruby-vpi-21.0.0
- old
+ new
@@ -3,16 +3,34 @@
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
- <title>to_ruby_const_name (String)</title>
+ <title>to_f (String)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
- <pre><span class="ruby-comment cmt"># File lib/ruby-vpi/util.rb, line 8</span>
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_ruby_const_name</span>
- <span class="ruby-keyword kw">self</span>[<span class="ruby-value">0</span>, <span class="ruby-value">1</span>].<span class="ruby-identifier">upcase</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">self</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
+ <pre><span class="ruby-comment cmt"># File lib/ruby-vpi/float.rb, line 9</span>
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_f</span> <span class="ruby-identifier">aRadix</span> = <span class="ruby-value">10</span>
+ <span class="ruby-identifier">whole</span>, <span class="ruby-identifier">frac</span> = <span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>, <span class="ruby-value">2</span>)
+ <span class="ruby-identifier">whole</span> = <span class="ruby-identifier">whole</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-identifier">aRadix</span>).<span class="ruby-identifier">to_f</span>
+
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">frac</span>
+ <span class="ruby-identifier">f</span> = <span class="ruby-value">0</span><span class="ruby-value">.0</span>
+
+ <span class="ruby-identifier">frac</span>.<span class="ruby-identifier">length</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
+ <span class="ruby-identifier">power</span> = <span class="ruby-identifier">i</span>.<span class="ruby-identifier">next</span>
+ <span class="ruby-identifier">weight</span> = <span class="ruby-identifier">aRadix</span> <span class="ruby-operator">**</span> <span class="ruby-operator">-</span><span class="ruby-identifier">power</span>
+ <span class="ruby-identifier">digit</span> = <span class="ruby-identifier">frac</span>[<span class="ruby-identifier">i</span>, <span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>(<span class="ruby-identifier">aRadix</span>)
+
+ <span class="ruby-identifier">f</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">digit</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">weight</span>
+ <span class="ruby-keyword kw">end</span>
+
+ <span class="ruby-identifier">f</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">f</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^-/</span>
+ <span class="ruby-identifier">whole</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">f</span>
+ <span class="ruby-keyword kw">end</span>
+
+ <span class="ruby-identifier">whole</span>
<span class="ruby-keyword kw">end</span></pre>
</body>
</html>
\ No newline at end of file