Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b65209d4 authored by STEFF Laurent's avatar STEFF Laurent
Browse files

Merge branch 'math-link-handson' into 'master'

Updated floating points links in the Hand-On introduction

See merge request !53
parents 22c4d9a5 40a45176
No related branches found
No related tags found
1 merge request!53Updated floating points links in the Hand-On introduction
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# [Getting started in C++](./) - [Procedural programming](./0-main.ipynb) - [Hands-on 1](./4b-hands-on.ipynb) # [Getting started in C++](./) - [Procedural programming](./0-main.ipynb) - [Hands-on 1](./4b-hands-on.ipynb)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<h1>Table of contents<span class="tocSkip"></span></h1> <h1>Table of contents<span class="tocSkip"></span></h1>
<div class="toc"><ul class="toc-item"><li><span><a href="#Introduction" data-toc-modified-id="Introduction-1">Introduction</a></span><ul class="toc-item"><li><span><a href="#How-to-do-the-hands-on?" data-toc-modified-id="How-to-do-the-hands-on?-1.1">How to do the hands-on?</a></span></li><li><span><a href="#The-problem-we'll-deal-with-throughout-the-hands-ons" data-toc-modified-id="The-problem-we'll-deal-with-throughout-the-hands-ons-1.2">The problem we'll deal with throughout the hands-ons</a></span></li><li><span><a href="#EXERCICE-1:-Adding-a-loop" data-toc-modified-id="EXERCICE-1:-Adding-a-loop-1.3"><strong>EXERCICE 1: Adding a loop</strong></a></span></li></ul></li></ul></div> <div class="toc"><ul class="toc-item"><li><span><a href="#Introduction" data-toc-modified-id="Introduction-1">Introduction</a></span><ul class="toc-item"><li><span><a href="#How-to-do-the-hands-on?" data-toc-modified-id="How-to-do-the-hands-on?-1.1">How to do the hands-on?</a></span></li><li><span><a href="#The-problem-we'll-deal-with-throughout-the-hands-ons" data-toc-modified-id="The-problem-we'll-deal-with-throughout-the-hands-ons-1.2">The problem we'll deal with throughout the hands-ons</a></span></li><li><span><a href="#EXERCICE-1:-Adding-a-loop" data-toc-modified-id="EXERCICE-1:-Adding-a-loop-1.3"><strong>EXERCICE 1: Adding a loop</strong></a></span></li></ul></li></ul></div>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Introduction ## Introduction
### How to do the hands-on? ### How to do the hands-on?
This [notebook](../HandsOn/HowTo.ipynb) explains very briefly your options to run the hands-ons. This [notebook](../HandsOn/HowTo.ipynb) explains very briefly your options to run the hands-ons.
### The problem we'll deal with throughout the hands-ons ### The problem we'll deal with throughout the hands-ons
Any real number can be approximated by the ratio between two integers. Any real number can be approximated by the ratio between two integers.
We will choose here to approximate any real `r` by an expression `numerator / 2^exponent`, where both `numerator` and `exponent` are integers. We will choose here to approximate any real `r` by an expression `numerator / 2^exponent`, where both `numerator` and `exponent` are integers.
The higher the numerator and exponent values, the more accurate the approximation can be. For example, 0.65 can be approximated successively by: The higher the numerator and exponent values, the more accurate the approximation can be. For example, 0.65 can be approximated successively by:
* 1 / 2<sup>1</sup> = 0.5 * 1 / 2<sup>1</sup> = 0.5
* 3 / 2<sup>2</sup> = 0.75 * 3 / 2<sup>2</sup> = 0.75
* 5 / 2<sup>3</sup> = 0.625 * 5 / 2<sup>3</sup> = 0.625
* ... * ...
The highest possible numbers will therefore be chosen, within the limits set by the system, i.e. by the number of bits available to encode these numbers. The highest possible numbers will therefore be chosen, within the limits set by the system, i.e. by the number of bits available to encode these numbers.
As part of the hands-on, the number of bits allowed to store the numerator will be arbitrarily fixed, and the effect on the accuracy of the approximation will be calculated. Note that if you have N bits to store an integer, the largest possible integer is 2<sup>N</sup> - 1. As part of the hands-on, the number of bits allowed to store the numerator will be arbitrarily fixed, and the effect on the accuracy of the approximation will be calculated. Note that if you have N bits to store an integer, the largest possible integer is 2<sup>N</sup> - 1.
The file you need to start is [provided](../HandsOn/1-ProceduralProgramming/initial_file.cpp) in the _HandsOn_ folder of ProceduralProgramming lectures. The file you need to start is [provided](../HandsOn/1-ProceduralProgramming/initial_file.cpp) in the _HandsOn_ folder of ProceduralProgramming lectures.
Note: you may found more about the context of the formation exercises in [this article](https://sites.ualberta.ca/~kbeach/phys420_580_2010/docs/ACM-Goldberg.pdf). Note: you may found more about the context of the formation exercises in those articles:
* ["Exposing Floating Points](https://ciechanow.ski/exposing-floating-point/)
* ["What Every Computer Scientist Should Know About Floating-Point Arithmetic"](https://dl.acm.org/doi/pdf/10.1145/103162.103163).
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### __EXERCICE 1: Adding a loop__ ### __EXERCICE 1: Adding a loop__
Write a loop that displays the like of above up to the 2<sup>8</sup> for 0.65. Write a loop that displays the like of above up to the 2<sup>8</sup> for 0.65.
_Expected result_: _Expected result_:
0.65 ~ 1 / 2^1 0.65 ~ 1 / 2^1
0.65 ~ 3 / 2^2 0.65 ~ 3 / 2^2
0.65 ~ 5 / 2^3 0.65 ~ 5 / 2^3
0.65 ~ 10 / 2^4 0.65 ~ 10 / 2^4
0.65 ~ 21 / 2^5 0.65 ~ 21 / 2^5
0.65 ~ 42 / 2^6 0.65 ~ 42 / 2^6
0.65 ~ 83 / 2^7 0.65 ~ 83 / 2^7
0.65 ~ 166 / 2^8 0.65 ~ 166 / 2^8
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
[© Copyright](../COPYRIGHT.md) [© Copyright](../COPYRIGHT.md)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment