You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/en/integer.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,18 @@ Although Rust performs some checks for potential integer overflows, precautions
6
6
7
7
In particular, note that the compilation profile (typically *dev*, the default debug build, or *release*, the standard optimized build) changes integer overflow behavior. In the *dev* configuration, overflow causes the termination of the program (`panic`), whereas in the *release* configuration, the computed value is silently truncated to the number of bits of the numeric type, giving it wrap-around semantics.
8
8
9
+
<divclass="note">
10
+
11
+
The integer overflow behavior can be explicitly defined by the compilation option `-C overflow-checks=true` (or `false`).
12
+
It can also be modified in the profile definition in `Cargo.toml`:
13
+
14
+
```toml
15
+
[profile.release]
16
+
overflow-checks = true# enable overflow checks in release builds
17
+
```
18
+
19
+
</div>
20
+
9
21
When an overflow is possible, the behavior can be made explicit either by using specific methods or by using specific wrapper types.
10
22
11
23
The methods are of the form `<mode>_<op>`, where `<mode>` is `checked`, `overflowing`, `wrapping`, or `saturating`, and `<op>` is `add`, `mul`, `sub`, `shr`, etc. The semantics are as follows:
Copy file name to clipboardExpand all lines: src/fr/integer.md
+14-1Lines changed: 14 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,18 @@ l'exécution d'opérations arithmétiques sur les entiers.
8
8
9
9
En particulier, il faut noter que le profil de compilation (généralement *dev*, la compilation de débogage par défaut, ou *release*, la compilation optimisée standard) modifie le comportement en cas de dépassement d'entier. En configuration *dev*, un dépassement provoque l'arrêt du programme (`panic`), tandis qu'en configuration *release*, la valeur calculée est silencieusement tronquée au nombre de bits du type numérique, ce qui donne une sémantique d'arithmétique circulaire (*wrap-around*).
10
10
11
+
<divclass="note">
12
+
13
+
Le comportement en cas de dépassement d'entier peut être défini explicitement par l'option de compilation `-C overflow-checks=true` (ou `false`).
14
+
Il peut également être modifié dans la définition du profil dans `Cargo.toml` :
15
+
16
+
```toml
17
+
[profile.release]
18
+
overflow-checks = true# enable overflow checks in release builds
19
+
```
20
+
21
+
</div>
22
+
11
23
Lorsqu'un dépassement est possible, le comportement peut être rendu explicite soit en utilisant des méthodes spécifiques, soit en utilisant des types enveloppants spécifiques.
12
24
13
25
Les méthodes sont de la forme `<mode>_<op>`, où `<mode>` est `checked`, `overflowing`, `wrapping` ou `saturating`, et `<op>` est `add`, `mul`, `sub`, `shr`, etc. Les sémantiques sont les suivantes :
@@ -25,6 +37,7 @@ Les types enveloppants sont `Wrapping<T>` et `Saturating<T>` (de `std::num`), o
25
37
26
38
<divclass="reco"id="LANG-ARITH"type="Règle"title="Utilisation des opérations arithmétiques appropriées au regard des potentiels dépassements">
27
39
28
-
Lorsqu'une opération arithmétique peut produire un dépassement, les opérateurs classiques sur les entiers ne doivent pas être utilisés. Les méthodes spécialisées comme `checked_<op>`, `overflowing_<op>`, `wrapping_<op>`, ou `saturating_<op>`, ou des types enveloppants spécialisés comme `Wrapping` ou `Saturating`, doivent être utilisés pour rendre le comportement explicite et homogène, quel que soit le profil de compilation.
40
+
Lorsqu'une opération arithmétique peut produire un dépassement, les opérateurs classiques sur les entiers NE DOIVENT PAS être utilisés.
41
+
Les méthodes spécialisées comme `checked_<op>`, `overflowing_<op>`, `wrapping_<op>`, ou `saturating_<op>`, ou des types enveloppants spécialisés comme `Wrapping` ou `Saturating`, DOIVENT être utilisés pour rendre le comportement explicite et homogène, quel que soit le profil de compilation.
0 commit comments