+ 7

Why (1/3 + 1/3 + 1/3 == 1) is False?

29th Dec 2017, 3:56 PM
Demetrius
8 Respuestas
+ 17
Because 1/3 goes on to infinity. Since the compiler can't handle infinite numbers, it rounds it after some decimal points after the comma. So 1/3 + 1/3 + 1/3 will equal 0.999999999 or something like that, but not one because of the limitations of the compiler ! (1/3 equals 0.333... and not 0) !
29th Dec 2017, 4:08 PM
The Coding Sloth
The Coding Sloth - avatar
+ 20
//in java 1/3 means 0 System.out.print(1/3); //0
29th Dec 2017, 6:18 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
because 1/3 is 0 and so on 0 + 0 + 0 = 0 which is different from 1
29th Dec 2017, 3:58 PM
Vukan
Vukan - avatar
+ 7
yes, that is true on floats and doubles, but these are integers so 1/3 = 0
29th Dec 2017, 4:43 PM
Vukan
Vukan - avatar
+ 5
@Vukan That highly depends on the language in question.
29th Dec 2017, 5:12 PM
1of3
1of3 - avatar
+ 2
You would need to round the 0.99999. If it's in js you could use something like Math.floor, Math.ceil, or Math.round. I think.toFixed(); can round sometimes as well, but it would still show decimal places
29th Dec 2017, 10:24 PM
Jayden Wyatt
Jayden Wyatt - avatar
+ 1
@Full Gamer: 0.999... is equal to 1 in pure math. There is no number in between. /math teacher off
30th Dec 2017, 8:36 PM
1of3
1of3 - avatar
+ 1
Thank you guys, this has bent the laws of maths. Appreciate it.
1st Jan 2018, 12:41 PM
Demetrius