Coder Social home page Coder Social logo

physunits's Introduction

# PhysUnits

This is a Python module aiming at easily representing and manipulating numerical values that have an associated physical unit.

### How to use

All you have to do is declare your variable by calling the constructor:

x = PhysUnit(3.25, 'm')

Then x represents 3.25m, and you can do all traditional operations on x as if it was an int or float.
Note that the unit is a string and then requires to be inside quotes.
To have a list of available methods, try help(PhysUnit).

Examples

You can start from the following minimal examples to understand the module.

from PhysUnits import PhysUnit as pu
x = pu(3.5, 'm')
y = pu(0.5, 's')
print(x/y)

The above should print 7 m.s^-1.

Functionnalities

Here is a (probably not exhaustive) list of what you can do with PhysUnits.

  • All the arithmetic operations (+, -, *, /, **), if they make sense in the context. For instance, + will generate an error if the variables you are trying to sum do not have the same unit. But you can do a + 5 if a is a PhysUnit with no unit.
    Integer arithmetic (%, // etc.) is not supported, but please create an issue if you think it should.
  • All the assignment operators associated with the above supported operations. You can for instance do a **= 2 to directly store in a the result of a**2.
  • All the comprarison operators (>=, <=,>, <, ==, !=) with the condition that the two operands have the same unit.
  • Unary operators: -, +, abs.
  • The print_Latex() method does what its name tells: return the Latex code that represents your variable. It is a method, so to use it do a.print_Latex(). If you want to get the string without printing it (for instance to export it in a file), use __str_Latex__ instead.

physunits's People

Contributors

kr0kspluish avatar

Stargazers

Turner John avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.