sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.29k stars 53 forks source link

Inconsistencies with associativity of multiplication. #637

Open dex-k opened 1 month ago

dex-k commented 1 month ago

Hi, I just came across Numbat from this post, and went to try it out. After skimming the documentation, I tried to do a currency conversion:

>>> 1 usd * ( aud / usd )

  1 dollar × (australian_dollar / dollar)

      = 1 AUD    [Money]

>>> aud / usd

  australian_dollar / dollar

      = 0.665332

>>> 1 usd * 0.665332

  1 dollar × 0.665332

      = 0.665332 $    [Money]

>>> 1 * usd * (aud/usd)

  1 dollar × (australian_dollar / dollar)

      = 1 AUD    [Money]

>>> 1 * (aud/usd) * usd

  1 × (australian_dollar / dollar) × dollar

      = 0.665332 $    [Money]

Having read the (seemingly) relevant parts of the documentation again, I don't understand why all of the former snippets don't evaluate to the same result. Is this intended behaviour?

Goju-Ryu commented 1 month ago

This looks a bit odd. I think it might be associated with the issues discussed following this comment on another issue.

And just in case you are unaware, it looks like you are trying to convert between currencies which is much more easily done this way: 1 usd -> aud or with the keyword to instead of the arrow if you prefer.

dex-k commented 1 month ago

Thank you, that's helpful to know.