processing decimal numbers with mpdecimal as a backdrop
***I wrote this lib to free myself from arithmetic problems on large decimals***
[https://speleotrove.com/decimal/](https://speleotrove.com/decimal/)
This part explains why we need it.
Another source that inspired me and that joins what I think
[https://github.com/dnotq/decNumber](https://github.com/dnotq/decNumber)
---
**os linux**
**I don't have Windows or Macintosh but it should work **
[https://www.bytereef.org/mpdecimal/index.html](https://www.bytereef.org/mpdecimal/index.html)
const c = @cImport( { @cInclude("mpdecimal.h"); } );
installation with your package manager or download
validated: by https://speleotrove.com/decimal/
official site thank you for making this standardization available
---
→ 2023-02-27 add compare a, b = enum CMP. LT EQ LT
→ 2023-03-02 add ceil r = a
→ 2023-03-02 add rem r = a / b
→ 2023-03-02 result alignment with OS400
→ 2023-03-02 update debugPrint(cnbr: DCMLFX, txt : []const u8)
→ 2023-03-27 isOverfow -> isOverflow
→ 2023-03-27 test decimal 256 - 70 digit and 512 - 142 digit work bank international
CTX_ADDR Communication structure for default common control decimal128 -> MPD_ROUND_HALF_EVEN
openContex() :
it is possible, to have very very large numbers
disable c.mpd_ieee_context but you go out of the norm
DCMLFX includes 3 values
number: mpdecimal structure [*c]
integer: number of integers in front of the point
scale: number of integers behind the point
associated function:
def: checks the relevance of bounding with mpdecimal and determines the fixed decimal
Test if the context is active otherwise it calls openContext()
free: frees the associated memory storage ".number" (not the definition)
debugPrint: small followed by ".number"
isNumber: check value is compliant '0-9 + - .' compliant SQL postgres DB2...
isValide: uses isNumber, and checks if the external value complies with the boundary
isOverflow: check if the internal value is out of bounds
assign: give a value (text format) to ".number"
setZeros: forces the value 0 to ".number"
isZeros: checks if the value 0
round: two-function round and truncate (0.5 = +1) see finance...
trunc: to a function, truncate without rounding
string: if the scale part is larger than its definition,
it rounds then adds zeros if necessary
(respects the SQL display alignment standard on the left ex: 1.00)
add: a = a + b
sub: a = a - b
mul: a = a x b
div: a = a / b if b = zeros raises an error
addTo: r = a + b
subTo: r = a - b
mulTo: r = a x b
divto: r = a / b if b = zeros raises an error
floor: r = a
ceil : r = a
rem : r = a / b if b = zeros raises an error
rate: raises a value with the percentage ex ( n = (val x nbr) , val = (n x %1.25)
function off DCMLF
enum CMP LT EQ GT
cmp compare a ,b return CMP
mdrate module: returns ex: ttc , htx (base val, article nrb, rate = 25 ) practice in 5 operations
forceAssign: forces the value
dsperr: practical @panic product in test
debugContext: print context
← 2024-03-23 update change var const ...