numbas / numbas-extension-quantities

A Numbas extension providing functions to handle amounts with units
Other
0 stars 0 forks source link

Failure to simplify some unitless quantities #5

Closed JoshuaCapel closed 5 years ago

JoshuaCapel commented 5 years ago

I was playing around trying to fix an issue with the quantities extension and found some unusual behavior which I cannot fix. These issue occur even if you include my pull request earlier today (https://github.com/numbas/numbas-extension-quantities/pull/4).

The expression 1/quantity(1,"m")*quantity(1,"cm") will become 1 cm/m instead of 0.01 as might be expected. You can also see this problem with the simpler command quantity(1,"cm/m").

More concerning is that the expression quantity(1,"cm/m")*quantity(1,"") becomes 100 cm^2/m^2, and quantity(1,"cm/m")*quantity(1,"")*quantity(1,"") becomes 1000000 cm^4/m^4.

These are actually technically correct (all being the same as 0.01), but it is not what I would have expected.

Adding in another unit prevents the second problem. For example quantity(1,"kg*cm/m")*quantity(1,"") is just 1 kg cm/m (so not simplified, but no strange powers appearing).

Based on these observations it seem the problem is somehow related to unitless quantities.

JoshuaCapel commented 5 years ago

I had a chance to play around with js-quantities and the issue exists there (https://github.com/gentooboontoo/js-quantities/issues/94). So that means this extension is just working as expected.

christianp commented 5 years ago

I've submitted a pull request fixing this to js-quantities, so we'll see if it's accepted. I'm reopening this to remind me to update the extension.

christianp commented 5 years ago

Now fixed in js-quantities v1.7.3, and I've updated this extension