[!SPOILER FOR TEST CASE!]Doubt in perf-test case 6

The perf-test case 6 input is 0.9999999995343387

According to this shouldn’t the output be ERROR?

1 Like

Wolframalpha is one the most advanced arithmetic best softwares out there without a doubt. However, languages like C++ , Python and JAVA dont have the same kind of precision while performing floating point multiplication. To know more about Floating point arithmetic errors click here .

Hence for the given input, on following the proper decimal to binary conversion algorithm , the input value on repeated multiplication converges for the given output.

Hence in the given case the following output is observed:

Input : 0.9999999995343387
Output : 0.1111111111111111111111111111111

The fractional part of the given number after every successive multiplication by 2 is as follows:

0.9999999995343387 * 2 = 1.9999999990686774
0.9999999990686774 * 2 = 1.9999999981373549
0.9999999981373549 * 2 = 1.9999999962747097
0.9999999962747097 * 2 = 1.9999999925494194
0.9999999925494194 * 2 = 1.9999999850988388
0.9999999850988388 * 2 = 1.9999999701976776
0.9999999701976776 * 2 = 1.9999999403953552
0.9999999403953552 * 2 = 1.9999998807907104
0.9999998807907104 * 2 = 1.9999997615814209
0.9999997615814209 * 2 = 1.9999995231628418
0.9999995231628418 * 2 = 1.9999990463256836
0.9999990463256836 * 2 = 1.9999980926513672
0.9999980926513672 * 2 = 1.9999961853027344
0.9999961853027344 * 2 = 1.9999923706054688
0.9999923706054688 * 2 = 1.9999847412109375
0.9999847412109375 * 2 = 1.9999694824218750
0.9999694824218750 * 2 = 1.9999389648437500
0.9999389648437500 * 2 = 1.9998779296875000
0.9998779296875000 * 2 = 1.9997558593750000
0.9997558593750000 * 2 = 1.9995117187500000
0.9995117187500000 * 2 = 1.9990234375000000
0.9990234375000000 * 2 = 1.9980468750000000
0.9980468750000000 * 2 = 1.9960937500000000
0.9960937500000000 * 2 = 1.9921875000000000
0.9921875000000000 * 2 = 1.9843750000000000
0.9843750000000000 * 2 = 1.9687500000000000
0.9687500000000000 * 2 = 1.9375000000000000
0.9375000000000000 * 2 = 1.8750000000000000
0.8750000000000000 * 2 = 1.7500000000000000
0.7500000000000000 * 2 = 1.5000000000000000
0.5000000000000000 * 2 = 1.0000000000000000

NOTE : You can observe the error in floating point multiplication operations from the following table

2 Likes

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.