-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
419 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: '*' | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
permissions: | ||
actions: write | ||
contents: write | ||
pull-requests: read | ||
statuses: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: '1' | ||
- uses: julia-actions/cache@v2 | ||
- name: Install dependencies | ||
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
- name: Build and deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: julia --project=docs/ docs/make.jl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*.cov | ||
|
||
docs/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[deps] | ||
Decimals = "abce61dc-4473-55a0-ba07-351d65e31d42" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Decimals | ||
using Documenter | ||
|
||
makedocs(sitename="Decimals.jl", | ||
pages=["index.md", | ||
"operations.md"]) | ||
deploydocs(repo="github.com/JuliaMath/Decimals.jl.git", | ||
push_preview=true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Development | ||
|
||
### Standard tests | ||
|
||
There is a standard test suite called | ||
[DecTests](https://speleotrove.com/decimal/dectest.html). The test suite is | ||
provided in a [custom format](https://speleotrove.com/decimal/dtfile.html). We | ||
have a script `scripts/dectest.jl` for translating test cases from the custom | ||
format to common Julia tests. The script should be called like this: | ||
``` | ||
julia scripts/dectest.jl <testset name> <dectest path> <output path> | ||
``` | ||
For example: | ||
`julia scripts/dectest.jl Plus dectests/plus.decTest test/dectests/test_plus.jl`. | ||
We put these test files into the `test/dectests` subdirectory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
```@meta | ||
DocTestSetup = quote | ||
using Decimals | ||
end | ||
``` | ||
|
||
# Introduction | ||
|
||
This package is a Julia implementation of arbitrary precision decimal floating | ||
point arithmetic, where numbers $x \in \mathbb{R}$ are represented using the | ||
`Decimal` type as | ||
```math | ||
x = (-1)^s \cdot c \cdot 10^q, | ||
``` | ||
where $s \in \{0, 1\}$ is the signbit, $c \in \mathbb{N}$ is the coefficient, and $q \in \mathbb{Z}$ is the exponent. | ||
|
||
|
||
## Construction | ||
|
||
The `Decimal` object can be created directly, or by conversion from a number, | ||
or by parsing from a string: | ||
|
||
```jldoctest | ||
julia> Decimal(0, 5, -1) # (-1)^0 * 5 * 10^-1 | ||
0.5 | ||
julia> Decimal(0.5) | ||
0.5 | ||
julia> Decimal(5E-1) | ||
0.5 | ||
julia> parse(Decimal, "0.5") | ||
0.5 | ||
julia> parse(Decimal, "5E-1") | ||
0.5 | ||
``` | ||
|
||
Alternatively, a `Decimal` can be parsed from a string literal via the | ||
`@dec_str` macro, which also supports the thousands separator `_`: | ||
```jldoctest | ||
julia> dec"1_000.000_000_1" | ||
1000.0000001 | ||
``` | ||
The thousands separator is not supported by the `parse` function: | ||
```jldoctest | ||
julia> parse(Decimal, "1_000") | ||
ERROR: ArgumentError: Invalid decimal: 1_000 | ||
``` | ||
|
||
!!! warning "Conversion from numbers is exact" | ||
The constructor `Decimal(::Real)` converts the given number to a `Decimal` | ||
exactly. The consequence is that `Decimal(x)` is not generally equal to | ||
`parse(Decimal, string(x))`. For example, | ||
```jldoctest | ||
julia> Decimal(0.1) | ||
0.1000000000000000055511151231257827021181583404541015625 | ||
|
||
julia> parse(Decimal, "0.1") | ||
0.1 | ||
|
||
julia> dec"0.1" # Alternative to parse | ||
0.1 | ||
|
||
julia> big(0.1) # Exact value of 0.1 represented by a binary floating-point number | ||
0.1000000000000000055511151231257827021181583404541015625 | ||
|
||
julia> string(0.1) # The string representation of 0.1 is deceiving | ||
"0.1" | ||
``` | ||
|
Oops, something went wrong.