<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://dirkmittler.homeip.net/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DirkMittler</id>
	<title>Dirks Personal WiKi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://dirkmittler.homeip.net/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=DirkMittler"/>
	<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php/Special:Contributions/DirkMittler"/>
	<updated>2026-04-26T21:42:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.13</generator>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=199</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=199"/>
		<updated>2024-09-22T10:46:34Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Conclusion.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrofluoric_acid|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A type of conclusion which can be drawn is, that specifically in the case of Hydrogen Fluoride, the buffer solution's main purpose is to reduce the acidity, and thus to reduce the rate at which the solution etches, below the rate at which an uncontrolled acid would etch, and on the basic side of neutrality for water. This has clear applications in, say, IC manufacture.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=198</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=198"/>
		<updated>2024-09-22T10:18:26Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrofluoric_acid|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=197</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=197"/>
		<updated>2024-09-22T10:11:51Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrofluoric_acid|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=196</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=196"/>
		<updated>2024-09-22T10:00:24Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrofluoric_acid|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=195</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=195"/>
		<updated>2024-09-22T09:59:08Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Changed reference.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrofluoric_acid|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.17&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=194</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=194"/>
		<updated>2024-09-22T09:56:36Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Added wiki reference.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. [[wikipedia:Hydrogen_fluoride|Some sources]] have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=193</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=193"/>
		<updated>2024-09-22T09:52:54Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Added to category.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Chemistry]]&lt;br /&gt;
&lt;br /&gt;
The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Category:Chemistry&amp;diff=192</id>
		<title>Category:Chemistry</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Category:Chemistry&amp;diff=192"/>
		<updated>2024-09-22T09:51:24Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Created page with &amp;quot;Some musings on Chemistry.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Some musings on Chemistry.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=190</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=190"/>
		<updated>2024-09-22T09:47:31Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Fixed multiline math typesetting (as list).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=189</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=189"/>
		<updated>2024-09-22T09:45:57Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1} \\&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=188</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=188"/>
		<updated>2024-09-22T09:44:50Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1} \\&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=187</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=187"/>
		<updated>2024-09-22T09:41:24Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11} \\&lt;br /&gt;
\left[H^{+}\right]=10^{-5} \\&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L \\&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1} \\&lt;br /&gt;
=6.6\cdot10^{-5} \\&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=186</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=186"/>
		<updated>2024-09-22T09:40:12Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
\newline&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
\newline&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
\newline&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
\newline&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=185</id>
		<title>Hydrogen Fluoride Buffer Solutions</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Hydrogen_Fluoride_Buffer_Solutions&amp;diff=185"/>
		<updated>2024-09-22T09:35:36Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Page created. HF Buffer Solutions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The subject of Dynamics And Equilibria is more complex than this, and a complete treatment of that subject will not be attempted here.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;complete&amp;quot; equilibrium constant which honestly describes the state of an HF buffer solution, derives from the chemical reaction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;HF\rightleftharpoons F^{1-}+H^{+}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And takes the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Where the square brackets denote the concentration of the particles enclosed. But, a quantity which is more frequently stated is, the ratio:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{a}=\frac{\left[F^{1-}\right]}{\left[HF\right]}&amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
Which is exact when the solution is neutral, and when the pH of water is (7). Thus, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; is exact when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;. Some sources have stated &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)=6.6\cdot10^{-4}&amp;lt;/math&amp;gt;, which means that its potency logarithm, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{a}\right)=3.18&amp;lt;/math&amp;gt;. But what some sources may state is, that it's difficult to measure &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)&amp;lt;/math&amp;gt; directly, because as soon as one has added some amount of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; to the solution, the solution becomes acidic, and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;gt;10^{-7}&amp;lt;/math&amp;gt;. If we were to assume that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{a}\right)==6.6\cdot10^{-4}&amp;lt;/math&amp;gt; when &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-7}&amp;lt;/math&amp;gt;, then it will also follow that...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;K_{c}=K_{a}\cdot10^{-7}=6.6\cdot10^{-11}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(pK_{c}\right)&amp;lt;/math&amp;gt; Or &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt; can be used to describe the general behavior of the buffer solution. Thus, if it's desired that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]=10^{-4}&amp;lt;/math&amp;gt;, then this value can just be plugged in to the equation for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and the ratio between &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; defined. The problem which then remains in preparing the buffer solution is, that neither &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; nor &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; will equal the amount of the compounds &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(NaF\right)&amp;lt;/math&amp;gt; and, say, &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; that were initially added. The increase of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; above &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-7}\right)&amp;lt;/math&amp;gt; may consume some &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(HF\right)&amp;lt;/math&amp;gt; and add to the final concentration of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(F^{1-}\right)&amp;lt;/math&amp;gt;. In that case, what the lab technicians may do is:&lt;br /&gt;
&lt;br /&gt;
* Rely on the effectiveness of the buffer solution to compensate. Or,&lt;br /&gt;
* Assume that acid has been added by itself, restate &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; as a more complex expression which depends on the known amount of that, minus &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, pretend that &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; and &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; are equal as the numerator of &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(K_{c}\right)&amp;lt;/math&amp;gt;, and solve the quadratic to determine &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;. Or,&lt;br /&gt;
* Subtract &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; from &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt; in order to determine how much conjugate base must be added to the solution. In this case, adding a negative amount of base isn't possible.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is close to its neutral value, their initial difference may be neglected as part of an approximation (but the buffer solution still offer increased resistance to fatigue as the acid gets used).&lt;br /&gt;
&lt;br /&gt;
Also, it can be explained that if &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; is to be maximized, say, in order to improve its glass-etching performance, then actually adding a strong acid will be helpful, as doing so increases &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt;, thereby elevating &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; with respect to &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[F^{1-}\right]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The example below is a scratch sheet, for formulating a buffer solution, where it's allowable for &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[HF\right]&amp;lt;/math&amp;gt; actually to be &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10\;mol\:/L\right)&amp;lt;/math&amp;gt;, and where the target &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left[H^{+}\right]&amp;lt;/math&amp;gt; is more realistically &amp;lt;math display=&amp;quot;inline&amp;quot;&amp;gt;\left(10^{-5}\right)&amp;lt;/math&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&amp;quot;block&amp;quot;&amp;gt;&lt;br /&gt;
K_{c}=\frac{\left[F^{1-}\right]\left[H^{+}\right]}{\left[HF\right]}=6.6\cdot10^{-11}&lt;br /&gt;
\left[H^{+}\right]=10^{-5}&lt;br /&gt;
\left[HF\right]=1.0\cdot10^{+1}\;mol\:/L&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}=\frac{6.6\cdot10^{-11}}{10^{-5}}\cdot10^{+1}&lt;br /&gt;
=6.6\cdot10^{-5}&lt;br /&gt;
\frac{\left[F^{1-}\right]}{mol\:/L}-\left[H^{+}\right]=5.6\cdot10^{-5}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=184</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=184"/>
		<updated>2024-09-04T19:09:48Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. But, what's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, the first two methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.0625) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.0625) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.0625) ~= 4&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it (that would normally just belong to the fractional part), and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=183</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=183"/>
		<updated>2024-09-04T17:33:43Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Undo revision 182 by DirkMittler (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. But, what's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, the first two methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it (that would normally just belong to the fractional part), and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=182</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=182"/>
		<updated>2024-09-04T17:32:40Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. But, what's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;e^{\left(C-\frac{1}{2}\ln\left|x\right|\right)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, the first two methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it (that would normally just belong to the fractional part), and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=181</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=181"/>
		<updated>2024-09-04T17:23:50Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. But, what's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, the first two methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it (that would normally just belong to the fractional part), and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=180</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=180"/>
		<updated>2024-09-04T17:17:53Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: This should be a good conclusion for the time being.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. But, what's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, the first two methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it (that would normally just belong to the fractional part), and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
In fact, one good thing to do ''might be'', just to negate the most significant bit of the fractional part, as belonging to the integer type-pun, just because the fractional part no longer has anything to do with the exponent.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=179</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=179"/>
		<updated>2024-09-04T17:07:26Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)=-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=178</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=178"/>
		<updated>2024-09-04T15:41:46Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=177</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=177"/>
		<updated>2024-09-04T15:37:47Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the first two code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{(n-1)}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=176</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=176"/>
		<updated>2024-09-04T15:32:56Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) exponent bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{n}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=175</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=175"/>
		<updated>2024-09-04T15:31:34Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
* [[#Eq 5|Eq 5]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;2^{n}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|5}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=174</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=174"/>
		<updated>2024-09-04T15:26:03Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;2^{n}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The Constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=173</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=173"/>
		<updated>2024-09-04T15:25:25Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;2^{n}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=172</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=172"/>
		<updated>2024-09-04T15:18:10Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: The magic revealed.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because serious code still requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\exp\left(C-\frac{1}{2}\ln\left(x\right)\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
One reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
What can be observed about IEEE 754 double-precision floating-point numbers is, that their MSB will be (0) for non-negative numbers, and that the following (n) bits will generally have the pattern of...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;2^{n}-1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as the floating-point number itself is less than (+2.0), but greater than or equal to (+1.0). Therefore, in such cases, the first digit of their hexadecimal representation should only be (0x3).&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Some Insight Into The constant ==&lt;br /&gt;
&lt;br /&gt;
There is a truth in the observation that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
( Rsqrt(1.0) == 1.0 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That would seem to suggest, that virtually any magic number will suffice, just from type-punning double(1.0), and adding the result to itself, right-shifted by one bit. Thus, what can also be done, is that the following code can test the premise:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*	This will be an attempt to test, whether the constant&lt;br /&gt;
 * 0x5FE6EB50C7B537A9&lt;br /&gt;
 * can be replaced by a simpler version of itself, to be&lt;br /&gt;
 * computed as follows...&lt;br /&gt;
 * &lt;br /&gt;
 *  -Dirk Mittler&lt;br /&gt;
 * September 4, 2024&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
using std::setprecision;&lt;br /&gt;
&lt;br /&gt;
using std::hex;&lt;br /&gt;
using std::dec;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
uint64_t magic_number = 0x5FE6EB50C7B537A9;&lt;br /&gt;
&lt;br /&gt;
uint64_t Create_Constant() {&lt;br /&gt;
	float64_t f1 = 1.0;&lt;br /&gt;
	uint64_t *t1 = (uint64_t *) &amp;amp;f1;&lt;br /&gt;
	return *t1 + (*t1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = magic_number - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	cout &amp;lt;&amp;lt; setprecision(15);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The suggested magic number is: &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(0.01) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	magic_number = Create_Constant();&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;The auto-generated magic number is : &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; hex &amp;lt;&amp;lt; magic_number &amp;lt;&amp;lt; dec &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using that number, rsqrt(1.0) ~= &amp;quot; &amp;lt;&amp;lt; Q_rsqrt(1.0) &amp;lt;&amp;lt; endl;&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Using the same number, rsqrt(0.01) ~= &amp;quot;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; Q_rsqrt(0.01) &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And indeed, what this generates as output is...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
The suggested magic number is: 5fe6eb50c7b537a9&lt;br /&gt;
Using that number, rsqrt(0.01) ~= 10.3396006783211&lt;br /&gt;
The auto-generated magic number is : 5fe8000000000000&lt;br /&gt;
Using that number, rsqrt(1.0) ~= 1&lt;br /&gt;
Using the same number, rsqrt(0.01) ~= 10.88&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, what I could do now is, to suggest a magic number which is based on '0x5fe8000000000000', to add (or otherwise modify) some obscure series of less-significant bits within it, and then seem to have created something mysterious.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=171</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=171"/>
		<updated>2024-09-02T20:18:31Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki...'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to [[User:DirkMittler|Dirk]] (the owner of this Web-site).&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
: [[First_Page|The Site's First Presentable WiKi Page]]&lt;br /&gt;
&lt;br /&gt;
The first page on this site started as an addendum to the Getting Started page that the MediaWiKi software shipped with. Now that that page is fleshed out, it has also been converted into a standalone page.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=User:DirkMittler&amp;diff=170</id>
		<title>User:DirkMittler</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=User:DirkMittler&amp;diff=170"/>
		<updated>2024-09-02T19:54:25Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm a computer hobbyist who created this MediaWiKi Instance on August 29, 2024, mainly to experiment with and gain knowledge about how WiKi's generally work. For that reason, there was not meant to be much factual information in this MediaWiKi.&lt;br /&gt;
&lt;br /&gt;
Also, I'm challenged in that my writing style is not very encyclopedic. I usually write small fragments of information, which, if put together, can describe a broader topic. But what I have found to my great reassurance is, that if I edit an article in-place numerous times, I can transform its initial version into one which is more concise.&lt;br /&gt;
&lt;br /&gt;
Also, this platform may actually lead to meaningful information being posted on my site in the future, who knows.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=User:DirkMittler&amp;diff=169</id>
		<title>User:DirkMittler</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=User:DirkMittler&amp;diff=169"/>
		<updated>2024-09-02T19:42:44Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Created page with &amp;quot;I'm a computer hobbyist who created this MediaWiKi Instance recently, mainly to experiment with and gain knowledge about how WiKi's generally work. For that reason, there is n...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm a computer hobbyist who created this MediaWiKi Instance recently, mainly to experiment with and gain knowledge about how WiKi's generally work. For that reason, there is not meant to be much factual information in this MediaWiKi.&lt;br /&gt;
&lt;br /&gt;
Also, I'm challenged in that my writing style is not very encyclopedic. I usually write small fragments of information, which, if put together, can describe a broader topic. But what I have found to my great reassurance is, that if I edit an article in-place numerous times, I can transform its initial version into one which is more concise.&lt;br /&gt;
&lt;br /&gt;
Also, this platform may actually lead to meaningful information being posted on my site in the future, who knows.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=168</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=168"/>
		<updated>2024-09-02T09:23:38Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Undo revision 167 by DirkMittler (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=167</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=167"/>
		<updated>2024-09-02T09:23:08Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
: ([[Category:Programming|Programming]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Category:Programming&amp;diff=166</id>
		<title>Category:Programming</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Category:Programming&amp;diff=166"/>
		<updated>2024-09-02T07:42:43Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Category created.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Programming pages could be in the languages C++, Python, or Java.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=165</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=165"/>
		<updated>2024-09-02T07:38:09Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Put in category.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=164</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=164"/>
		<updated>2024-09-02T07:04:01Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Split off serious part.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki...'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
: [[First_Page|The Site's First Presentable WiKi Page]]&lt;br /&gt;
&lt;br /&gt;
The first page on this site started as an addendum to the Getting Started page that the MediaWiKi software shipped with. Now that that page is fleshed out, it has also been converted into a standalone page.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=163</id>
		<title>First Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=First_Page&amp;diff=163"/>
		<updated>2024-09-02T06:59:54Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: First presentable page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=162</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=162"/>
		<updated>2024-09-02T05:52:59Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Regenerate sitemap.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki...'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=160</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=160"/>
		<updated>2024-09-01T22:01:17Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Try to generate sitemap.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=159</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=159"/>
		<updated>2024-09-01T21:57:12Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Try to generate sitemap.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki'''...&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=File:Dirk-fract-3.jpg&amp;diff=158</id>
		<title>File:Dirk-fract-3.jpg</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=File:Dirk-fract-3.jpg&amp;diff=158"/>
		<updated>2024-09-01T21:56:00Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: This is a picture of the site owner, that has been compressed with fractal compression (as a WFA File) and then converted back into Jpeg format. The parameters with which WFA Files are usually generated, try to achieve accuracy. But here, the parameters were changed, in order to emphasize the fractal nature of WFA Files.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
This is a picture of the site owner, that has been compressed with fractal compression (as a WFA File) and then converted back into Jpeg format. The parameters with which WFA Files are usually generated, try to achieve accuracy. But here, the parameters were changed, in order to emphasize the fractal nature of WFA Files.&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=157</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=157"/>
		<updated>2024-09-01T13:56:57Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
Another reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, based on unspecified principles.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=155</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=155"/>
		<updated>2024-09-01T13:44:11Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Recognize normal-mapping under OpenGL.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
The only other reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, that make unknown assumptions.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
Although Quake III was surely programmed using some version of DirectX, the practice of normal-mapping is also standard with OpenGL.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=154</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=154"/>
		<updated>2024-09-01T13:39:33Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on GNU-C++17 compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article should work.&lt;br /&gt;
&lt;br /&gt;
The only other reason why devs might deprecate it at some point in the future, could have to do with forms of optimization which the compilers will carry out, that make unknown assumptions.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=153</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=153"/>
		<updated>2024-09-01T13:34:50Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on C++2017 -based compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article will work.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=152</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=152"/>
		<updated>2024-09-01T13:34:02Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: Replace remaining equation labels with templates.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
{{equation|2}}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
{{equation|3}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on C++2017 -based compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article will work.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
{{equation|4}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=151</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=151"/>
		<updated>2024-09-01T13:31:51Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
{{equation|1}} {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 2&amp;quot;&amp;gt;Eq 2:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 3&amp;quot;&amp;gt;Eq 3:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on C++2017 -based compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article will work.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 4&amp;quot;&amp;gt;Eq 4:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
	<entry>
		<id>https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=149</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://dirkmittler.homeip.net/mediawiki/index.php?title=Main_Page&amp;diff=149"/>
		<updated>2024-09-01T11:55:46Z</updated>

		<summary type="html">&lt;p&gt;DirkMittler: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''This is a personal MediaWiki.'''&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
The [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide] will explain how to use the WiKi software, to Dirk.&lt;br /&gt;
&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/ MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
== Some Experimentation with MediaWiKi ==&lt;br /&gt;
&lt;br /&gt;
=== Basics ===&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 1&amp;quot;&amp;gt;Eq 1:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;y=\pm\sqrt{1-x^{2}}&amp;lt;/math&amp;gt; {{spaces|2|emsp}} (Equation for circle.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tab name=&amp;quot;Drop-Down Menu&amp;quot; dropdown&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Plastic Widgets]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Framistans]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* &amp;lt;nowiki&amp;gt;[[Pet Rocks]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* [[#Eq 1|Eq 1]]&lt;br /&gt;
* [[#Eq 2|Eq 2]]&lt;br /&gt;
* [[#Eq 3|Eq 3]]&lt;br /&gt;
* [[#Replacement Code for C++2017|Some Working C++]]&lt;br /&gt;
* [[#Eq 4|Eq 4]]&lt;br /&gt;
&amp;lt;/tab&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inter-WiKi Links ===&lt;br /&gt;
&lt;br /&gt;
The following is a hypothetical exercise...&lt;br /&gt;
&lt;br /&gt;
[[File:Wikipedesketch.png|thumb|left|alt=A cartoon centipede reads books and types on a laptop.|The Wikipede edits ''[[wikipedia:Myriapoda]]''.]] This example is supposed to show how thumbnails can be made to display by default, as well as how inter-WiKi links work.&lt;br /&gt;
&lt;br /&gt;
Some of the links which follow, will not be prefixed with an obvious 'wikipedia:', but are also not of my own origin, as they will point to the English-speaking WiKiPedia.&lt;br /&gt;
&lt;br /&gt;
{{below}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== A Real Coding Issue ==&lt;br /&gt;
&lt;br /&gt;
The following is some reinvented (C++) code which was first suggested in 1999, to compute the reciprocal square root [[wikipedia:Fast inverse square root|using a trick]]. It may not be helpful, because this code requires that the language implementation can already perform multiplication and subtraction in [[wikipedia:Double precision|double-precision, floating-point]] representation, as well as to access such numbers as though they were integers. The fact that so-called 'doubles' have 11 most significant bits that state their power of 2 means that for most purposes, this sort of [[wikipedia:Type punning|type-punning]] computes their logarithm very quickly, which, in turn, is useful to produce a first approximation of their reciprocal square root, of the form...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 2&amp;quot;&amp;gt;Eq 2:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;\ln\left(\frac{1}{\sqrt{x}}\right)-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, exactly, the constants are used as starting values, from which half the punned value of (x) is to be subtracted, is not clear to most people, including This Author. This may have more to do with the binary floating-point format than with the square root of (x). Yet, the fact that Matthew Robertson was able to derive the double-precision version &amp;lt;ref&amp;gt;Matthew Robertson (2012-04-24). &amp;quot;A Brief History of InvSqrt&amp;quot; [https://mrober.io/papers/rsqrt.pdf X] &amp;lt;/ref&amp;gt; suggests that he knows. What's being computed more closely resembles...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 3&amp;quot;&amp;gt;Eq 3:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;C-\frac{1}{2}\ln\left(x\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What the reader may already have noticed is, that if he or she tries to implement this with C++2020, the standard method of type-punning no longer works, or produces some type of error message from the compiler&amp;lt;ref&amp;gt;GitHub Advice. &amp;quot;Don't use unions or pointer casts...&amp;quot; [https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html X]&amp;lt;/ref&amp;gt;... What this did for me was create a conflict, about whether I should code for the C++2017 installed on most of my boxes, or for C++2020, which I only have installed on one machine. I had the theoretical demand for code that was valid either way.&lt;br /&gt;
&lt;br /&gt;
=== The Legacy Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
float64_t Q_rsqrt_pun(const float64_t number) noexcept {&lt;br /&gt;
	uint64_t *temp1 = (uint64_t *) &amp;amp;number;&lt;br /&gt;
	uint64_t temp2 = 0x5FE6EB50C7B537A9 - (*temp1 &amp;gt;&amp;gt; 1);&lt;br /&gt;
	float64_t *out = (float64_t *) &amp;amp;temp2;&lt;br /&gt;
	return *out;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notably, this code still works on C++2017 -based compilers, and there is no compelling reason to think that it would not work under C++2020, except for the possibility that the compiler blocks it, just because it offends some aesthetic standard. As long as the floating-point number still conforms to the [[wikipedia:IEEE 754|IEEE 754]] standard, both methods shown in this article will work.&lt;br /&gt;
&lt;br /&gt;
However, there is the very real fact that on certain hardware architectures, the IEEE 754 standard may no longer define how 'double' floating-point numbers are formatted, and this could be the real reason to drop such practices. In that case, neither of the code versions in this article will work.&lt;br /&gt;
&lt;br /&gt;
=== Replacement Code for C++2017 ===&lt;br /&gt;
&lt;br /&gt;
The rest of the (working) computation applies [[wikipedia:Newton's Method|Newton's Method]] 4 extra times, resulting in precision which reaches the limit of the double-precision floating-point format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*  Fast Inverse Square Root, using Matthew Robertson's&lt;br /&gt;
 * Magic Number for double-precision floating-point.&lt;br /&gt;
 * &lt;br /&gt;
 * Implemented August 2, 2024&lt;br /&gt;
 * by Dirk Mittler&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdint&amp;gt;&lt;br /&gt;
&lt;br /&gt;
typedef double float64_t;&lt;br /&gt;
&lt;br /&gt;
float64_t Q_rsqrt(const float64_t number) noexcept {&lt;br /&gt;
	const float64_t threehalfs = 1.5;&lt;br /&gt;
	const float64_t halfnum = 0.5 * number;&lt;br /&gt;
	uint64_t temp;&lt;br /&gt;
	float64_t y;&lt;br /&gt;
	static_assert(sizeof(uint64_t) == sizeof(number),&lt;br /&gt;
					&amp;quot;`double` has a weird size.&amp;quot;);&lt;br /&gt;
	memcpy(&amp;amp;temp, &amp;amp;number, sizeof(float64_t));&lt;br /&gt;
//	temp = 0x5f3759df - (temp &amp;gt;&amp;gt; 1);	// Original 32-bit fr Quake III&lt;br /&gt;
	temp = 0x5FE6EB50C7B537A9 - (temp &amp;gt;&amp;gt; 1);	// Matthew Robertson's&lt;br /&gt;
	memcpy(&amp;amp;y, &amp;amp;temp, sizeof(float64_t));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	y *= (threehalfs - (halfnum * y * y));&lt;br /&gt;
	return y * (threehalfs - (halfnum * y * y));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reason Such Code Was Invented ===&lt;br /&gt;
&lt;br /&gt;
Of course, the original hack had as context that in early 3D games, texture maps were also associated with normal-maps &amp;lt;ref&amp;gt;LearnOpenGL - Normal Mapping [https://learnopengl.com/Advanced-Lighting/Normal-Mapping X]&amp;lt;/ref&amp;gt; that only had 8 bits of (signed) precision per coordinate (fetched as R, G and B components of a specially-prepared texture image, at 8 bits per channel), so that even 32-bit, single-precision floating point numbers were overkill for certain parts of the rendering. The game in which this was first exploited was a Quake III Arena version that ran on early PCs, but it can still be played today on Steam &amp;lt;ref&amp;gt;Quake III Arena on Steam (2024-08-31). [https://store.steampowered.com/app/2200/Quake_III_Arena/ X] &amp;lt;/ref&amp;gt;. And so, a real speed improvement can be achieved over ''accurate'' computations, by reducing the number of passes of Newton's Method, to 1 or even 0. In this case, precision is truly not equivalent to accuracy.&lt;br /&gt;
&lt;br /&gt;
In general, Normal Vectors need to be Unit Vectors, which can be derived from arbitrary vectors, such as the per-texel vectors of a normal-map, using the following equation, but requiring that a square root be divided by, which really means that the reciprocal of a square root frequently needs to be scalar-multiplied by...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;Eq 4&amp;quot;&amp;gt;Eq 4:&amp;lt;/span&amp;gt; {{spaces|2|emsp}} &amp;lt;math&amp;gt;\widehat{N}=\frac{1}{\left\Vert N\right\Vert }N,\;\left\Vert N\right\Vert =\sqrt{N_{x}^{2}+N_{y}^{2}+N_{z}^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>DirkMittler</name></author>
	</entry>
</feed>