From daecc6b7ee246bc7c28ec85f3a9a77d545967bd4 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 12 Dec 2023 10:47:46 +0100 Subject: [PATCH] Add example construction from int and exp --- doc/decimal.adoc | 3 ++- doc/decimal/examples.adoc | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 doc/decimal/examples.adoc diff --git a/doc/decimal.adoc b/doc/decimal.adoc index 141989d8a..588659878 100644 --- a/doc/decimal.adoc +++ b/doc/decimal.adoc @@ -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: @@ -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[] diff --git a/doc/decimal/examples.adoc b/doc/decimal/examples.adoc new file mode 100644 index 000000000..ed92e1c2c --- /dev/null +++ b/doc/decimal/examples.adoc @@ -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 +#include + +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; +} +----