connorferster / forallpeople

Python SI units library: your 'daily driver' for calculations.
Apache License 2.0
307 stars 40 forks source link

Force different unit system for output #14

Closed JBloss1517 closed 4 years ago

JBloss1517 commented 4 years ago

Is there a way to change the units that are returned from an equation? I am using the structural environment and have an equation where all of the parameters are in us imperial units (ksi, psi, inch) but the equation returns units of mm. The library is returning the correct dimension (length) but is no longer following the imperial system. Is there an easy way to change the output system?

image

connorferster commented 4 years ago

Yes, you can do:

a = (A_s*f_y/(0.85*f_prime_c*b)).to('inch')

or

a = A_s*f_y/(0.85*f_prime_c*b)
a = a.to('inch')
JBloss1517 commented 4 years ago

Oh nice! Thank you. When working in conjunction with your handcalcs library, is there a more elegant solution to hiding the "to('inch')" part than to use

%%render
a =A_s*f_y/(0.85*f_prime_c*b)
a = (a.to('inch'))

image image

connorferster commented 4 years ago

No, not yet :sob:

However, I am surprised that the factor did not carry through to produce a inch as the final result. I will look into that. The idea is that your result should be in inch without an extra conversion step. I think it has to do with the tolerance I set up on how factors carry. Because of floating point precision, every multiplicative operation between Physical instances with a .factor degrades the carried factor which reduces the likelihood that the factor at the end will be recognized and the Physical will be represented with the corresponding unit.

This is something to fix. I will open a new issue in regards to this. Thank you for posting.

JBloss1517 commented 4 years ago

Gotcha that makes sense. Thanks for creating such a great library!