Ranter
Join devRant
Do all the things like
				++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
				Sign Up
			Pipeless API
 
				From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
				Learn More
			Comments
		- 
				
				 okkimus16918yTo me it's working as intended. You are doing integer division -> answer will be floored to the integer value. okkimus16918yTo me it's working as intended. You are doing integer division -> answer will be floored to the integer value.
 
 -1 / 10 is -0,1 and gets floored to -1.
 
 -(1 / 10) is -0,1 but you are doing the division first and 1 / 10 = 0,1 which is floored to 0 and therefore answer is 0.
 
 Edit: And this is pretty much the standard behaviour in all the major programming languages. If you wish to get the right answer, just turn the dividend or divider to float / double.
- 
				
				@okkimus why do u use , instead of . in floats.. like 0,1 instead of 0.1??? Both these characters are close by!!!
- 
				
				 okkimus16918y@AnonymusPanther okkimus16918y@AnonymusPanther
 
 Just the convention used in my country :D You can imagine the same confusion when I needed to start using "." while programming...
- 
				
				 hido13458y@AnonymusPanther I have no reason of saving integers as floats, and should not have a reason to convert the types just to get a reasonable division. hido13458y@AnonymusPanther I have no reason of saving integers as floats, and should not have a reason to convert the types just to get a reasonable division.
- 
				
				 okkimus16918y@hido13 okkimus16918y@hido13
 
 Oh yeah, actually you are correct. Tried few repls and Java, C++ and bunch of others gave 0 for both. Ruby gave the same as Python.
 
 Though the Python way just makes more sense for me.
 
 And what contradicts basic property of real numbers?
- 
				
				 okkimus16918y@Julien00859 okkimus16918y@Julien00859
 
 Yeah, it seems to be python 2.
 
 I started to look in to it it's actually kinda interesting question. They changes it in python 3 to change the type to double if needed. Though you can use "//" operator to do the good ol' integer division.
 
 But I started to investigate why there's difference between python 2 and Java. I checked and they have same operator precedence...so there's something else happening under the hood.
- 
				
				 Buggz6048yAll the scandinavian countries use comma, Germany does too. I wonder if most of Europe does, and it's only the english speaking countries that use dot for decimals. Our way looks weird to them because the comma is a thousands separator, but here we just throw in a space for easier readability of large numbers. Buggz6048yAll the scandinavian countries use comma, Germany does too. I wonder if most of Europe does, and it's only the english speaking countries that use dot for decimals. Our way looks weird to them because the comma is a thousands separator, but here we just throw in a space for easier readability of large numbers.
- 
				
				I Greece we also use comma for decimals and dot to separate very big numbers, ie 1.234.567
 
 Also, most scripted languages have fucked up math operations.
Related Rants





 when your code is a mess but everything work out in the end
when your code is a mess but everything work out in the end
 When you keep getting +1s on a rant you posted a month ago.
When you keep getting +1s on a rant you posted a month ago.
 Go big or go home.
Go big or go home.
I was looking up for a bug in my code that caused a fail in one of the test.
Hours later I found that negative integer division in python is just stupid and -1 / 10 = -1.
The sad part is that -1/10 != -(1/10) contradicting the associative property of multiplication over the real numbers.
FUCK YOU PYTHON.
rant
python 2
stupidity