Fuel consumption unit conversion doesn't work for some unit combination. Discovered using KRunner Unit Converter plugin. Expected values: 100 mpg (US) = 2.35215 l/100km 10 l/100 km = 23.5215 mpg (US) 20 kmpl = 5 l/100km Actual values: 100 mpg (US) = 0.4251700680272109 l/100km 10 l/100 km = 2351.9999999999995 mpg (US) 20 kmpl = 0.2 l/100km Given that kmpl to mpg conversion is correct (20kmpl = 47.04mpg) I guess that just l/100km is incorrect. I've used Google Unit Conversion for checking the values (like "https://www.google.com/search?q=100 mpg to l/100km")
Created attachment 105098 [details] Screenshot from KRunner
I doubt KUnitConversion handles reciprocals, so either the units should get removed, or some major rework is needed.
*** Bug 387959 has been marked as a duplicate of this bug. ***
It seems KUnitConversion cannot handle an inverse fraction. n mpg = 253 / n l/100km The code tries to do "something" in that direction by overriding toDefault()/fromDefault() but that clearly breaks in one or other form (either mpg→l/100km or, if you fix that, mpg→mpgi and mpg→km/l)
For those interested, please review the following patch https://phabricator.kde.org/D20284
Git commit bc7495095baa7a70e756c4d2044de2197d1a4e3b by Albert Astals Cid, on behalf of Michal Malý. Committed on 14/04/2019 at 15:59. Pushed by aacid into branch 'master'. Fix l/100 km to MPG conversion Summary: Previous code (probably) worked only for l/100 km -> MPG but not the other way around. Fix this by using reciprocal conversion when necessary. Output: 38.7 MPG -> 6.077 l/100 km; 16.455 km/l; 46.482 MPGI 16.455 km/l -> 6.077 l/100 km; 38.7 MPG 46.48 MPGI -> 6.077 l/100 km Seems good to me. Reviewers: broulik, #frameworks, aacid Subscribers: apol, aacid, meven, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D20284 M +20 -0 autotests/convertertest.cpp M +23 -9 src/fuel_efficiency.cpp https://commits.kde.org/kunitconversion/bc7495095baa7a70e756c4d2044de2197d1a4e3b