Giter VIP home page Giter VIP logo

unithorse's Introduction

UnitHorse πŸ“πŸ΄

Unit conversion library for .NET

Why Am I Doing This?

I have had a great time learning F#. I wanted the experience of making a simple, high-quality F# library to get some practice.

Background

Let's talk about units for a minute. What is a unit of measurement? Well, it's a way to express a quantity. The SI System defines units for these quantities:

  • electric current
  • temperature
  • time
  • length
  • mass
  • luminous intensity
  • amount of substance

Converting between two units can be done with a function where the values of the parameters are determined by the source and target units. For a quantity like temperature, 0ΒΊC is not the same as 0ΒΊF. Perhaps you have seen the function to convert from Celsius to Fahrenheit:

let convertToF degreesC = 9./5. * degreesC + 32.

Converting between two different units of measure for the temperature quantity must take an offset and a slope into account. So, we have a function to convert between 2 different specific units in a single direction. To perform the opposite conversion, we need another function.Β  C --> F F --> C For 2 units of measure, we need 2 functions. Saw we want to add Kelvin (K) to the mix. Now we have: C --> F, C --> K F --> C, F --> K K --> C, K --> F For 3 units of measure, we need 6 functions. How about Rankine (R)? C --> F, C --> K, C --> R F --> C, F --> K, F --> R K --> C, K --> F, K --> R R --> C, R --> F, R --> K

For 4 units of measure, we need 24 functions. I'm not writing those. That's n factorial functions! For length, 0 is 0 is 0. Said another way, 0 US Survey Feet is the same as 0 meters. Perhaps you're thinking of the y = ax + b from school. In the case of length, there is no 'b' or offset term, just different slopes, 'a'. So, what would such a function look like?Β  let convert value source target = value * source / target Let's talk about length. Some common units for length are the meter and the US Survey Foot, defined as 1200/2927 meters https://en.wikipedia.org/wiki/Foot_(unit)#US_survey_foot. Is 0 meters the same as 0 feet? Yes, it is. Length is nice in that two different length units differ only in their slope, not their offset.

unithorse's People

Contributors

brettrowberry avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

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