Comments (5)
decimal_diff.txt
This fixes the issue, I think (credits go to my collegue Clemens Misch)
from decimal_for_cpp.
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.
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.
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.
Updated code accordingly. Please see unit test decimalTypeLevel and readme for more information.
from decimal_for_cpp.
Related Issues (20)
- Problem with overflow detection with CLANG compiler.. HOT 1
- incorrect constructing from fp HOT 5
- How does it stand against Muller's recursion ? HOT 2
- specify decimal separator HOT 2
- Make it fully trivial HOT 3
- Suggest using constexpr HOT 1
- Is it compatible with IEEE 754-2008? HOT 2
- Modulo operator HOT 2
- is there a way to perform assigment from std::string? HOT 1
- how to get an int/double from dec type ? HOT 3
- signal SIGSEGV, Segmentation fault on return HOT 2
- Still C++11 stuff when DEC_NO_CPP11 is defined HOT 1
- format_from_stream truncates its return value from decimal_format to basic_decimal_format HOT 3
- Enhancement: More friendly constructor HOT 1
- support for power and root ? HOT 1
- Edge cases failing HOT 1
- how to initialize in struct declaration HOT 4
- Need support to wstring HOT 1
- macos build is failing HOT 1
- unable to change precision of existing variable HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decimal_for_cpp.