<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Float going wild</title>
		<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild</link>
		<description>Posts in the discussion thread &quot;Float going wild&quot; - I am tracking my difficultymodifier float, which goes wild</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 16 May 2026 14:38:28 +0000</lastBuildDate>
		
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1298252</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1298252</link>
				<description></description>
				<pubDate>Sat, 05 Nov 2011 09:27:37 +0000</pubDate>
				<wikidot:authorName>WindwalkerDM</wikidot:authorName>				<wikidot:authorUserId>1158597</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Excellent and nimble code; thanks. Though I got a new job and coding slowed down, we are in a holiday period now and I may make use of the idea.</p> <p>Thanks.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1297893</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1297893</link>
				<description></description>
				<pubDate>Fri, 04 Nov 2011 18:52:14 +0000</pubDate>
				<wikidot:authorName>EmpiresBane</wikidot:authorName>				<wikidot:authorUserId>1193823</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>One thing I might suggest so that you don't have to constantly cast it is this:</p> <div class="code"> <pre><code>private int scoreModifier; public float ScoreModifier { get { return scoreModifier / 10; } set { scoreModifier = (int)(value * 10); } }</code></pre></div> <p>You can change 10 to any power of 10 based on how many digits of accuracy you want. For example, if you want 3 digits after the decimal place, you would change 10 to 1000.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1294137</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1294137</link>
				<description></description>
				<pubDate>Sun, 30 Oct 2011 20:17:12 +0000</pubDate>
				<wikidot:authorName>WindwalkerDM</wikidot:authorName>				<wikidot:authorUserId>1158597</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Thank you jake; I followed the link and dug some deeper and found the answer. It turns out float calculations in our rams and intermadiate/computer language doesn't work like we instictively imagine. People suggest solutions like mine if small losses of data are not important. They also suggest using int in some circumstances.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1292995</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1292995</link>
				<description></description>
				<pubDate>Fri, 28 Oct 2011 20:12:09 +0000</pubDate>
				<wikidot:authorName>ff8jake</wikidot:authorName>				<wikidot:authorUserId>1215695</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hmm, just did an interesting test that shows what you're seeing in action (though, I am not really closer to a solution, just wanted to see if I could reproduce it). Make a new console application with the following code:</p> <div class="code"> <div class="hl-main"> <pre><span class="hl-reserved">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">; </span><span class="hl-reserved">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Collections</span><span class="hl-code">.</span><span class="hl-identifier">Generic</span><span class="hl-code">; </span><span class="hl-reserved">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Linq</span><span class="hl-code">; </span><span class="hl-reserved">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Text</span><span class="hl-code">; </span><span class="hl-types">namespace</span><span class="hl-code"> </span><span class="hl-identifier">ConsoleApplication1</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">class</span><span class="hl-code"> </span><span class="hl-identifier">Program</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">Main</span><span class="hl-brackets">(</span><span class="hl-identifier">string</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">testFloat</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-reserved">while</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">testFloat</span><span class="hl-code"> &lt; </span><span class="hl-number">9999</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-identifier">testFloat</span><span class="hl-code"> += </span><span class="hl-number">0.1</span><span class="hl-identifier">f</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">WriteLine</span><span class="hl-brackets">(</span><span class="hl-identifier">testFloat</span><span class="hl-code">.</span><span class="hl-identifier">ToString</span><span class="hl-brackets">())</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">ReadLine</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-brackets">}</span></pre></div> </div> <br /> This will spit a line with the testFloat value and wait for input. Just hit Enter to get new values from it. On my machine it happens as early as .8 (becomes .800001 or so). <p>EDIT: stackoverflowDOTcom/questions/478474/c-sharp-float-bug-0-1-0-1-1-490116e-08 seems to talk about it and some rounding options.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1292865</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1292865</link>
				<description></description>
				<pubDate>Fri, 28 Oct 2011 17:52:51 +0000</pubDate>
				<wikidot:authorName>WindwalkerDM</wikidot:authorName>				<wikidot:authorUserId>1158597</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I have tried some nasty (and ugly) method by casting, then dividing the result by 10 and storing the result in a new float and it worked. For now there might be some very minor data loss in the process, but it's overall effect would be minimal and completely unnoticable. If it were some windows application using writeline() I could have put it into shape by using {0#.###} format but I couldnt find the same for spritefont.</p> <p>I didn't put a breakpoint for this matter, but there is nothing else in the code. It's just</p> <p>difficultymodifier += 0.1;</p> <p>I have no idea&#8230;</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1292464</guid>
				<title>Re: Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1292464</link>
				<description></description>
				<pubDate>Fri, 28 Oct 2011 04:48:48 +0000</pubDate>
				<wikidot:authorName>ff8jake</wikidot:authorName>				<wikidot:authorUserId>1215695</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>In my brick breaker game I have run into a couple issues like this that seemed totally illogical, but I have found using breakpoints in Visual C# very helpful in diagnosing the problem. You might try putting a breakpoint on the section of code that adds to your float, then using the &quot;step into&quot; button to watch what happens to that variable after each statement. If it only happens after the game has been going for a bit, you might have luck putting in a temporary &quot;if&quot; statement to check your variable's value (i.e., as soon as it gets over some amount it shouldn't be at), and put the breakpoint on some code inside that &quot;if&quot; statement.</p> <p>Alternatively if you aren't worried about why your float is suddenly taking on a value it shouldn't have (personally, it would bug me, but floating point numbers are a pain to figure out sometimes), you could cast that variable in your scoring function using (int)difficultymodifier so your score doesn't take on a strange floating point value. :)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-405146#post-1291837</guid>
				<title>Float going wild</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-405146/float-going-wild#post-1291837</link>
				<description></description>
				<pubDate>Thu, 27 Oct 2011 14:47:34 +0000</pubDate>
				<wikidot:authorName>WindwalkerDM</wikidot:authorName>				<wikidot:authorUserId>1158597</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hello everyone.</p> <p>I got a job now, which slowed my progression rather hard. Besides, I am also toying with microsoft pivotviewer and silverlight in a different&#8230; thread&#8230;</p> <p>Anyway, my game is going quite fine, I handled almost all the problems, tried it on many different computers, and&#8230; finally I was able to add my (quite simple and foolish) line-of-sight machanic into game. Now the player only can see in a conical field in front of her ship combined with a small radius circle all around her. It's basically a 2000 x 2000 black sprite with the mentioned field transparent, rotating with the player, and drawn last, so everything else stays behind it. It's quite sloppy but it works for desired effect.</p> <p>However, there is a rathet strange problem I am encountering. I made the game so that it goes progressively difficult, each spawning of an enemy increasing a global float value by 0.1. This &quot;difficultymodifier&quot; is than used to increse enemy sprites speeds, health, rate of fire etc. But it also increases the players score multiplier. So the game gets more difficult, but the player also gains more points in return. Currently there is no end to the game and the player is trying to achieve the highest score.</p> <p>The problem I noticed when I decided to see the values on the screen during gameplay, so I could fine-tune them. At some point, the normally 0.1 incrementing float variable increases by 0.09999999999 or something like that, and the difficulty modifer thus becomes sth like 4,399999999999 (and keeps increasing in 0.1 increments) I didnt notice if it did get increased by 0.0999999 again later, but it probably does.</p> <p>Now normally this is not a big problem for an invisible background worker, but the problem is I tied it to player score. Thus the player socre becomes f*cked up too. Any ideas why this is happening, and what I could do to fix this?</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>