Skip to content

Commit 311a7db

Browse files
committed
UPDATE
1 parent f773836 commit 311a7db

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

JS/JS-br.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
- [Map、FlatMap e Reduce](#mapflatmap-e-reduce)
3333
- [Async e await](#async-e-await)
3434
- [Proxy](#proxy)
35-
- [Por que 0.1 + 0.2 != 0.3](#why-01--02--03)
35+
- [Por que 0.1 + 0.2 != 0.3](#por-que-01--02--03)
3636
- [Expressões regulares](#regular-expressions)
3737
- [Metacaracteres](#metacharacters)
3838
- [Flags](#flags)
@@ -1332,24 +1332,28 @@ p.a = 2 // liga `value` para `2`
13321332
p.a // -> obtém 'a' = 2
13331333
```
13341334
1335-
# Why 0.1 + 0.2 != 0.3
1335+
# Por que 0.1 + 0.2 != 0.3
13361336
1337-
Because JS uses the IEEE 754 double-precision version (64-bit). Every language that uses this standard has this problem.
1337+
Porque JS usa o precisão-dupla do IEEE 754 versão (64-bit). Toda linguagem que usa esse padrão tem esse problema.
1338+
1339+
Como nós sabemos, computadores usam binários para representar decimais, então `0.1` em binário é representado como
13381340
13391341
As we know, computers use binaries to represent decimals, so `0.1` in binary is represented as
13401342
13411343
```js
1342-
// (0011) represents cycle
1344+
// (0011) representa o ciclo
13431345
0.1 = 2^-4 * 1.10011(0011)
13441346
```
13451347
1346-
How do we come to this binary number? We can try computing it as below:
1348+
Como nós chegamos a esse número binário? Podemos tentar computar ele como abaixo:
13471349
13481350
![](https://user-gold-cdn.xitu.io/2018/4/26/162ffcb7fc1ca5a9?w=800&h=1300&f=png&s=83139)
13491351
1350-
Binary computations in float numbers are different from those in integers. For multiplications, only the float bits are computed, while the integer bits are used for the binaries for each bit. Then the first bit is used as the most significant bit. Therefore we get `0.1 = 2^-4 * 1.10011(0011)`.
1352+
Computações binária em números flutuantes são diferentes daqueles em inteiros. Por multiplicação, apenas bits flutuants são computados, enquanto bits do tipo inteiro são usados pelos binários para cada bit. Então o primeiro bit é usado como o bit mais significante. Assim sendo nós obtemos 0.1 = 2^-4 * 1.10011(0011)`.
1353+
1354+
`0.2` é similar. Nós apenas precisamos passear na primeira multiplicação e obter `0.2 = 2^-3 * 1.10011(0011)`
13511355

1352-
`0.2` is similar. We just need to get rid of the first multiplcation and get `0.2 = 2^-3 * 1.10011(0011)`.
1356+
Voltando a precisão dupla pelo padrão IEE 754. Entre o 64 bits, um bit é usado
13531357

13541358
Back to the double float for IEEE 754 standard. Among the 64 bits, one bit is used for signing, 11 used for integer bits, and the rest 52 bits are floats. Since `0.1` and `0.2` are infinitely cycling binaries, the last bit of the floats needs to indicate whether to round (same as rounding in decimals).
13551359

0 commit comments

Comments
 (0)