+ 4
[BUG] maybe or please explain me if I'm wrong
15 Answers
+ 13
Yeah. SL is buggy af
Found out today morning
Drove me nuts lol
+ 10
my original theory was correct perhaps
+ 10
yes. floating point values are never to be trusted to be whole numbers that 10 is like a 9.87657743 or something dumb
+ 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
+ 9
lol its bugging me now too lol
+ 9
https://code.sololearn.com/c86d015HFYVY/?ref=app
check this.. maybe thats it there
+ 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
+ 8
what happens if they are done seperately?
convert pow function. store that. then do the multiply?
+ 8
true words!
+ 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.
+ 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...
+ 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
+ 5
Let me try it
+ 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.
+ 4
No progress, still the same results.