GithubHelp home page GithubHelp logo

eweknits's Introduction

Eweknits

Eweknits (pronounced "YU-nihts", i.e., "units") is a library for creating and working with "units" (such as feet, grams, seconds, potrzebies, etc.), and "measures" (such as 30 days, 9.8 meters per second per second, 364.4 smoots, 123 furlongs per fortnight, etc.).

It provides some "base" units (such as seconds, inches, meters, ounces avoirdupoids, and grams), and some units made from combining them (such as newtons, horsepower, and kilowatt-hours).

Usage

You will probably mostly be creating and using measures.  These are created using Eweknits.measure/2.  The arguments are a numeric quantity and a unit.  For instance:

earth_gravity = Eweknits.measure(9.8, meter_per_second_squared)

Once you have a measure, you can add it to or subtract it from another measure of the same unit, and multiply or divide it by another measure or a number.  For instance:

# hurl something straight down at 3.1 m/s, on the moon,
# and how fast is it going after 4.5 seconds?
# (assuming we threw it from high enough!)
moon_gravity = earth_gravity / 6
initial_velocity = Eweknits.measure(3.1, meter_per_second)
falling_time = Eweknits.measure(4.5, second)
falling_velocity = initial_velocity + moon_gravity * falling_time

You can also create your own units by either just declaring it with Eweknits.unit/1, or multiplying or dividing an existing unit by another unit.  For instance:

newton = kilogram * meter / second / second
joule = newton * meter
watt = joule / second

Eweknits will automagically take care of ensuring that the resulting measure will have the correct unit.  For instance, if you divide a "foot" measure by a "second" measure, you will get a measure whose unit is "feet per second".

Limitations / Plans

At this time it does not handle scaled units (e.g., automatic conversion between feet and inches, let alone between feet and meters), vector units (such as true velocity as opposed to speed), nor unit conversions that require an offset (such as between degrees C, F, and K).  These features will most likely be added in that order.

It also does not yet search for extant units fitting a description.  So, if you do a calculation that results in, say, joules, and print out the results, it will print them out in terms of the base units and their exponents.  Eventually it may search a registry for some way to at least simplify the output.

Installation

If available in Hex, the package can be installed by adding eweknits to your list of dependencies in mix.exs:

def deps do
  [
    {:eweknits, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/eweknits.

eweknits's People

Contributors

davearonson 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.