Skip to content

Commit ad06481

Browse files
committed
Add a basic README
[ci skip]
1 parent 0d87dfe commit ad06481

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,44 @@
44
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/edir9h23fs98jfjc/branch/master?svg=true)](https://ci.appveyor.com/project/omus/fixedpointdecimals-jl)
55
[![coveralls](https://coveralls.io/repos/github/JuliaMath/FixedPointDecimals.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/JuliaMath/FixedPointDecimals.jl?branch=master)
66
[![codecov.io](https://codecov.io/github/JuliaMath/FixedPointDecimals.jl/coverage.svg?branch=master)](https://codecov.io/github/JuliaMath/FixedPointDecimals.jl?branch=master)
7+
8+
Provides the fixed-point decimal type `FixedDecimal` allowing for exact representations of
9+
decimal numbers. These numbers are useful in financial calculations where interactions
10+
between decimal numbers are required to be exact.
11+
12+
This library defines the type `FixedDecimal{T <: Integer, f}` as a subtype of `Real`. The
13+
parameter `T` is the underlying machine representation and `f` is the number of decimal
14+
places which can be stored.
15+
16+
For example, `FixedDecimal{Int8, 2}` allows you to a decimal number with up to 2 fractional
17+
digits. All `FixedDecimal{Int8, 2}` numbers `x` must satisfy
18+
19+
```
20+
-1.28 = -128/10² ≤ x ≤ 127/10² = 1.27
21+
```
22+
23+
because the range of `Int8` is from -128 to 127.
24+
25+
In general `FixedDecimal{T <: Integer, f}` numbers `y` must satisfy:
26+
27+
```
28+
typemin(T)/10ᶠ ≤ y ≤ typemax(T)/10ᶠ
29+
```
30+
31+
## Usage
32+
33+
```julia
34+
julia> using FixedPointDecimals
35+
36+
julia> 2.2 / 10
37+
0.22000000000000003
38+
39+
julia> FixedDecimal{Int,2}(2.2) / 10
40+
FixedDecimal{Int64,2}(0.22)
41+
42+
julia> 0.1 + 0.2
43+
0.30000000000000004
44+
45+
julia> FixedDecimal{Int,1}(0.1) + FixedDecimal{Int,1}(0.2)
46+
FixedDecimal{Int64,1}(0.3)
47+
```

0 commit comments

Comments
 (0)