I suggest you ...

Add "decimal" support to the standard C++ library

Among the most challenging problems in a financial system is dealing with numeric precision.

Take this example for instance (using the double data type in C++):
We have a number 4.3599999999999994 which we withdraw the same negative number from (4.3599999999999977), we would then end up with the number 1.7763568394002505e-015. Hence, if we were testing if the number added up to 0, we would get "False", or "True" if we were testing if the number was greater than "0".

This could easily get the system into an unwanted "IF" statement,
and tracking down these unwanted "IF" statements can be difficult.

Since C++ is used in many financial systems where accurate numeric precision is required, it seems reasonable to add "decimal" support to the standard C++ library.

77 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Anonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    5 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Andy BolstridgeAndy Bolstridge commented  ·   ·  Flag as inappropriate

        Agreed, if you want a standard C++ decimal type, write one and submit it to Boost, or appeal to the C++ committee. In the meantime, use a 64-bit int, store pennies (or fractions of) in there.

      • JeffJeff commented  ·   ·  Flag as inappropriate

        I think this is a great idea.

        Almost all languages support decimal floating point arithmetic.
        Java by java.math.BigDecimal, Python by decimal.Decimal, Ruby by BigDecimal and .NET by System.Decimal which is also accessible in C# as decimal.

        The document ISO/IEC TR 24733 specifies an extension for the programming language C++ to support decimal floating-point arithmetic.

        Unfortunately, the Decimal TR (ISO/IEC TR 24733) was not accepted into C++11. However, there is already a proposal N3407 to add decimal floating point support to the C++ standard. The proposal indicates to accept it for C++17.

        Hopefully Decimal TR (ISO/IEC TR 24733) will be provided by the C++ Standard Library shipped with Visual C++ as soon as possible.

        The GNU C compiler already supports decimal floating types as defined in the N1312 draft of ISO/IEC WDTR24732.

      • Brian WebbBrian Webb commented  ·   ·  Flag as inappropriate

        Google C++ Decimal Struct. There are open source decimals that are structs. They are all integer based, with an N coefficient, which is what you want when you don't want a float.

        Or use the .NET one in System.

      • ta.speot.ista.speot.is commented  ·   ·  Flag as inappropriate

        I'd -1 this if I could, if you want to change the standard C++ libraries give some feedback to the C++ standards comittee.

      Feedback and Knowledge Base