Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplification of units #13

Closed
barche opened this issue Sep 5, 2016 · 2 comments
Closed

Simplification of units #13

barche opened this issue Sep 5, 2016 · 2 comments

Comments

@barche
Copy link

barche commented Sep 5, 2016

Hi,

Is there a way to simplify units that are the same, for example if I enter:

1J / (1N*m)

The result is:

1.0 m^-1 N^-1 J

I would have expected just 1.0, like when I do 1J / (1J)

This was on 0.5-rc3 using the master branch, is it recommended to use the rewrite branch instead?

@ajkeller34
Copy link
Collaborator

Units don't cancel out automatically, apart from powers of the same exact unit including power-of-ten prefixes. This permits expressions like micron/(meter * K), or mV/V, etc.

The rewrite branch will be the basis for the code going forward. A great deal has changed for the better. As you may have gathered from the other Unitful issues, I planned to register and tag Unitful shortly after Julia 0.5 is released. I guess this should happen very soon. However, I'm already nearly done with the revisions and will merge into master within a day or two. At that point the documentation for the rewrite branch will also appear online. I will solicit some community input in between merging and registering the package.

Anyway, to finally answer your question, in the rewrite branch, you will have two options: 1) you can directly convert a dimensionless quantity to a Real or Complex subtype of your choice, or 2) you can use uconvert. Formerly, I had been exploiting convert to do the work of unit conversion, which was ill-advised; now I define uconvert instead. You would use NoUnits as the target unit you want to convert to.

Neither of these options will work if the quantity has dimensions; an error exception is raised. When a quantity x has dimensions, you can access the number in front of the units by dividing out by unit(x), although some caution is warranted doing this sort of thing.

@barche
Copy link
Author

barche commented Sep 6, 2016

Thanks, this makes sense. I also just realized that for some of my work this is desirable, e.g. moist air water content in g/kg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants