You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All examples can be found in the library `examples/` folder as well.
12
12
13
13
[#examples_construction]
14
-
== Basic construction
15
-
16
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/basic_construction.cpp[basic_construction.cpp]
17
-
14
+
== Basic Construction
15
+
.This example demonstrates the basic use of the various constructors offered by the decimal types
16
+
====
18
17
[source, c++]
19
18
----
20
19
include::example$basic_construction.cpp[]
21
20
----
22
21
23
-
The expected output from this example is:
24
-
----
22
+
.Expected Output
23
+
....
25
24
Val_1: 100
26
25
Val_2: 100
27
26
Val_3: -100
@@ -30,58 +29,60 @@ Underflow constructs zero
30
29
NaN constructs NaN
31
30
Values constructed from const char* and std::string are the same
32
31
Can not construct from invalid string
33
-
----
32
+
....
33
+
====
34
34
35
35
[#examples_promotion]
36
36
== Promotion and Mixed Decimal Arithmetic
37
37
38
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/promotion.cpp[promotion.cpp]
39
-
38
+
.This example demonstrates the behaviors of promotion between types, and mixed decimal type arithmetic
39
+
====
40
40
[source, c++]
41
41
----
42
42
include::example$promotion.cpp[]
43
43
----
44
44
45
-
Expected Output:
46
-
----
45
+
.Expected Output:
46
+
....
47
47
decimal32_t value (a): 5.2
48
48
decimal64_t value (b): 3.9
49
49
a is greater than b
50
50
5.2 is less than 1e+385
51
51
1e+385 is now less than inf
52
52
The result of a + b is a decimal64_t: 9.1
53
-
----
53
+
....
54
+
====
54
55
55
56
[#examples_charconv]
56
57
== `<charconv>`
57
58
58
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/charconv.cpp[charconv.cpp]
59
-
59
+
.This example demonstrates the fundamentals of the `<charconv>` like functions provided by the library
60
+
====
60
61
[source, c++]
61
62
----
62
63
include::example$charconv.cpp[]
63
64
----
64
65
65
-
Output:
66
-
----
66
+
.Expected Output:
67
+
....
67
68
Initial decimal: -7123450
68
69
Value from string: 3.1415
69
70
Value in scientific format: -7.12345e+06
70
71
Value in scientific format with precision 20: -7.12345000000000000000e+06
71
-
----
72
+
....
73
+
====
72
74
73
75
[#examples_generic_programming]
74
76
== Generic Programming
75
-
76
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/adl.cpp[adl.cpp].
77
-
77
+
.This example demonstrates how to write generic code that accepts both built-in floating point types, and decimal floating point values from this library
78
+
====
78
79
[source, c++]
79
80
----
80
81
include::example$adl.cpp[]
81
82
----
82
83
83
84
Expected Output:
84
-
----
85
+
....
85
86
Float:
86
87
sin(-0.5) = -0.479426
87
88
-sin(0.5) = -0.479426
@@ -137,8 +138,8 @@ pass:[{fmt}] support is available starting with pass:[C++14] so long as you have
137
138
[#examples_fmt_format]
138
139
=== `<fmt/format.hpp>`
139
140
140
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/fmt_format.cpp[fmt_format.cpp].
141
-
141
+
.This example demonstrates the various formatting options provided by the library to support usage of pass:[{fmt}]
142
+
====
142
143
[source, c++]
143
144
----
144
145
// Copyright 2025 Matt Borland
@@ -184,7 +185,7 @@ int main()
184
185
----
185
186
186
187
Expected Output:
187
-
----
188
+
....
188
189
Default Format:
189
190
3.14
190
191
3.141
@@ -200,7 +201,8 @@ Scientific Format with Specified Precision:
200
201
Scientific Format with Specified Precision and Padding:
201
202
03.140e+00
202
203
03.141e+00
203
-
----
204
+
....
205
+
====
204
206
205
207
IMPORTANT: If you are using the convenience header `<boost/decimal.hpp>` the header `<boost/decimal/fmt_format.hpp>` is *NOT* automatically included since it requires an external library.
206
208
You must include it yourself.
@@ -209,15 +211,16 @@ You must include it yourself.
209
211
=== `<format>`
210
212
211
213
Taking the above example of pass:[{fmt}] and replacing all instances of `namespace fmt` with `namespace std` gives us another working example.
212
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/format.cpp[format.cpp]
213
214
215
+
.This example demonstrates how to use `<format>` with the library in-place or in addition to pass:[{fmt}]
216
+
====
214
217
[source, c++]
215
218
----
216
219
include::example$format.cpp[]
217
220
----
218
221
219
-
Expected Output:
220
-
----
222
+
.Expected Output:
223
+
....
221
224
Default Format:
222
225
3.14
223
226
3.141
@@ -233,16 +236,13 @@ Scientific Format with Specified Precision:
233
236
Scientific Format with Specified Precision and Padding:
234
237
03.140e+00
235
238
03.141e+00
236
-
----
239
+
....
240
+
====
237
241
238
242
239
243
[#examples_print]
240
-
== `<print>`
241
-
242
-
We can make one final change to our `<format>` example where instead of using `std::cout`, we use pass:[C++23's] `<print>`.
243
-
This example can be found in the `examples/` folder as https://github.com/cppalliance/decimal/blob/develop/examples/print.cpp[print.cpp].
244
-
245
-
.`<print>` Example
244
+
=== `<print>`
245
+
.This example demonstrates how to use `<print>` with the library
0 commit comments