Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.73k stars 141 forks source link

Percentage weirdness / addition commutativity #242

Open sw opened 3 years ago

sw commented 3 years ago

This may have been introduced with #75. I think I remember the behaviour was different in an older version, but can't say which.

Observed behaviour with 2.8.2-1build3 on Xubuntu:

$ qalc '1%+2%, 2%+1%'
[(1 * percent) * (102 * percent), (2 * percent) * (101 * percent)] = [0.0102, 0.0202]

Expected behaviour (I guess?):

$ qalc '1%+2%, 2%+1%'
[(1 * percent) + (2 * percent), (2 * percent) + (1 * percent)] = [0.03, 0.03]

I understand the reasoning given by @juanfra684 in #75, but in my case it just seems wrong, because commutativity of addition is violated.

hanna-kn commented 3 years ago

This is standard calculator behaviour. The handling of addition to percentage does however vary, and I've now changed the behaviour so that ordinary addition is performed when the first term includes percent (e.g. 10 + 20% = 12, but 10% + 20% = 30% = 0.3).

hanna-kn commented 3 years ago

See also https://github.com/Qalculate/libqalculate/issues/208#issuecomment-658897138