<?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 Development Blog &#187; fmod</title>
	<atom:link href="http://gushh.net/blog/tag/fmod/feed/" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics and game development.</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:02:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Float Modulo in PureBasic</title>
		<link>http://gushh.net/blog/2009/08/27/float-modulo-in-purebasic/</link>
		<comments>http://gushh.net/blog/2009/08/27/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[<!-- AdSense Now! V1.95 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadin" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-2462949361920197";
/* 468x15, created 4/6/10 */
google_ad_slot = "8315313616";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><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>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/08/05/average-template/" rel="bookmark" class="crp_title">Average template</a></li><li><a href="http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/" rel="bookmark" class="crp_title">An efficient and simple object factory for PureBasic</a></li><li><a href="http://gushh.net/blog/2010/08/14/autocomplete-library/" rel="bookmark" class="crp_title">AutoComplete Library</a></li><li><a href="http://gushh.net/blog/2009/08/06/animation-lib/" rel="bookmark" class="crp_title">Animation lib</a></li><li><a href="http://gushh.net/blog/2007/09/10/have-you-heard-japan-trying-to-remake-the-internet/" rel="bookmark" class="crp_title">Have you heard? &#8211; Japan &#8220;trying&#8221; to remake the Internet&#8230;</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/08/27/float-modulo-in-purebasic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updated the vec3 lib, major overhaul.</title>
		<link>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/</link>
		<comments>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 10:37:31 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[coordinate]]></category>
		<category><![CDATA[cross product]]></category>
		<category><![CDATA[dot product]]></category>
		<category><![CDATA[endpoint]]></category>
		<category><![CDATA[fmod]]></category>
		<category><![CDATA[isometric]]></category>
		<category><![CDATA[lerp]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[quadratic curve]]></category>
		<category><![CDATA[transformation]]></category>
		<category><![CDATA[vec2]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector math]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=49</guid>
		<description><![CDATA[The VEC3 lib was updated today, I haven&#8217;t had time to put the newer versions as they were developed so I&#8217;m just uploading the latest version right now. A small change-log can be found at the header of the source. Same link as before: VEC3_MACRO.PBI Or you can download the package: VEC3_MACRO.ZIP New functionality as seen [...]]]></description>
			<content:encoded><![CDATA[<p>The VEC3 lib was updated today, I haven&#8217;t had time to put the newer versions as they were developed so I&#8217;m just uploading the latest version right now. A small change-log can be found at the header of the source.</p>
<p>Same link as before: <a href="http://gushh.net/dev/?file=pb/vec3_macro.pbi" target="_blank">VEC3_MACRO.PBI</a></p>
<p>Or you can download the package: <a href="http://gushh.net/dls/vec3_macro.zip" target="_blank">VEC3_MACRO.ZIP</a></p>
<p><a href="http://gushh.net/dls/vec3_macro.zip"><span id="more-49"></span><br />
</a></p>
<p>New functionality as seen on the change-log:</p>
<blockquote><p>24/01/2009: Added min, max. Fixed Lerp.</p>
<p>18/01/2009: Fixed structure, made FMOD compliant with VEC3_TYPE. Refactored FastSine() and PIWRAP().</p>
<p>12/01/2009: Optimized/Fixed the PIWRAP macro with FMOD. Added resolution switch For the quadratic curve.</p>
<p>11/01/2009: Added wrap, clamp, lerp, string. Fixed some bugs. Refactored the vec3 structure. Added approximation method for sine and cosine functions.</p>
<p>10/01/2009: Library created.</p></blockquote>
<p> </p>
<p>I think I got carried away a little, but it proves to be a useful library for quick prototyping (at least that&#8217;s what I use it for). I&#8217;ll write a few examples with a small drawing framework perhaps by next week if I have time for it. Some of the things that are left to do include angle and coordinate helpers, which also means isometric transformation for 3d points, projections, etc.</p>
<p>As it stands right now, you could prototype almost any type of game/application without having to code most of the trivial stuff (such as, the vector code, provided by the library!).</p>
<p>Cheers.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/" rel="bookmark" class="crp_title">VEC3 and EasyObject Libraries updated.</a></li><li><a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" rel="bookmark" class="crp_title">A fast vector library for purebasic.</a></li><li><a href="http://gushh.net/blog/2009/07/13/macro-templates-by-example/" rel="bookmark" class="crp_title">Macro Templates, by example.</a></li><li><a href="http://gushh.net/blog/2009/09/05/automatic-declare-tool/" rel="bookmark" class="crp_title">Declar&#8217;em! &#8211; Automatic declaration of procedures.</a></li><li><a href="http://gushh.net/blog/2009/06/13/randomize-array-a-flexible-hard-coded-macro/" rel="bookmark" class="crp_title">Randomize Array &#8211; A Flexible hard-coded macro</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
