<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; User Favorites: larryang</title>
		<link><a href='http://forums.leaflabs.com/profile.php?id=92'>92</a></link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:36 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?profile=92" rel="self" type="application/rss+xml" />

		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-12168</link>
			<pubDate>Fri, 03 Aug 2012 03:11:55 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">12168@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi both - I'm glad this is proving useful to someone.&#60;/p&#62;
&#60;p&#62;I will return to the library later this year, but at the moment working on the project for my MSc is swallowing somewhere between most and all of my time when I'm not sleeping!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-11974</link>
			<pubDate>Tue, 24 Jul 2012 17:42:11 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">11974@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;dapoup - This has been used to discuss the fixed point.&#60;br /&#62;
Some folks are trying a newer (than LeafLabs) gcc from &#60;a href=&#34;https://launchpad.net/gcc-arm-embedded&#34; rel=&#34;nofollow&#34;&#62;https://launchpad.net/gcc-arm-embedded&#60;/a&#62; which has fixed point support built in.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>dapoup on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-11967</link>
			<pubDate>Tue, 24 Jul 2012 08:32:46 +0000</pubDate>
			<dc:creator>dapoup</dc:creator>
			<guid isPermaLink="false">11967@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Indeed, as a Maple newcomer and audio enthusiast, I'm extremely interested in the outcome of this work. Is this the topic covering technical points about the &#34;fixed point library&#34; that is announced on the documentation of the Maple?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10441</link>
			<pubDate>Mon, 30 Apr 2012 19:39:33 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">10441@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;iainism - while this isn't very helpful to you, but following you through this fixed point stuff is very interesting to me. I suspect several people are (or will be) getting some benefit from following along with you. So thanks for all you effort.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10438</link>
			<pubDate>Mon, 30 Apr 2012 17:45:43 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10438@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer - thanks for catching that - you're absolutely right (again) about the sign bit.  I really need to brush up on my bitwise operations!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10436</link>
			<pubDate>Mon, 30 Apr 2012 16:11:48 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">10436@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ianism&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I've corresponded with Trenki, who has pointed out that the sign conversion in my code above isn't necessary, as the sign bit is preserved by the bitwise shifts&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;That is not completely accurate.&#60;/p&#62;
&#60;p&#62;The sign &#60;strong&#62;is&#60;/strong&#62; preserved for signed integers by &#60;code&#62;&#38;gt;&#38;gt;=&#60;/code&#62;. &#60;/p&#62;
&#60;p&#62;As I mentioned in my earlier post, sign is &#60;strong&#62;not&#60;/strong&#62; preserved for &#60;code&#62;&#38;lt;&#38;lt;=&#60;/code&#62;.&#60;br /&#62;
This shift could move a '1' into the most-significant-bit (msb), which is always an error because that bit represented part of the value, and not the sign of the value. The rewritten code still has the same error. The error won't happen on every value, only the values where a '1' is shifted into the msb.&#60;/p&#62;
&#60;p&#62;The fact that division is faster is pretty interesting.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10435</link>
			<pubDate>Mon, 30 Apr 2012 14:07:06 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10435@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer.&#60;/p&#62;
&#60;p&#62;[The last paragraph of this post may be more significant then the remainder]&#60;/p&#62;
&#60;p&#62;&#34;It appears to be template &#38;lt;int q&#38;gt; inline fixed_point&#38;lt;q&#38;gt; f_inv(fixed_point&#38;lt;q&#38;gt; a)&#60;br /&#62;
but it actually adjust the number so that the return value is a fixed_point&#38;lt;32-q&#38;gt;, and not a fixed_point&#38;lt;q&#38;gt;.&#34;&#60;/p&#62;
&#60;p&#62;Yes, it is slightly confusing, but this is due to the nature of Trenki's library function:&#60;br /&#62;
&#60;code&#62;template &#38;lt;int q&#38;gt; inline fixed_point&#38;lt;q&#38;gt; fixinv(fixed_point&#38;lt;q&#38;gt; a)&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Which sits behind &#60;code&#62;inv&#38;lt;p&#38;gt;&#60;/code&#62; (for p=) and takes a &#60;code&#62;fixed_point&#38;lt;q&#38;gt;&#60;/code&#62; but returns a &#60;code&#62;fixed_point&#38;lt;32-q&#38;gt;&#60;/code&#62;, which is fine for inv&#38;lt;16&#38;gt;.  The purpose of my code is to convert the returned value back to &#60;code&#62;fixed_point&#38;lt;q&#38;gt;&#60;/code&#62; when q isn't 16.&#60;/p&#62;
&#60;p&#62;I've corresponded with Trenki, who has pointed out that the sign conversion in my code above isn't necessary, as the sign bit is preserved by the bitwise shifts (something I'd forgotten in the 10 years or so since I last did bitwise operations!).  His suggestion is:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// q is the precision of the input
// output also has precision of q
template&#38;lt;int q&#38;gt;
inline fixed_point&#38;lt;q&#38;gt; f_inv(fixed_point&#38;lt;q&#38;gt; a)
{
       const int p = 32 - q;

       fixed_point&#38;lt;q&#38;gt; retVal;
       retVal.intValue = fixinv&#38;lt;q&#38;gt;(a.intValue);

       if (q &#38;lt; p)
               retVal.intValue &#38;gt;&#38;gt;= (p - q);
       else
               retVal.intValue &#38;lt;&#38;lt;= (q - p);

       return retVal;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I suppose a logical step could be to create a &#60;code&#62;.longValue&#60;/code&#62; (similar to &#60;code&#62;.intValue&#60;/code&#62;) to allow overflow checking but I'm not sure how much use this would be, since this would still leave an opening for underflow when using a low number of fractional bits and inverting large numbers...&#60;/p&#62;
&#60;p&#62;In any case this could all be moot, since in my (very brief) tests, it seems (that for p != 16) the division operator outperforms taking the product of a &#60;code&#62;fixed_point&#38;lt;p&#38;gt;&#60;/code&#62; and a &#60;code&#62;f_inv&#38;lt;p&#38;gt;(fixed_point&#38;lt;p&#38;gt;)&#60;/code&#62;.  Which is a trifle vexing!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10424</link>
			<pubDate>Mon, 30 Apr 2012 06:29:52 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">10424@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;iainism - IMHO this is confusing, and not explicit.&#60;/p&#62;
&#60;p&#62;It appears to be&#60;br /&#62;
&#60;code&#62;template &#38;lt;int q&#38;gt; inline fixed_point&#38;lt;q&#38;gt; f_inv(fixed_point&#38;lt;q&#38;gt; a)&#60;/code&#62;&#60;br /&#62;
but it actually adjust the number so that the return value is a &#60;code&#62;fixed_point&#38;lt;32-q&#38;gt;&#60;/code&#62;, and &#60;strong&#62;not&#60;/strong&#62; a &#60;code&#62;fixed_point&#38;lt;q&#38;gt;&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;IMHO it would be clearer if it were:&#60;br /&#62;
&#60;code&#62;template &#38;lt;int p&#38;gt; inline fixed_point&#38;lt;p&#38;gt; f_inv(fixed_point&#38;lt;p&#38;gt; a)&#60;/code&#62;&#60;br /&#62;
and it kept all of the details of how it achieves that internal, and actually return a &#60;code&#62;fixed_point&#38;lt;p&#38;gt;&#60;/code&#62;.&#60;br /&#62;
Or it were&#60;br /&#62;
&#60;code&#62;template &#38;lt;int p, int q&#38;gt; inline fixed_point&#38;lt;q&#38;gt; f_inv(fixed_point&#38;lt;p&#38;gt; a)&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;NB: it can silently overflow, and lose the most significant bits.&#60;br /&#62;
If it does &#60;code&#62;helper &#38;lt;&#38;lt;= (q-p);&#60;/code&#62; the upper bits are discarded which could have the effect of drastically changing the value.&#60;/p&#62;
&#60;p&#62;Edit: NB 2: the sign might be incorrect, but this is related to the overflow due to &#60;code&#62;helper &#38;lt;&#38;lt;= (q-p);&#60;/code&#62; which could shift a '1' into the top, sign, bit, and change the sign of the value.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10410</link>
			<pubDate>Sat, 28 Apr 2012 12:32:57 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10410@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;OK, adding this to fixed_class.h seems to work (all the time now!), and provides the template function &#60;code&#62;f_inv&#60;/code&#62; to handle non-16-bit precision cases:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// q is the precision of the input
// output also has precision of q
template &#38;lt;int q&#38;gt;
inline fixed_point&#38;lt;q&#38;gt; f_inv(fixed_point&#38;lt;q&#38;gt; a)
{
	int p=32-q;
	int helper;
	bool sign = false;

	fixed_point&#38;lt;32-q&#38;gt; x;
	fixed_point&#38;lt;q&#38;gt; retVal;

	x.intValue = fixinv&#38;lt;q&#38;gt;(a.intValue);

	helper=x.intValue;

	if (a &#38;lt; 0) {
		sign = true;
		a = -a;
	}

	if (p==q) {
		// Do nothing!
	} else {
		if (q&#38;lt;p) { // Need to right-shift
			helper &#38;gt;&#38;gt;= (p-q);
		} else {   // Need to left-shift
			helper &#38;lt;&#38;lt;= (q-p);
		}
	}

	retVal.intValue = helper;

	if (sign) {
		return -retVal;
	} else {
		return retVal;
	}
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;One can then do a*f_inv&#38;lt;P&#38;gt;(b)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10409</link>
			<pubDate>Sat, 28 Apr 2012 10:25:49 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10409@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;[I realise the &#60;code&#62;if&#60;/code&#62; I've added could be optimised a little to use a negative shift operation, but I prefer explicit code and I never try to out-optimise my compiler ;-)]
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10408</link>
			<pubDate>Sat, 28 Apr 2012 10:18:04 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10408@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Edit:  Removed faulty code... Will be back later with some that works, I hope!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=4#post-10406</link>
			<pubDate>Sat, 28 Apr 2012 06:00:12 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10406@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Argh. On my phone and didn't quite cover the last question!&#60;/p&#62;
&#60;p&#62;Using 32-p for q works fine, but this requires some shifting around if one is feeding in the result of a previous &#38;lt;p&#38;gt;	operation, as per my final thought above.&#60;/p&#62;
&#60;p&#62;Iain
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=3#post-10405</link>
			<pubDate>Sat, 28 Apr 2012 05:54:11 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10405@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer, yes inv&#38;lt;16&#38;gt; works fine, (there's actually a function written for p=16 as a special case, but any other p fails at compile time, with a 'no match' error).&#60;/p&#62;
&#60;p&#62;I can use the division operator to get where I need to be. I was just mindful of the discussion of the additional time taken for division, as discussed above, and so curious if anyone had found a way to use fixinv for p!=16, without using the two conversions, which add a floating point operation each.&#60;/p&#62;
&#60;p&#62;I think that one could do a bitwise shift one way or the other on the result of fixinv based off a comparison of p and 32-p by 32-2p bits. I'll test this once I'm back at my machine and feed back.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=3#post-10390</link>
			<pubDate>Fri, 27 Apr 2012 13:40:12 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">10390@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;iainism - have you tried using p=16, and &#60;code&#62;fixed_point&#38;lt;16&#38;gt; inv(..)&#60;/code&#62; as an experiment?&#60;/p&#62;
&#60;p&#62;The comment in fixed_func.h says:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// q is the precision of the input
// output has 32-q bits of fraction
template &#38;lt;int q&#38;gt;
inline int fixinv(int32_t a) ...&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Which seems to agree with what you wrote. &#60;/p&#62;
&#60;p&#62;So have you tried instantiating&#60;code&#62;template &#38;lt;int q&#38;gt; inline int fixinv(int32_t a)&#60;/code&#62; with &#60;code&#62;&#38;lt;32-p&#38;gt;&#60;/code&#62;?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>iainism on "Fixed Point Math library"</title>
			<link>http://forums.leaflabs.com/topic.php?id=266&amp;page=3#post-10372</link>
			<pubDate>Thu, 26 Apr 2012 16:33:33 +0000</pubDate>
			<dc:creator>iainism</dc:creator>
			<guid isPermaLink="false">10372@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#34;Use the 'inv' function in Trenki's library to implement division a/b as a*inv(b)&#34;&#60;/p&#62;
&#60;p&#62;Has anyone got this to work with anything except P=16?  The fixed_class.h file says:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// math functions
// no default implementation

template &#38;lt;int p&#38;gt;
inline fixed_point&#38;lt;p&#38;gt; sin(fixed_point&#38;lt;p&#38;gt; a);

template &#38;lt;int p&#38;gt;
inline fixed_point&#38;lt;p&#38;gt; cos(fixed_point&#38;lt;p&#38;gt; a);

template &#38;lt;int p&#38;gt;
inline fixed_point&#38;lt;p&#38;gt; sqrt(fixed_point&#38;lt;p&#38;gt; a);

template &#38;lt;int p&#38;gt;
inline fixed_point&#38;lt;p&#38;gt; rsqrt(fixed_point&#38;lt;p&#38;gt; a);

template &#38;lt;int p&#38;gt;
inline fixed_point&#38;lt;p&#38;gt; inv(fixed_point&#38;lt;p&#38;gt; a);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I've looked at using&#60;/p&#62;
&#60;p&#62;&#60;code&#62;fixinv&#38;lt;P&#38;gt;(c)&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;But this returns a result with 32-P fractional bits, and the only way I've found to convert this back to P fractional bits is to do a fix2float&#38;lt;32-P&#38;gt; and then a float2fix&#38;lt;P&#38;gt; which seems quite wasteful (and brings in floating point operations)!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
