Code Monkey home page Code Monkey logo

Comments (5)

mteske avatar mteske commented on June 9, 2024

decimal_diff.txt
This fixes the issue, I think (credits go to my collegue Clemens Misch)

from decimal_for_cpp.

vpiotr avatar vpiotr commented on June 9, 2024

Hi, thanks for this fix.

This is good direction but there are some issues to be considered:

  • there should be compilation error in this case: p4 += p8
  • this compilation error must be meaningful
  • m_value is preferred over getUnbiased, the latter is an API method for persistence

from decimal_for_cpp.

mteske avatar mteske commented on June 9, 2024

Hi,
thanks for the reply. If I understand you correct, p4 += p8 should give a compilation error because you possibly lose precision? This might depend on the use case, for my task the (pre-existing) code that rounds the result is fine. Ideally one could configure the behaviour with a template parameter.
We had to use getUnbiased() because else the compiler would complain about m_value being private.
We forgot assignment operators, I have it fixed here, it's done in a similar way.

from decimal_for_cpp.

vpiotr avatar vpiotr commented on June 9, 2024

Hi,

There are the following common rules for this lib:

  • on value copy execution without data loss is preferred (see constructor with string argument)
  • when p4 is mixed with another p4, rounding occurs automatically
  • when p4 is mixed with p8, it is possible only if there is no rounding, otherwise you should explicit specify (using decimal_cast) when and how the rounding should be executed.
  • so if you mix p8 and p4 and there is no requirement for rounding, statement can be compiled correctly (only if rounding detection can be performed at compile time)
  • and if you mix p8 and p4 without decimal_cast and rounding can happen, compilation error should occur

This is kind of "strong typing" which is helpful for decimal calculations in financial code.

from decimal_for_cpp.

vpiotr avatar vpiotr commented on June 9, 2024

Updated code accordingly. Please see unit test decimalTypeLevel and readme for more information.

from decimal_for_cpp.

Related Issues (20)

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.