|
10 | 10 |
|
11 | 11 | --- |
12 | 12 |
|
13 | | -Decimal is an implementation of IEEE-754:2008 decimal floating point numbers. |
14 | | -See also [1]. |
15 | | - |
16 | | -The library is header-only, and requires C++14. |
17 | | -It is compatible through C++14, 17, 20, 23 and beyond. |
18 | | - |
19 | | -# Notice |
20 | | - |
21 | | -Decimal is under active development and is not an official boost library. |
| 13 | +Boost.Decimal is an implementation of [IEEE 754](https://standards.ieee.org/ieee/754/6210/) and [ISO/IEC DTR 24733](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2849.pdf) Decimal Floating Point numbers. |
| 14 | +The library is header-only, has no dependencies, and requires C++14. |
22 | 15 |
|
23 | 16 | # How To Use The Library |
24 | 17 |
|
@@ -95,78 +88,11 @@ class decimal_fast128_t; |
95 | 88 | These types operate like built-in floating point types. |
96 | 89 | They have their own implementations of the Standard-Library functions |
97 | 90 | (e.g. like those found in `<cmath>`, `<charconv>`, `<cstdlib>`, etc.). |
98 | | - |
99 | 91 | The entire library can be conveniently included with `#include <boost/decimal.hpp>` |
100 | 92 |
|
101 | | -Using the decimal types is simple. |
102 | | - |
103 | | -```cpp |
104 | | -#include <boost/decimal.hpp> |
105 | | -#include <iostream> |
106 | | - |
107 | | -int main() |
108 | | -{ |
109 | | - using boost::decimal::decimal32_t; |
110 | | - |
111 | | - constexpr decimal32_t a {2, -1}; // Constructs the number 0.2 |
112 | | - constexpr decimal32_t b {1, -1}; // Constructs the number 0.1 |
113 | | - auto sum {a + b}; |
114 | | - |
115 | | - std::cout << sum << std::endl; // prints 0.3 |
116 | | - |
117 | | - const auto neg_a {2, -1, true}; // Constructs the number -0.2 |
118 | | - |
119 | | - sum += neg_a; |
120 | | - |
121 | | - std::cout << sum << std::endl; // Prints 0.1 |
122 | | - |
123 | | - return 0; |
124 | | -} |
125 | | -``` |
126 | | - |
127 | | -This intuitive straightforwardness is the same when using Standard-Library |
128 | | -functions (such as STL functions, `<cmath>` functions and the like). |
129 | | - |
130 | | -```cpp |
131 | | -#include <boost/decimal.hpp> |
132 | | -#include <cassert> |
133 | | -#include <cstring> |
134 | | - |
135 | | -int main() |
136 | | -{ |
137 | | - using namespace boost::decimal; |
138 | | - |
139 | | - decimal64_t val {-0.25}; // Construction from a double |
140 | | - val = abs(val); // DO NOT call std::abs |
141 | | - |
142 | | - char buffer[256]; |
143 | | - auto r_to = to_chars(buffer, buffer + sizeof(buffer) - 1, val); |
144 | | - assert(r_to); // checks std::errc() |
145 | | - *r_to.ptr = '\0'; |
146 | | - |
147 | | - decimal64_t return_value; |
148 | | - auto r_from = from_chars(buffer, buffer + std::strlen(buffer), return_value); |
149 | | - |
150 | | - assert(val == return_value); |
151 | | - |
152 | | - return 0; |
153 | | -} |
154 | | -``` |
| 93 | +Using the decimal types is simple and can be learned by [example](https://develop.decimal.cpp.al/decimal/examples.html). |
| 94 | +Their usage closely resembles that of built-in binary floating point types by design. |
155 | 95 |
|
156 | 96 | # Full Documentation |
157 | 97 |
|
158 | 98 | The complete documentation can be found at: https://develop.decimal.cpp.al |
159 | | - |
160 | | -## References |
161 | | - |
162 | | -- Michael F. Cowlishaw [_Floating-Point: Algorism(sic) for Computers_](https://www.cs.tufts.edu/~nr/cs257/archive/mike-cowlishaw/decimal-arith.pdf_Decimal), Proceedings of the 16th IEEE Symposium on Computer Arithmetic, 2003 |
163 | | - |
164 | | -- Donald E. Knuth, _The Art of Computer Programming Volume 2 Seminumerical Algorithms_, 3rd edition, 1998 |
165 | | - |
166 | | -- Jean-Michel Muller, _Elementary Functions_, 3rd edition, 2010 |
167 | | - |
168 | | -- Jean-Michel Muller, et. al., _Handbook of Floating-Point Arithmetic_, 2000 |
169 | | - |
170 | | -- John F. Hart, et. al., _Computer Approximations_, 1968 |
171 | | - |
172 | | -- IEEE, _IEEE Standard for Floating-Point Arithmetic_, 2019 |
0 commit comments