"### __EXERCISE 8: Multiplication by an integer__\n",
"### __EXERCISE 8: Multiplication by an integer__\n",
"\n",
"\n",
"Write the `Multiply()` function that computes the approximate product of a real by an integer coefficient and returns an integer. \n",
"Write the `Multiply()` function that calculates the product of an approximated real by an integer coefficient and returns an integer. \n",
"\n",
"\n",
"*Reminder*: a real is approximated by `numerator / 2^exponent`; your function should rely upon `ComputePowerOf2Approx()` and `TimesPowerOf2()` functions.\n",
"*Reminder*: a real is approximated by `numerator / 2^exponent`; your function should rely upon `ComputePowerOf2Approx()` and `TimesPowerOf2()` functions.\n",
"\n",
"\n",
...
@@ -87,7 +87,12 @@
...
@@ -87,7 +87,12 @@
"source": [
"source": [
"### __EXERCISE 9: display sum of two Multiply__\n",
"### __EXERCISE 9: display sum of two Multiply__\n",
"\n",
"\n",
"Write a `DisplaySumOfMultiply` function which will write the computation of the sum of two real numbers through their approximation (see expected result below)\n",
"Write a `DisplaySumOfMultiply` function which will write the computation of the sum of two approximated real numbers that have each been multiplied by a different integer coefficient.\n",
"\n",
"The function is expected to compute and display the following:\n",
# [Getting started in C++](./) - [Procedural programming](./0-main.ipynb) - [Hands-on 3](./7b-hands-on.ipynb)
# [Getting started in C++](./) - [Procedural programming](./0-main.ipynb) - [Hands-on 3](./7b-hands-on.ipynb)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### __EXERCISE 8: Multiplication by an integer__
### __EXERCISE 8: Multiplication by an integer__
Write the `Multiply()` function that computes the approximate product of a real by an integer coefficient and returns an integer.
Write the `Multiply()` function that calculates the product of an approximated real by an integer coefficient and returns an integer.
*Reminder*: a real is approximated by `numerator / 2^exponent`; your function should rely upon `ComputePowerOf2Approx()` and `TimesPowerOf2()` functions.
*Reminder*: a real is approximated by `numerator / 2^exponent`; your function should rely upon `ComputePowerOf2Approx()` and `TimesPowerOf2()` functions.
The arguments of `Multiply()` are the maximum number of bits for approximation, the real and the integer coefficient.
The arguments of `Multiply()` are the maximum number of bits for approximation, the real and the integer coefficient.
The new main will be:
The new main will be:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` C++17
``` C++17
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
Write a `DisplaySumOfMultiply` function which will write the computation of the sum of two real numbers through their approximation (see expected result below)
Write a `DisplaySumOfMultiply` function which will write the computation of the sum of two approximated real numbers that have each been multiplied by a different integer coefficient.
The function is expected to compute and display the following:
### [optional] __EXERCISE 11: write in output file__
### [optional] __EXERCISE 11: write in output file__
Modify the program so that the `DisplayPowerOf2Approx` and `DisplaySumOfMultiply` functions take an additional argument: the output stream to which the content should be written.
Modify the program so that the `DisplayPowerOf2Approx` and `DisplaySumOfMultiply` functions take an additional argument: the output stream to which the content should be written.
The following `main()` which writes part of the outputs in a file should work:
The following `main()` which writes part of the outputs in a file should work:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` C++17
``` C++17
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)