update
This commit is contained in:
3
phoenix/deps/decimal/.formatter.exs
Normal file
3
phoenix/deps/decimal/.formatter.exs
Normal file
@@ -0,0 +1,3 @@
|
||||
[
|
||||
inputs: ["{bench,mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
||||
BIN
phoenix/deps/decimal/.hex
Normal file
BIN
phoenix/deps/decimal/.hex
Normal file
Binary file not shown.
150
phoenix/deps/decimal/CHANGELOG.md
Normal file
150
phoenix/deps/decimal/CHANGELOG.md
Normal file
@@ -0,0 +1,150 @@
|
||||
# CHANGELOG
|
||||
|
||||
## v2.3.0 (2024-12-13)
|
||||
|
||||
* Implement the upcoming [`JSON.Encoder`](https://hexdocs.pm/elixir/main/JSON.Encoder.html)
|
||||
protocol
|
||||
|
||||
## v2.2.0 (2024-11-13)
|
||||
|
||||
* Add `Decimal.gte?/2` and `Decimal.lte?/2`
|
||||
* Add `Decimal.compare/3` and `Decimal.eq?/3` with threshold as parameter
|
||||
|
||||
## v2.1.1 (2023-04-26)
|
||||
|
||||
Decimal v2.1 requires Elixir v1.8+.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Fix `Decimal.compare/2` when comparing against `0`
|
||||
|
||||
## v2.1.0 (2023-04-26)
|
||||
|
||||
Decimal v2.1 requires Elixir v1.8+.
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Improve error message from `Decimal.to_integer/1` during precision loss
|
||||
* `Inspect` protocol implementation returns strings in the `Decimal.new(...)` format
|
||||
* Add `Decimal.scale/1`
|
||||
* Optimize `Decimal.compare/2` for numbers with large exponents
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Fix `Decimal.integer?/1` spec
|
||||
* Fix `Decimal.integer?/1` check on 0 with >1 significant digits
|
||||
|
||||
## v2.0.0 (2020-09-08)
|
||||
|
||||
Decimal v2.0 requires Elixir v1.2+.
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add `Decimal.integer?/1`
|
||||
|
||||
### Breaking changes
|
||||
|
||||
* Change `Decimal.compare/2` to return `:lt | :eq | :gt`
|
||||
* Change `Decimal.cast/1` to return `{:ok, t} | :error`
|
||||
* Change `Decimal.parse/1` to return `{t, binary} | :error`
|
||||
* Remove `:message` and `:result` fields from `Decimal.Error`
|
||||
* Remove sNaN
|
||||
* Rename qNaN to NaN
|
||||
* Remove deprecated support for floats in `Decimal.new/1`
|
||||
* Remove deprecated `Decimal.minus/1`
|
||||
* Remove deprecated `Decimal.plus/1`
|
||||
* Remove deprecated `Decimal.reduce/1`
|
||||
* Remove deprecated `Decimal.with_context/2`, `Decimal.get_context/1`, `Decimal.set_context/1`,
|
||||
and `Decimal.update_context/1`
|
||||
* Remove deprecated `Decimal.decimal?/1`
|
||||
|
||||
### Deprecations
|
||||
|
||||
* Deprecate `Decimal.cmp/2`
|
||||
|
||||
## v1.9.0 (2020-09-08)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add `Decimal.negate/1`
|
||||
* Add `Decimal.apply_context/1`
|
||||
* Add `Decimal.normalize/1`
|
||||
* Add `Decimal.Context.with/2`, `Decimal.Context.get/1`, `Decimal.Context.set/2`,
|
||||
and `Decimal.Context.update/1`
|
||||
* Add `Decimal.is_decimal/1`
|
||||
|
||||
### Deprecations
|
||||
|
||||
* Deprecate `Decimal.minus/1` in favour of the new `Decimal.negate/1`
|
||||
* Deprecate `Decimal.plus/1` in favour of the new `Decimal.apply_context/1`
|
||||
* Deprecate `Decimal.reduce/1` in favour of the new `Decimal.normalize/1`
|
||||
* Deprecate `Decimal.with_context/2`, `Decimal.get_context/1`, `Decimal.set_context/2`,
|
||||
and `Decimal.update_context/1` in favour of new functions on the `Decimal.Context` module
|
||||
* Deprecate `Decimal.decimal?/1` in favour of the new `Decimal.is_decimal/1`
|
||||
|
||||
## v1.8.1 (2019-12-20)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Fix Decimal.compare/2 with string arguments
|
||||
* Set :signal on error
|
||||
|
||||
## v1.8.0 (2019-06-24)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add `Decimal.cast/1`
|
||||
* Add `Decimal.eq?/2`, `Decimal.gt?/2`, and `Decimal.lt?/2`
|
||||
* Add guards to `Decimal.new/3` to prevent invalid Decimal numbers
|
||||
|
||||
## v1.7.0 (2019-02-16)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add `Decimal.sqrt/1`
|
||||
|
||||
## v1.6.0 (2018-11-22)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Support for canonical XSD representation on `Decimal.to_string/2`
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix exponent off-by-one when converting from decimal to float
|
||||
* Fix negative?/1 and positive?/1 specs
|
||||
|
||||
### Deprecations
|
||||
|
||||
* Deprecate passing float to `Decimal.new/1` in favor of `Decimal.from_float/1`
|
||||
|
||||
## v1.5.0 (2018-03-24)
|
||||
|
||||
### Enhancements
|
||||
|
||||
* Add `Decimal.positive?/1` and `Decimal.negative?/1`
|
||||
* Accept integers and strings in arithmetic functions, e.g.: `Decimal.add(1, "2.0")`
|
||||
* Add `Decimal.from_float/1`
|
||||
|
||||
### Soft deprecations (no warnings emitted)
|
||||
|
||||
* Soft deprecate passing float to `new/1` in favor of `from_float/1`
|
||||
|
||||
## v1.4.1 (2017-10-12)
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Include the given value as part of the error reason
|
||||
* Fix `:half_even` `:lists.last` bug (empty signif)
|
||||
* Fix error message for round
|
||||
* Fix `:half_down` rounding error when remainder is greater than 5
|
||||
* Fix `Decimal.new/1` float conversion with bigger precision than 4
|
||||
* Fix precision default value
|
||||
|
||||
## v1.4.0 (2017-06-25)
|
||||
|
||||
### Bugfixes
|
||||
|
||||
* Fix `Decimal.to_integer/1` for large coefficients
|
||||
* Fix rounding of ~0 values
|
||||
* Fix errors when comparing and adding two infinities
|
||||
176
phoenix/deps/decimal/LICENSE.txt
Normal file
176
phoenix/deps/decimal/LICENSE.txt
Normal file
@@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
207
phoenix/deps/decimal/README.md
Normal file
207
phoenix/deps/decimal/README.md
Normal file
@@ -0,0 +1,207 @@
|
||||
# Decimal
|
||||
|
||||
Arbitrary precision decimal arithmetic.
|
||||
|
||||
## Concept
|
||||
|
||||
Decimal represents values internally using three integers: a sign, a coefficient, and an exponent.
|
||||
In this way, numbers of any size and with any number of decimal places can be represented exactly.
|
||||
|
||||
```elixir
|
||||
Decimal.new(_sign = 1, _coefficient = 42, _exponent = 0) #=> Decimal.new("42")
|
||||
Decimal.new(-1, 42, 0) #=> Decimal.new("-42")
|
||||
Decimal.new(1, 42, -1) #=> Decimal.new("4.2")
|
||||
Decimal.new(1, 42, -20) #=> Decimal.new("4.2E-19")
|
||||
Decimal.new(1, 42, 20) #=> Decimal.new("4.2E+21")
|
||||
Decimal.new(1, 123456789987654321, -9) #=> Decimal.new("123456789.987654321")
|
||||
```
|
||||
|
||||
For calculations, the amount of desired precision - that is, the number of
|
||||
decimal digits in the coefficient - can be specified.
|
||||
|
||||
## Usage
|
||||
|
||||
Add Decimal as a dependency in your `mix.exs` file:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[{:decimal, "~> 2.0"}]
|
||||
end
|
||||
```
|
||||
|
||||
Next, run `mix deps.get` in your shell to fetch and compile `Decimal`. Start an
|
||||
interactive Elixir shell with `iex -S mix`:
|
||||
|
||||
```elixir
|
||||
iex> alias Decimal, as: D
|
||||
iex> D.add(6, 7)
|
||||
Decimal.new("13")
|
||||
iex> D.div(1, 3)
|
||||
Decimal.new("0.3333333333333333333333333333")
|
||||
iex> D.new("0.33")
|
||||
Decimal.new("0.33")
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Using the context
|
||||
|
||||
The context specifies the maximum precision of the result of calculations and
|
||||
the rounding algorithm if the result has a higher precision than the specified
|
||||
maximum. It also holds the list of trap enablers and the current set
|
||||
flags.
|
||||
|
||||
The context is stored in the process dictionary. You don't have to pass the
|
||||
context around explicitly and the flags will be updated automatically.
|
||||
|
||||
The context is accessed with `Decimal.Context.get/0` and set with
|
||||
`Decimal.Context.set/1`. It can be set temporarily with
|
||||
`Decimal.Context.with/2`.
|
||||
|
||||
```elixir
|
||||
iex> D.Context.get()
|
||||
%Decimal.Context{flags: [:rounded, :inexact], precision: 9, rounding: :half_up,
|
||||
traps: [:invalid_operation, :division_by_zero]}
|
||||
|
||||
iex> D.Context.with(%D.Context{precision: 2}, fn -> IO.inspect D.Context.get() end)
|
||||
%Decimal.Context{flags: [], precision: 2, rounding: :half_up,
|
||||
traps: [:invalid_operation, :division_by_zero]}
|
||||
%Decimal.Context{flags: [], precision: 2, rounding: :half_up,
|
||||
traps: [:invalid_operation, :division_by_zero]}
|
||||
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | traps: []})
|
||||
:ok
|
||||
|
||||
iex> D.Context.get()
|
||||
%Decimal.Context{flags: [:rounded, :inexact], precision: 9, rounding: :half_up,
|
||||
traps: []}
|
||||
```
|
||||
|
||||
### Precision and rounding
|
||||
|
||||
Use `:precision` option to limit the amount of decimal digits in the
|
||||
coefficient of any calculation result:
|
||||
|
||||
```elixir
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | precision: 9})
|
||||
:ok
|
||||
|
||||
iex> D.div(100, 3)
|
||||
Decimal.new("33.3333333")
|
||||
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | precision: 2})
|
||||
:ok
|
||||
|
||||
iex> D.div(100, 3)
|
||||
Decimal.new("33")
|
||||
```
|
||||
|
||||
The `:rounding` option specifies the algorithm and precision of the rounding
|
||||
operation:
|
||||
|
||||
```elixir
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | rounding: :half_up})
|
||||
:ok
|
||||
|
||||
iex> D.div(31, 2)
|
||||
Decimal.new("16")
|
||||
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | rounding: :floor})
|
||||
:ok
|
||||
|
||||
iex> D.div(31, 2)
|
||||
Decimal.new("15")
|
||||
```
|
||||
|
||||
### Comparisons
|
||||
|
||||
Using comparison operators (`<`, `=`, `>`) with two or more decimal digits may
|
||||
not produce accurate result. Instead, use comparison functions.
|
||||
|
||||
```elixir
|
||||
iex> D.compare(-1, 0)
|
||||
:lt
|
||||
iex> D.compare(0, -1)
|
||||
:gt
|
||||
iex> D.compare(0, 0)
|
||||
:eq
|
||||
|
||||
iex> D.equal?(-1, 0)
|
||||
false
|
||||
iex> D.equal?(0, "0.0")
|
||||
true
|
||||
```
|
||||
|
||||
### Flags and trap enablers
|
||||
|
||||
When an exceptional condition is signalled, its flag is set in the current
|
||||
context. `Decimal.Error` will be raised if the trap enabler is set.
|
||||
|
||||
```elixir
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | rounding: :floor, precision: 2})
|
||||
:ok
|
||||
|
||||
iex> D.Context.get().traps
|
||||
[:invalid_operation, :division_by_zero]
|
||||
|
||||
iex> D.Context.get().flags
|
||||
[]
|
||||
|
||||
iex> D.div(31, 2)
|
||||
Decimal.new("15")
|
||||
|
||||
iex> D.Context.get().flags
|
||||
[:inexact, :rounded]
|
||||
```
|
||||
|
||||
`:inexact` and `:rounded` flag were signalled above because the result of the
|
||||
operation was inexact given the context's precision and had to be rounded to
|
||||
fit the precision. `Decimal.Error` was not raised because the signals' trap
|
||||
enablers weren't set.
|
||||
|
||||
```elixir
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | traps: D.Context.get().traps ++ [:inexact]})
|
||||
:ok
|
||||
|
||||
iex> D.div(31, 2)
|
||||
** (Decimal.Error)
|
||||
```
|
||||
|
||||
The default trap enablers, such as `:division_by_zero`, can be unset:
|
||||
|
||||
```elixir
|
||||
iex> D.Context.get().traps
|
||||
[:invalid_operation, :division_by_zero]
|
||||
|
||||
iex> D.div(42, 0)
|
||||
** (Decimal.Error)
|
||||
|
||||
iex> D.Context.set(%D.Context{D.Context.get() | traps: [], flags: []})
|
||||
:ok
|
||||
|
||||
iex> D.div(42, 0)
|
||||
Decimal.new("Infinity")
|
||||
|
||||
iex> D.Context.get().flags
|
||||
[:division_by_zero]
|
||||
```
|
||||
|
||||
### Mitigating rounding errors
|
||||
|
||||
TODO
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2013 Eric Meadows-Jönsson
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
14
phoenix/deps/decimal/hex_metadata.config
Normal file
14
phoenix/deps/decimal/hex_metadata.config
Normal file
@@ -0,0 +1,14 @@
|
||||
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/ericmj/decimal">>}]}.
|
||||
{<<"name">>,<<"decimal">>}.
|
||||
{<<"version">>,<<"2.3.0">>}.
|
||||
{<<"description">>,<<"Arbitrary precision decimal arithmetic.">>}.
|
||||
{<<"elixir">>,<<"~> 1.8">>}.
|
||||
{<<"app">>,<<"decimal">>}.
|
||||
{<<"licenses">>,[<<"Apache-2.0">>]}.
|
||||
{<<"requirements">>,[]}.
|
||||
{<<"files">>,
|
||||
[<<"lib">>,<<"lib/decimal">>,<<"lib/decimal/error.ex">>,
|
||||
<<"lib/decimal/context.ex">>,<<"lib/decimal/macros.ex">>,
|
||||
<<"lib/decimal.ex">>,<<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>,
|
||||
<<"LICENSE.txt">>,<<"CHANGELOG.md">>]}.
|
||||
{<<"build_tools">>,[<<"mix">>]}.
|
||||
2106
phoenix/deps/decimal/lib/decimal.ex
Normal file
2106
phoenix/deps/decimal/lib/decimal.ex
Normal file
File diff suppressed because it is too large
Load Diff
125
phoenix/deps/decimal/lib/decimal/context.ex
Normal file
125
phoenix/deps/decimal/lib/decimal/context.ex
Normal file
@@ -0,0 +1,125 @@
|
||||
defmodule Decimal.Context do
|
||||
import Decimal.Macros
|
||||
alias Decimal.Context
|
||||
|
||||
@moduledoc """
|
||||
The context is kept in the process dictionary. It can be accessed with
|
||||
`get/0` and `set/1`.
|
||||
|
||||
The default context has a precision of 28, the rounding algorithm is
|
||||
`:half_up`. The set trap enablers are `:invalid_operation` and
|
||||
`:division_by_zero`.
|
||||
|
||||
## Fields
|
||||
|
||||
* `precision` - maximum number of decimal digits in the coefficient. If an
|
||||
operation result has more digits it will be rounded to `precision`
|
||||
digits with the rounding algorithm in `rounding`.
|
||||
* `rounding` - the rounding algorithm used when the coefficient's number of
|
||||
exceeds `precision`. Strategies explained below.
|
||||
* `flags` - a list of signals that for which the flag is sent. When an
|
||||
exceptional condition is signalled its flag is set. The flags are sticky
|
||||
and will be set until explicitly cleared.
|
||||
* `traps` - a list of set trap enablers for signals. When a signal's trap
|
||||
enabler is set the condition causes `Decimal.Error` to be raised.
|
||||
|
||||
## Rounding algorithms
|
||||
|
||||
* `:down` - round toward zero (truncate). Discarded digits are ignored,
|
||||
result is unchanged.
|
||||
* `:half_up` - if the discarded digits is greater than or equal to half of
|
||||
the value of a one in the next left position then the coefficient will be
|
||||
incremented by one (rounded up). Otherwise (the discarded digits are less
|
||||
than half) the discarded digits will be ignored.
|
||||
* `:half_even` - also known as "round to nearest" or "banker's rounding". If
|
||||
the discarded digits is greater than half of the value of a one in the
|
||||
next left position then the coefficient will be incremented by one
|
||||
(rounded up). If they represent less than half discarded digits will be
|
||||
ignored. Otherwise (exactly half), the coefficient is not altered if it's
|
||||
even, or incremented by one (rounded up) if it's odd (to make an even
|
||||
number).
|
||||
* `:ceiling` - round toward +Infinity. If all of the discarded digits are
|
||||
zero or the sign is negative the result is unchanged. Otherwise, the
|
||||
coefficient will be incremented by one (rounded up).
|
||||
* `:floor` - round toward -Infinity. If all of the discarded digits are zero
|
||||
or the sign is positive the result is unchanged. Otherwise, the sign is
|
||||
negative and coefficient will be incremented by one.
|
||||
* `:half_down` - if the discarded digits is greater than half of the value
|
||||
of a one in the next left position then the coefficient will be
|
||||
incremented by one (rounded up). Otherwise (the discarded digits are half
|
||||
or less) the discarded digits are ignored.
|
||||
* `:up` - round away from zero. If all discarded digits are zero the
|
||||
coefficient is not changed, otherwise it is incremented by one (rounded
|
||||
up).
|
||||
|
||||
This table shows the results of rounding operations for all the rounding
|
||||
algorithms:
|
||||
|
||||
Rounding algorithm | 5.5 | 2.5 | 1.6 | 1.1 | 1.0 | -1.0 | -1.1 | -1.6 | -2.5 | -5.5
|
||||
:----------------- | :-- | :-- | :-- | :-- | :-- | :--- | :--- | :--- | :--- | :---
|
||||
`:up` | 6 | 3 | 2 | 2 | 1 | -1 | -2 | -2 | -3 | -6
|
||||
`:down` | 5 | 2 | 1 | 1 | 1 | -1 | -1 | -1 | -2 | -5
|
||||
`:ceiling` | 6 | 3 | 2 | 2 | 1 | -1 | -1 | -1 | -2 | -5
|
||||
`:floor` | 5 | 2 | 1 | 1 | 1 | -1 | -2 | -2 | -3 | -6
|
||||
`:half_up` | 6 | 3 | 2 | 1 | 1 | -1 | -1 | -2 | -3 | -6
|
||||
`:half_down` | 5 | 2 | 2 | 1 | 1 | -1 | -1 | -2 | -2 | -5
|
||||
`:half_even` | 6 | 2 | 2 | 1 | 1 | -1 | -1 | -2 | -2 | -6
|
||||
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
precision: pos_integer,
|
||||
rounding: Decimal.rounding(),
|
||||
flags: [Decimal.signal()],
|
||||
traps: [Decimal.signal()]
|
||||
}
|
||||
|
||||
defstruct precision: 28,
|
||||
rounding: :half_up,
|
||||
flags: [],
|
||||
traps: [:invalid_operation, :division_by_zero]
|
||||
|
||||
@context_key :"$decimal_context"
|
||||
|
||||
@doc """
|
||||
Runs function with given context.
|
||||
"""
|
||||
doc_since("1.9.0")
|
||||
@spec with(t(), (-> x)) :: x when x: var
|
||||
def with(%Context{} = context, fun) when is_function(fun, 0) do
|
||||
old = Process.put(@context_key, context)
|
||||
|
||||
try do
|
||||
fun.()
|
||||
after
|
||||
set(old || %Context{})
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets the process' context.
|
||||
"""
|
||||
doc_since("1.9.0")
|
||||
@spec get() :: t()
|
||||
def get() do
|
||||
Process.get(@context_key, %Context{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Set the process' context.
|
||||
"""
|
||||
doc_since("1.9.0")
|
||||
@spec set(t()) :: :ok
|
||||
def set(%Context{} = context) do
|
||||
Process.put(@context_key, context)
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
Update the process' context.
|
||||
"""
|
||||
doc_since("1.9.0")
|
||||
@spec update((t() -> t())) :: :ok
|
||||
def update(fun) when is_function(fun, 1) do
|
||||
get() |> fun.() |> set()
|
||||
end
|
||||
end
|
||||
24
phoenix/deps/decimal/lib/decimal/error.ex
Normal file
24
phoenix/deps/decimal/lib/decimal/error.ex
Normal file
@@ -0,0 +1,24 @@
|
||||
defmodule Decimal.Error do
|
||||
@moduledoc """
|
||||
The exception that all decimal operations may raise.
|
||||
|
||||
## Fields
|
||||
|
||||
* `signal` - the signalled error, additional signalled errors will be found
|
||||
in the context.
|
||||
* `reason` - the reason for the error.
|
||||
|
||||
Rescuing the error to access the result or the other fields of the error is
|
||||
discouraged and should only be done for exceptional conditions. It is more
|
||||
pragmatic to set the appropriate traps on the context and check the flags
|
||||
after the operation if the result needs to be inspected.
|
||||
"""
|
||||
|
||||
defexception [:signal, :reason]
|
||||
|
||||
@impl true
|
||||
def message(%{signal: signal, reason: reason}) do
|
||||
reason = reason && ": " <> reason
|
||||
"#{signal}#{reason}"
|
||||
end
|
||||
end
|
||||
11
phoenix/deps/decimal/lib/decimal/macros.ex
Normal file
11
phoenix/deps/decimal/lib/decimal/macros.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule Decimal.Macros do
|
||||
@moduledoc false
|
||||
|
||||
defmacro doc_since(version) do
|
||||
if Version.match?(System.version(), ">= 1.7.0") do
|
||||
quote do
|
||||
@doc since: unquote(version)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
43
phoenix/deps/decimal/mix.exs
Normal file
43
phoenix/deps/decimal/mix.exs
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule Decimal.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
@version "2.3.0"
|
||||
@source_url "https://github.com/ericmj/decimal"
|
||||
|
||||
def project() do
|
||||
[
|
||||
app: :decimal,
|
||||
version: @version,
|
||||
elixir: "~> 1.8",
|
||||
deps: deps(),
|
||||
name: "Decimal",
|
||||
source_url: @source_url,
|
||||
docs: [source_ref: "v#{@version}", main: "readme", extras: ["README.md"]],
|
||||
description: description(),
|
||||
package: package()
|
||||
]
|
||||
end
|
||||
|
||||
def application() do
|
||||
[]
|
||||
end
|
||||
|
||||
defp deps() do
|
||||
[
|
||||
{:ex_doc, ">= 0.0.0", only: :dev},
|
||||
{:stream_data, "~> 0.5.0", only: :test}
|
||||
]
|
||||
end
|
||||
|
||||
defp description() do
|
||||
"Arbitrary precision decimal arithmetic."
|
||||
end
|
||||
|
||||
defp package() do
|
||||
[
|
||||
maintainers: ["Eric Meadows-Jönsson"],
|
||||
licenses: ["Apache-2.0"],
|
||||
links: %{"GitHub" => @source_url}
|
||||
]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user