Coder Social home page Coder Social logo

metric's Introduction

metric - bringing SI to Nim

nimble

metric is a small library providing type-level dimensional analysis. It allows you to keep track of the physical units of your programs, and can be useful for writing scientific software.

Installation

metric has no non-standard dependencies. Just type nimble install metric and you're good to go.

A small usage example

import metric, strformat

## Let's open a block with a lot of miscellaneous units predefinded:
withUnits:
  var
    v0 = 40.0 * mile / hour # Some non-SI units of velocity.
  echo "v0 in miles per hour: ", fmt"{v0 as mile / hour} [mph]"
  echo "v0 in decimeters per fortnight: ",
    fmt"{v0 as dm / (2.0 * week)} [dm / fortnight]"
  echo "v0 in SI units: ", v0

As you can see, metric makes it easy to handle units, and never have to worry about keeping track of strange conversions.

Custom dimensions

metric provides the means to handle all dimensionful quantities under the SI system. Dimensions taken into consideration are:

  • Length
  • Time
  • Mass
  • Amount
  • Temperature
  • Current
  • Intensity

Should you need different units, you can do that, by just defining them as object of BaseDimension, with the following procs and constants:

type
  MyDimension = object of BaseDimension

proc `$`(x: typedesc[MyDimension]): string = "mydim" ## \
  ## Define how you want your dimension's base unit to be pretty-printed.

const
  myUnitValue = Unit[MyDimension](val: 1.0) ## The name does not matter here.

With those things defined, you are good to use your units in the same way, as the built-ins.

metric's People

Contributors

mjendrusch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

elcritch

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.