-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #359 from cppalliance/docs
Add example construction from int and exp to docs
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
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
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,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; | ||
} | ||
---- |