GithubHelp home page GithubHelp logo

moneycpp's Introduction

Hi there ๐Ÿ‘‹

My name is Marius Bฤƒncilฤƒ. I'm a developer, architect, author, speaker passionate about programming, mainly working with C++ and C# and related technologies. I'm a Microsoft MVP for developer technologies.

CPP CS DOTNET Microsoft

๐Ÿ‘จโ€๐Ÿ’ป What I do is:

๐Ÿ“š My books:

Modern C++ Programming Cookbook, 3rd Edition Template Metaprogramming with C++ Modern C++ Programming Cookbook, 2nd Edition The Modern C++ Challenge Learn C# Programming Modern C++ Programming Cookbook, 1st Edition

๐Ÿ’ฌ How to reach me:

Twitter Linkedin

moneycpp's People

Contributors

mariusbancila avatar ruipires avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

moneycpp's Issues

Add complete set of arithmetic operations

It would be good to be able to use money objects arithmetically unimpeded using math libraries such as xtensor or DataFrame. To provide a concrete example of something that's not currently supported, would be finding the standard deviation of a timeseries of money objects:

std::vector<money> population {{5.0, currency::USD}, {10.0, currency::USD}, {30.0, currency::USD}};
money std_dev = sqrt((1/population.size()) * sum(pow(population - mean(population)), 2.0));

The element of this calculation not currently supported is the pow operation. This can't be easily computed using addition (though it can), but providing the multiplication overload for two money types would drastically improve the ease of a calculation such as this:

template <typename TValue1>
inline auto operator*(money<TValue1> const & lhs, money<TValue1> const & rhs)

Understandably only the TValue2 overload has been implemented for this, as the result of money * money doesn't necessarily make a lot of sense - the result isn't necessarily a sensible value that represents money. However, these kinds of operations are essential in performing any kind of data analysis.

Additional overloads that would be useful:

  • operator*(TValue2, money) - so that the float doesn't have to be the second argument - i.e. moneyVal * 2.0 and 2.0 * moneyVal are both valid statements
  • operator/(money, money)
  • operator/(TValue2, money)
  • operator%(money, money)
  • operator%(TValue2, money)
  • operator+=(TValue2)
  • operator+=(money)
  • operator-=(TValue2)
  • operator-=(money)
  • operator*=(TValue2)
  • operator*=(money)
  • operator\=(TValue2)
  • operator\=(money)
  • operator<<(stream, money) - It would be good to be able to convert money objects to strings for debugging/output

It may also be necessary to implement proxy functions for some of the std math functions: std::pow, std::sqrt, std::sin, etc.

One complication to consider here is that I think it's probably prudent to ensure that these operations are all homogeneous. You could have heterogeneous calculations in which you do conversions between currencies on the fly, but especially for the operations in which a new money object is generated, there would be ambiguity around which currency the result should be denominated in. The calculation is exactly the same, the result is exactly the same, so it actually doesn't matter which currency is assigned to the object, but for the sake of consistency and type safety I think that it would be prudent to throw an error if the currencies of the money objects in a multiplication or a division are not the same. I can see that you've done this for the equality operator so it seems that this perspective is consistent with yours.

idea: expand to allow for std::decimal

gcc's libstdc++ includes std::decimal64, a compact 64-bit, exact decimal representation for money values.

It would be nice if moneycpp were expanded to allow for std::decimal32, std::decimal64, and std::decimal128 as the representational type.

References:
specifications
code

Make find_country_currency in country_currency.h inline

I think you forgot to make find_country_currency inline.

If not inline, since this is a header-only library, you would get multiple definitions of find_country_currency during linking if the file is included in multiple compilation unit (cpp files). #pragma once won't help in this case.

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.