Skip to content

Commit

Permalink
Merge pull request #359 from cppalliance/docs
Browse files Browse the repository at this point in the history
Add example construction from int and exp to docs
  • Loading branch information
mborland authored Dec 12, 2023
2 parents e9964c3 + daecc6b commit b6092e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/decimal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////

# Decimal: IEEE 754 Decimal Floating Point Numbers
= Decimal: IEEE 754 Decimal Floating Point Numbers
:toc: left
:toclevels: 4
:idprefix:
Expand All @@ -24,6 +24,7 @@ include::decimal/cmath.adoc[]
include::decimal/cstdlib.adoc[]
include::decimal/cfenv.adoc[]
include::decimal/config.adoc[]
include::decimal/examples.adoc[]
//include::decimal/reference.adoc[]
include::decimal/design.adoc[]
include::decimal/copyright.adoc[]
Expand Down
34 changes: 34 additions & 0 deletions doc/decimal/examples.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
////
Copyright 2023 Matt Borland
Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////

[#Examples]
= Examples
:idprefix: examples_

== Construction from an Integer and Exponent

[source, c++]
----
#include <boost/decimal.hpp>
#include <iostream>
int main()
{
constexpr boost::decimal::decimal32 a {2, -1}; // Constructs the number 0.2
constexpr boost::decimal::decimal32 b {1, -1}; // Constructs the number 0.1
boost::decimal::decimal32 sum {a + b};
std::cout << sum << std::endl; // prints 0.3
const boost::decimal::decimal32 neg_a {2, -1, true}; // Constructs the number -0.2
sum += neg_a;
std::cout << sum << std::endl; // Prints 0.1
return 0;
}
----

0 comments on commit b6092e9

Please sign in to comment.