+ 4

[BUG] maybe or please explain me if I'm wrong

https://code.sololearn.com/cGA5S2L0DhZo/?ref=app

12th May 2017, 11:39 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
15 Respostas
+ 13
Yeah. SL is buggy af Found out today morning Drove me nuts lol
12th May 2017, 12:41 PM
Pixie
Pixie - avatar
+ 10
my original theory was correct perhaps
12th May 2017, 12:32 PM
jay
jay - avatar
+ 10
yes. floating point values are never to be trusted to be whole numbers that 10 is like a 9.87657743 or something dumb
12th May 2017, 12:39 PM
jay
jay - avatar
+ 10
seeds of doubt were getting sown in my head lol.. glad we sorted it otherwise I would of gone a bit crazy! :) I was sure i thought correctly. but i guess the moral of the story here is assume nothing. investigate everything
12th May 2017, 12:51 PM
jay
jay - avatar
+ 9
lol its bugging me now too lol
12th May 2017, 12:21 PM
jay
jay - avatar
+ 9
https://code.sololearn.com/c86d015HFYVY/?ref=app check this.. maybe thats it there
12th May 2017, 12:30 PM
jay
jay - avatar
+ 8
Think I found the answer.. if any datatype in a formula is floating point/double type all types are converted to this for the calculation http://www.brighthub.com/computing/linux/articles/11239.aspx
12th May 2017, 12:18 PM
jay
jay - avatar
+ 8
what happens if they are done seperately? convert pow function. store that. then do the multiply?
12th May 2017, 12:22 PM
jay
jay - avatar
+ 8
true words!
15th May 2017, 3:26 AM
jay
jay - avatar
+ 7
So the conclusion is if we store a double value to int, no matter whether it is integer or decimal, some of the data is still lost.
12th May 2017, 12:38 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 6
I suggest you don't use power function for ints, as the numbers get messed up during conversion from double to int and so lose some precision. If you save this in a double, you will get 600, not 599. Eg - Trying pow(5,2) usually returns 24, but 5*5 always returns 25... This is just a case of lost precision, as 5.0*5.0 is taken by the PC as 4.999 and 4.999 and their product is 24.999867 which is floored for int conversion to 24 and given to you... IDK why that happens, but this is why the answers are wrong... So, please try forcing the result to be of type double or float...
15th May 2017, 3:14 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 5
But all the variable are int except "pow" and if i convert it implicitly to int then it further reduces to 6*100=594
12th May 2017, 12:20 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 5
Let me try it
12th May 2017, 12:23 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 5
@jay I think the difference lies in implicit type conversion, because as in your code the double variable gives exact answer but in my code integer variable gives wrong answer.
12th May 2017, 12:26 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 4
No progress, still the same results.
12th May 2017, 12:24 PM
Rishabh Agrawal
Rishabh Agrawal - avatar