Replies: 1 comment
-
Pint can handle complex arithmetic expressions, but not for defining units. In order to have a working unit system, you need to be able to go back and forth from one unit to the other. Out of the box, Pint is able to do that from a string definition with multiplicative, offset and logarithmic units. Pint does not now how to invert a polynomial equation. What you could do is create a new Converter class that allows you to specify how to convert back and from the referenced unit. Take a look at Converter, ScaleConverter and so on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using Pint in a project, where the base units are nearly enough. However, I have a few units that I'm creating myself. I'd rather have Pint do these conversions for me for consistency. Unfortunately, it seems pint is built on basic arithmetic. i.e. Can't use order-of-operations with parenthesis. Is there a way I can attach a function to a conversion?
This is what I'm trying to do, but can't using standard definitions:
So far so good. Now, let me add a complex conversion:
PINT_UNIT_REGISTER.define('Brix = (((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622) = bx')
The parser doesn't expect the order-of-operations. Is there some way I can do:
PINT_UNIT_REGISTER.define('Brix = MyClass.convert.toBrix(sg) = bx')
Or is there some extension to Pint I can leverage?
Beta Was this translation helpful? Give feedback.
All reactions