<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: NaN from dear euclid</title>
		<atom:link href="http://cycling74.com/forums/topic/nan-from-dear-euclid/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 23:23:21 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-31889</guid>
					<title><![CDATA[NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-31889</link>
					<pubDate>Sun, 13 May 2007 13:53:10 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;ve got a Euclidean distance method which looks right to me, but it&#8217;s giving me NaNs here and there&#8230;</p>
<p>	public double euclideanDistance(double[] origin, double[] point)<br />
		{<br />
		double distance = 0;<br />
		double sum = 0;<br />
		for(int i=0;i < point.length;i++)<br />
			{<br />
			double diff = Math.abs(origin[i] &#8211; point[i]);<br />
			double pow = (double)Math.pow(diff, 2);<br />
			sum += pow;<br />
			}<br />
		distance = (double)Math.sqrt(sum);<br />
		post(&#8220;origin tension: &#8221; +origin[0] +&#8221;, point tension: &#8221; +point[0] +&#8221;, distance: &#8221; +distance);<br />
		return distance;<br />
		}</p>
<p>I check that the double[]s are the same length *before* calling.</p>
<p>I&#8217;m wondering whether this is a precision or rounding problem with double&#8230;??? (As in, perhaps I need the mythical bigDecimal)<br />
I&#8217;ve never used BigDecimal, so if somebody can clue me in, I&#8217;d appreciate it.</p>
<p>Or maybe I&#8217;m just doing something goofy that I&#8217;m not seeing?</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104072</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104072</link>
					<pubDate>Sun, 13 May 2007 14:13:47 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>ugh&#8230;</p>
<p>So, I tried using BigDecimal with MathContext HALF_UP, and the line where the BigDecimal shows up gives a NumberFormatException: Infinite or NaN. Fair enough. It certainly seems to indicate that I&#8217;ve found the problem, but how do I track down the source? I just thought BigDecimal would deal with it&#8230;</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104073</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104073</link>
					<pubDate>Sun, 13 May 2007 14:47:21 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>okay&#8230; sorry for the spam.</p>
<p>It&#8217;s not the euclideanDistance method. I was sending poor euclid a NaN somehow&#8230; tracking it down now. Not sure why it didn&#8217;t get detected earlier. </p>
<p>Apologies.</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104074</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104074</link>
					<pubDate>Sun, 13 May 2007 18:05:30 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 13 mai 07, at 16:47, jbmaxwell wrote:</p>
<p>> okay&#8230; sorry for the spam.<br />
><br />
> It&#8217;s not the euclideanDistance method. I was sending poor euclid a  <br />
> NaN somehow&#8230; tracking it down now. Not sure why it didn&#8217;t get  <br />
> detected earlier.</p>
<p>By the way, why do you use Math.abs? I&#8217;m quite sure your for loop can  <br />
be more efficient (no memory allocation either):</p>
<p>for(int i=0;i < point.length;i++)<br />
{<br />
	sum += (double)Math.pow(origin[i] &#8211; point[i], 2);<br />
}</p>
<p>Cheers,<br />
ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104075</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104075</link>
					<pubDate>Sun, 13 May 2007 18:44:17 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>Quote: Emmanuel Jourdan wrote on Sun, 13 May 2007 19:05<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
> On 13 mai 07, at 16:47, jbmaxwell wrote:<br />
> <br />
> > okay&#8230; sorry for the spam.<br />
> ><br />
> > It&#8217;s not the euclideanDistance method. I was sending poor euclid a  <br />
> > NaN somehow&#8230; tracking it down now. Not sure why it didn&#8217;t get  <br />
> > detected earlier.<br />
> <br />
> By the way, why do you use Math.abs? I&#8217;m quite sure your for loop can  <br />
> be more efficient (no memory allocation either):<br />
> <br />
> for(int i=0;i < point.length;i++)<br />
> {<br />
> 	sum += (double)Math.pow(origin[i] &#8211; point[i], 2);<br />
> }<br />
> <br />
> Cheers,<br />
> ej<br />
></p>
<p>oops! Yeah, the Math.abs() wasn&#8217;t in there originally, but I was freaking out thinking maybe a sqrt() on a negative value was causing my NaN&#8230; I&#8217;ll rip that out again.</p>
<p>thanks!</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104076</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104076</link>
					<pubDate>Sun, 13 May 2007 18:51:37 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>Actually, ej, this brings up a general efficiency question I&#8217;ve had. Is it actually more efficient to roll multiple lines into one, like you did with my code? I&#8217;ve never really been sure about that. I mean, it looks more &#8220;compact&#8221; on the page, but does it matter once the class is compiled?</p>
<p>thanks,</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104077</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104077</link>
					<pubDate>Sun, 13 May 2007 19:16:30 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104078</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104078</link>
					<pubDate>Tue, 15 May 2007 19:21:25 +0000</pubDate>
					<dc:creator>projects</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104079</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104079</link>
					<pubDate>Wed, 16 May 2007 06:19:49 +0000</pubDate>
					<dc:creator>jbm</dc:creator>

					<description>
						<![CDATA[
						<p>
> <br />
> ps. I would use  a*a instead of Math.pow(a,2)  :)<br />
> </p>
<p>Right, got it. Good point! Not much need to load up a whole new class for a^2. I guess pow() is handy when it&#8217;s a^25 or something.</p>
<p>cheers,</p>
<p>J.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104080</guid>
					<title><![CDATA[Re: NaN from dear euclid]]></title>
					<link>http://cycling74.com/forums/topic/nan-from-dear-euclid/#post-104080</link>
					<pubDate>Wed, 16 May 2007 17:02:08 +0000</pubDate>
					<dc:creator>projects</dc:creator>

					<description>
						<![CDATA[
						<p>> Right, got it. Good point! Not much need to load up a whole new class for a^2. I guess pow() is handy when it&#8217;s a^25 or something.</p>
<p>
Yes.  Or even better, when the exponent value is also a variable.  :)</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

