www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Double precision?

reply TheDGuy <loder.feuer googlemail.com> writes:
I don't know what my computer is doing today:

code:
		double normalized_i = (x / width) - 0.5;
		double normalized_j = (y / height) - 0.5;
		writeln(x);
		writeln(normalized_i);
		writeln(y);
		writeln(normalized_j);

x and y are coordinates and if x is any number from 0 to 150 the 
result of x/width is always zero, how can that be (width is never 
0)? Another video: https://youtu.be/Fysv2fOwtk4
Dec 27 2015
parent Bubbasaur <bubba gmail.com> writes:
On Sunday, 27 December 2015 at 20:06:53 UTC, TheDGuy wrote:
 I don't know what my computer is doing today:
 x and y are coordinates and if x is any number from 0 to 150 
 the result of x/width is always zero
Dividing Integers will result in Integer: int x = 10, width = 50; writeln(x/width); // Will be "0" writeln(x/cast(double)width); // Will be 0.2 Check out: http://dpaste.dzfl.pl/8bcfb3d9c551
... Another video: https://youtu.be/Fysv2fOwtk4
Please dude, start using dpaste for that, it's a bit nonsense watching videos. Bubba.
Dec 27 2015