Giter Site home page Giter Site logo

units's Introduction

MBa Units

A small units library supporting intregral powers of kilogram, meter and seconds and - spearate from that - angles in rad

Here is a simple example, of how this can be used

#include <mba-units/units.hpp>
#include <mba-units/fmt.hpp>

#include <iostream>

using namespace mba;

constexpr units::UPos distance_traveled( units::USpeed v, units::UAccel a, units::UTime t )
{
	return t * v + 0.5 * a * square( t );
	// equivalent:
	// return t * v +  a * t * t / 2.0
}

using namespace mba::units::litterals;

constexpr auto initial_speed = 2.0_mps;
constexpr auto acceleration  = units::UAccel{1.0};

int main()
{

	constexpr auto dist = distance_traveled( initial_speed, acceleration, 3.0_s );
	static_assert( dist == 10.5_m );

	std::cout << "With an initial speed of " << sformat( initial_speed ) << " and an acceleration of "
			  << sformat( acceleration ) << " we will travel " << sformat( dist ) << " in " << sformat( 3.0_s )
			  << std::endl;

/**
 * Prints:
 *
 * With an initial speed of 2m_s^-1 and an acceleration of 1m_s^-2 we will travel 10.5m in 3s
 *
 */

// Compile time error examples
#if 0
	auto wrong_order = distance_traveled( acceleration, initial_speed, 3.0_s );
#endif

#if 0
	auto strange = acceleration + initial_speed;
#endif
}

units's People

Contributors

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