<?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>fast inverse square root | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/fast-inverse-square-root/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 05 Nov 2020 09:10:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>fast inverse square root | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>So what do you think this code does?</title>
		<link>https://learncgames.com/so-what-do-you-think-this-code-does/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=so-what-do-you-think-this-code-does</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 05 Nov 2020 00:00:24 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[fast inverse square root]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1721</guid>

					<description><![CDATA[<p>Here&#8217;s a little C function. It&#8217;s not exactly intuitive what it does and I&#8217;ve renamed it to prevent giving it away. float mystery( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &#38;y; i = [&#8230;]</p>
The post <a href="https://learncgames.com/so-what-do-you-think-this-code-does/">So what do you think this code does?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:406,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/pixapopz-2873171\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:407,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:31&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 22:35:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-22 16:29:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-03 12:55:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 12:22:23&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 09:32:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-20 15:40:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-27 21:41:50&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 18:25:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-09 05:44:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 13:17:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 22:45:05&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 22:45:05&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:408,&quot;href&quot;:&quot;https:\/\/www.beyond3d.com\/content\/articles\/8&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251230093552\/https:\/\/www.beyond3d.com\/content\/articles\/8\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 14:43:34&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-22 16:29:26&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 11:04:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-03 12:55:49&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-09 12:22:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 09:33:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 15:41:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:42:21&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 18:25:17&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-04-09 05:44:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-13 13:17:40&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-18 18:06:51&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-18 18:06:51&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1722" aria-describedby="caption-attachment-1722" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-1722" src="https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640-300x168.jpg" alt="Math(s) symbols" width="300" height="168" srcset="https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640-300x168.jpg 300w, https://learncgames.com/wp-content/uploads/2020/11/math-1500720_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1722" class="wp-caption-text">Image by <a href="https://pixabay.com/users/pixapopz-2873171/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720">Chuk Yong</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1500720">Pixabay</a></figcaption></figure>
<p>Here&#8217;s a little C function. It&#8217;s not exactly intuitive what it does and I&#8217;ve renamed it to prevent giving it away.</p>
<pre><code class="language-c" data-line="">  float mystery( float number )
  {
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &amp;y;                       
    i  = 0x5f3759df - ( i &gt;&gt; 1 );               
    y  = * ( float * ) &amp;i;
    y  = y * ( threehalfs - ( x2 * y * y ) );   
    return y;
  }</code></pre>
<p>If it helps, this line is really the heart of it.</p>
<pre><code class="language-c" data-line="">    i  = 0x5f3759df - ( i &gt;&gt; 1 );  </code></pre>
<p>Mystified? Well it&#8217;s a fast inverse square root. No one really knows who wrote it though John Carnack of Quake and Doom fame popularised it. There&#8217;s an <a title="Link to discussion abouty the author of the fast inverse square root" href="https://www.beyond3d.com/content/articles/8/" target="_blank" rel="nofollow noopener noreferrer">interesting discussion about the author</a> but no one really knows.</p>
<p>There&#8217;s less need for this type of thing nowadays because of all the fast silicon but back 20-25 years ago when graphics processors were in their very infancy, it was a highly useful optimization. Mind you , you&#8217;d need to know assembly language inside out to come up with stuff like this.</p>The post <a href="https://learncgames.com/so-what-do-you-think-this-code-does/">So what do you think this code does?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1721</post-id>	</item>
	</channel>
</rss>
