<?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; Topic: sqrt() not working?</title>
		<link>http://forums.leaflabs.com/topic.php?id=125</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:22:33 +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?topic=125" rel="self" type="application/rss+xml" />

		<item>
			<title>CarlO on "sqrt() not working?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=125#post-776</link>
			<pubDate>Thu, 19 Aug 2010 18:16:11 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">776@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks bnewbold,&#60;/p&#62;
&#60;p&#62;That was easy!!!&#60;/p&#62;
&#60;p&#62;I modified my linker script files and the linker is happy now!&#60;/p&#62;
&#60;p&#62;Thanks again for your quick response to this problem,&#60;/p&#62;
&#60;p&#62;Carl
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bnewbold on "sqrt() not working?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=125#post-775</link>
			<pubDate>Thu, 19 Aug 2010 17:55:55 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">775@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The fix I found is in this commit:&#60;br /&#62;
&#60;a href=&#34;http://github.com/leaflabs/libmaple/commit/5f11e12d66ce65e8be2b695ece6f35c2889d2aa2&#34; rel=&#34;nofollow&#34;&#62;http://github.com/leaflabs/libmaple/commit/5f11e12d66ce65e8be2b695ece6f35c2889d2aa2&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The punchline is that you can hand-modify the ram.ld and flash.ld linker scripts and add libm.a to the GROUPS() line to get the math functions linked in correctly.&#60;/p&#62;
&#60;p&#62;libm.a is already included in the gcc toolchain, it simply wasn't added to the linker search path. This problem took a while to track down because it didn't affect our Makefile toolchain and the compiler would frequently optimize calls away. For instance this bit of code links fine:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;float foo = 12.34;
void setup() {}
void loop() {
  //foo = sqrt(foo);
  SerialUSB.println(foo);
  float bar = 56.78;
  bar = sqrt(bar);
  SerialUSB.println(bar);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;but if you uncomment the &#34;foo = sqrt(foo);&#34; line it does not link.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "sqrt() not working?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=125#post-774</link>
			<pubDate>Thu, 19 Aug 2010 16:53:16 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">774@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi bnewbold,&#60;/p&#62;
&#60;p&#62;After digging around the web, I found out that the code for sqrt() is supposed to be in an archived library named libm.a  After trying to decipher the ArmCompiler class and the Boards.txt file, it looks like the IDE is telling the linker to look for libraries in this path: &#60;/p&#62;
&#60;p&#62;Maple IDE\hardware\leaflabs\cores\maple&#60;/p&#62;
&#60;p&#62;I notice there is not a copy of the libm.a library in the path that the linker is looking at.&#60;/p&#62;
&#60;p&#62;It also looks like adding the compiler switch -lm will instruct the linker to link in the proper math library included with the compiler.  This seems to be the approach that Arduino uses in it's Compiler class.&#60;/p&#62;
&#60;p&#62;You can see an explanation here:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html&#34; rel=&#34;nofollow&#34;&#62;http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I'm not really set up to build the IDE or I would test this out.&#60;/p&#62;
&#60;p&#62;Carl
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bnewbold on "sqrt() not working?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=125#post-772</link>
			<pubDate>Thu, 19 Aug 2010 13:51:22 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">772@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oops, lost track of that bug, it also affects the standard trig functions (sin, cos, atan, etc). It's some strange linker mojo, we haven't figured it out yet to be honest. The canonical weirdness is that this code works fine:&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
float bar = 12.34;&#60;/p&#62;
&#60;p&#62;void setup() { }&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
  float foo = 12.34;&#60;br /&#62;
  foo = sqrt(foo);&#60;br /&#62;
  //bar = sqrt(bar);&#60;br /&#62;
  Serial2.println(foo);&#60;br /&#62;
  Serial2.println(bar);&#60;br /&#62;
}&#60;br /&#62;
&#60;/code&#62;&#60;br /&#62;
but if you uncomment the &#60;code&#62;bar&#60;/code&#62; line it doesn't work. I'm pretty sure this is because the math library isn't actually getting linked in, but in most trivial test cases the compiler optimizes out the actual function call so this wasn't found in our earlier testing.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "sqrt() not working?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=125#post-763</link>
			<pubDate>Wed, 18 Aug 2010 16:28:47 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">763@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I am getting a linker error when trying to use sqrt:&#60;/p&#62;
&#60;p&#62;C:\Users\Carl\AppData\Local\Temp\build4423889891360605121.tmp/PPM.cpp:323: undefined reference to `sqrt'&#60;/p&#62;
&#60;p&#62;It compiles fine, but won't link.&#60;/p&#62;
&#60;p&#62;Has anyone used sqrt() before?  Is there a library missing?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
