<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GuShH&#039;s DevBlog &#187; fprem</title>
	<atom:link href="http://gushh.net/blog/?tag=fprem&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Float Modulo in PureBasic</title>
		<link>http://gushh.net/blog/float-modulo-in-purebasic/</link>
		<comments>http://gushh.net/blog/float-modulo-in-purebasic/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 09:17:51 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[basic operators]]></category>
		<category><![CDATA[float modulo]]></category>
		<category><![CDATA[fmod]]></category>
		<category><![CDATA[fprem]]></category>
		<category><![CDATA[fprem1]]></category>
		<category><![CDATA[fstsw]]></category>
		<category><![CDATA[ia32]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[modulo operator]]></category>
		<category><![CDATA[pb float modulo]]></category>
		<category><![CDATA[pb modulo]]></category>
		<category><![CDATA[pb operators]]></category>
		<category><![CDATA[purebasic]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=48</guid>
		<description><![CDATA[I keep forgetting the fact that PB is retarded when it comes to the modulo operator and floating point values!. It&#8217;s time to write our own fmod() equivalent; lucky for us the Intel guys were kind enough as to implement quite a useful instruction called FPREM a few eons ago, which pretty much means &#8220;Partial [...]]]></description>
			<content:encoded><![CDATA[<p>I keep forgetting the fact that PB is retarded when it comes to the modulo operator and floating point values!.</p>
<p>It&#8217;s time to write our own fmod() equivalent; lucky for us the Intel guys were kind enough as to implement quite a useful instruction called FPREM a few eons ago, which pretty much means &#8220;Partial REMinder&#8221; and what it does is rather simple: it computes the partial remainder of st(0)/st(1).</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.f fmod<span style="color: #000066;">&#40;</span> x.f, y.f <span style="color: #000066;">&#41;</span>
  <span style="color: #000066; font-weight: bold;">EnableASM</span>
	  <span style="color: #000fff;">FLD</span> DWORD<span style="color: #000066;">&#91;</span>p.v_y<span style="color: #000066;">&#93;</span>
	  <span style="color: #000fff;">FLD</span> DWORD<span style="color: #000066;">&#91;</span>p.v_x<span style="color: #000066;">&#93;</span>
	  <span style="color: #000066;">!</span>NOT_READY:
		  <span style="color: #000fff;">FPREM</span>
		  <span style="color: #000fff;">FSTSW</span> AX
		  <span style="color: #000fff;">TEST</span> AH, 100b
	  <span style="color: #000066;">!</span><span style="color: #000fff;">JNZ</span> NOT_READY
	  FSTP ST1
  <span style="color: #000066; font-weight: bold;">DisableASM</span>
  <span style="color: #000066; font-weight: bold;">ProcedureReturn</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Of course with great instructions comes great limitations: in this case we cannot produce the final reminder if the difference between X and Y is bigger than 63. We can solve this by implementing a loop and checking for the C2 bit of the status word to be cleared. This is all explained in the IA32 manuals.</p>
<p>It&#8217;s not pretty but until fpu modulo operations are officially supported in the language, this might well be your only sane choice.</p>
<g:plusone href='http://gushh.net/blog/float-modulo-in-purebasic/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/float-modulo-in-purebasic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-09 06:48:11 by W3 Total Cache -->
