Skip to content

Commit

Permalink
Flushed out tests and the rest of encoding (BID)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAD committed May 9, 2020
1 parent c363b0b commit 9ec5431
Show file tree
Hide file tree
Showing 13 changed files with 1,374 additions and 615 deletions.
42 changes: 36 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ ver 0.1.0
:alt: repo.support
:target: https://repo.support/gh/JohnAD/decimal128

This library creates a data type called Decimal128 that allows one to do
store and manipulated decimal numbers.
This library creates a data type called ``Decimal128`` that allows one to
store and manipulate decimal numbers.

By storing number as decimal digits you can avoid the ambiguity and rounding
By storing a number as decimal digits you can avoid the ambiguity and rounding
errors encountered when converting values back-and-forth from binary floating
point numbers such as the 64-bit floats used by Nim.
point numbers (base 2) and the decimal notation typically used by humans (base 10).

This is especially useful for applications that are not tolerant of such
rounding errors such as accounting, banking, and finance.

STANDARD
--------
STANDARD USED
-------------

The specification specifically conforms to the IEEE 754-2008 standard that
is formally available at https://standards.ieee.org/standard/754-2008.html
Expand All @@ -38,6 +38,36 @@ for serializing and unserializing from binary images.

The BID method is used by BSON and MongoDB.

EXAMPLES OF USE
--------------

.. code:: nim
import decimal128
let a = newDecimal128("4003.250")
assert a.getPrecision == 7
assert a.toFloat == 4003.25
assert a.toInt == 4003
assert $a == "4003.250"
assert a === newDecimal128("4003250E-3")
assert a === newDecimal128("4.003250E+3")
# interpret a segment of data from a BSON file:
let b = decodeDecimal128("2FF83CD7450BE3F39FA2D32880000000", encoding=ceBID)
assert $b == "0.001234000000000000000000000000000000"
assert b.getPrecision == 34
assert b.toFloat == 0.001234
Expand Down
2 changes: 1 addition & 1 deletion docnimble.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rst_dir": "rst/",
"doc_src_dir": "",
"nimble_file": "decimal128.nimble",
"files_to_ignore": ["src/uint113.nim", "src/dpd.nim", "src/const.nim"]
"files_to_ignore": ["src/decimal128/uint113.nim", "src/decimal128/dpd.nim"]
}
Loading

0 comments on commit 9ec5431

Please sign in to comment.