Skip to content

Commit cefa865

Browse files
[BigInt] 번역
- 폴리필 관련 내용 일부 미완성
1 parent d0b5433 commit cefa865

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

1-js/99-js-misc/05-bigint/article.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,129 @@
22

33
[recent caniuse="bigint"]
44

5-
`BigInt` is a special numeric type that provides support for integers of arbitrary length.
5+
`BigInt`는 길이의 제약 없이 정수를 다룰 수 있게 해주는 숫자형입니다.
66

7-
A bigint is created by appending `n` to the end of an integer literal or by calling the function `BigInt` that creates bigints from strings, numbers etc.
7+
정수 리터럴 끝에 `n`을 붙이거나 함수 `BigInt`를 호출하면 문자열이나 숫자를 가지고 `BigInt` 타입의 값을 만들 수 있습니다.
88

99
```js
1010
const bigint = 1234567890123456789012345678901234567890n;
1111

1212
const sameBigint = BigInt("1234567890123456789012345678901234567890");
1313

14-
const bigintFromNumber = BigInt(10); // same as 10n
14+
const bigintFromNumber = BigInt(10); // 10n과 동일합니다.
1515
```
1616

17-
## Math operators
17+
## 수학 연산자
1818

19-
`BigInt` can mostly be used like a regular number, for example:
19+
`BigInt`는 대개 일반 숫자와 큰 차이 없이 사용할 수 있습니다.
2020

2121
```js run
2222
alert(1n + 2n); // 3
2323

2424
alert(5n / 2n); // 2
2525
```
2626

27-
Please note: the division `5/2` returns the result rounded towards zero, without the decimal part. All operations on bigints return bigints.
27+
위 예시에서 나눗셈 연산 `5/2`의 결과엔 소수부가 없다는 점에 주의하시기 바랍니다. `BigInt`형 값을 대상으로 한 연산은 `BigInt`형 값을 반환합니다.
2828

29-
We can't mix bigints and regular numbers:
29+
`BigInt`형 값과 일반 숫자를 섞어서 사용할 순 없습니다.
3030

3131
```js run
3232
alert(1n + 2); // Error: Cannot mix BigInt and other types
3333
```
3434

35-
We should explicitly convert them if needed: using either `BigInt()` or `Number()`, like this:
35+
일반 숫자와 섞어서 써야 하는 상황이라면 `BigInt()``Number()`를 사용해 명시적으로 형 변환을 해주면 됩니다.
3636

3737
```js run
3838
let bigint = 1n;
3939
let number = 2;
4040

41-
// number to bigint
41+
// 숫자를 bigint로
4242
alert(bigint + BigInt(number)); // 3
4343

44-
// bigint to number
44+
// bigint를 숫자로
4545
alert(Number(bigint) + number); // 3
4646
```
4747

48-
The conversion operations are always silent, never give errors, but if the bigint is too huge and won't fit the number type, then extra bits will be cut off, so we should be careful doing such conversion.
48+
형 변환과 관련된 연산은 항상 조용히 동작합니다. 절대 에러를 발생시키지 않죠. 그런데 bigint가 너무 커서 숫자형에서 허용하는 자릿수를 넘으면 나머지 비트는 자동으로 잘려 나갑니다. 이런 점을 염두하고 형 변환을 해야 합니다.
4949

50-
````smart header="The unary plus is not supported on bigints"
51-
The unary plus operator `+value` is a well-known way to convert `value` to a number.
50+
````smart header="단항 덧셈 연산자는 bigint에 사용할 수 없습니다."
51+
단항 덧셈 연산자 `+value`를 사용하면 `value`를 손쉽게 숫자형으로 바꿀 수 있습니다.
5252
53-
On bigints it's not supported, to avoid confusion:
53+
그런데 bigint는 혼란을 방지하기 위해 단항 덧셈 연산자를 지원하지 않습니다.
5454
```js run
5555
let bigint = 1n;
5656
57-
alert( +bigint ); // error
57+
alert( +bigint ); // 에러
5858
```
59-
So we should use `Number()` to convert a bigint to a number.
59+
bigint를 숫자형으로 바꿀 때는 `Number()`를 사용해야 합니다.
6060
````
6161

62-
## Comparisons
62+
## 비교 연산자
6363

64-
Comparisons, such as `<`, `>` work with bigints and numbers just fine:
64+
비교 연산자 `<`, `>`는 bigint와 일반 숫자 모두에 사용할 수 있습니다.
6565

6666
```js run
6767
alert( 2n > 1n ); // true
6868

6969
alert( 2n > 1 ); // true
7070
```
7171

72-
Please note though, as numbers and bigints belong to different types, they can be equal `==`, but not strictly equal `===`:
72+
그런데 비교하려는 대상이 다른 타입에 속하면 `==`를 사용할 때는 같을지 모르지만 `===`를 사용할 때는 다르다고 판단됩니다.
7373

7474
```js run
7575
alert( 1 == 1n ); // true
7676

7777
alert( 1 === 1n ); // false
7878
```
7979

80-
## Boolean operations
80+
## 논리 연산
8181

82-
When inside `if` or other boolean operations, bigints behave like numbers.
82+
bigint는 `if` 안이나 다른 논리 연산자와 함께 사용할 때 일반 숫자와 동일하게 행동합니다.
8383

84-
For instance, in `if`, bigint `0n` is falsy, other values are truthy:
84+
`if`안에서 `0n`은 falsy이고 다른 값들은 truthy로 평가되죠.
8585

8686
```js run
8787
if (0n) {
88-
// never executes
88+
// 절대 실행되지 않습니다.
8989
}
9090
```
9191

92-
Boolean operators, such as `||`, `&&` and others also work with bigints similar to numbers:
92+
`||`, `&&` 등의 논리 연산자를 bigint에 적용할 때도 일반 숫자와 유사하게 동작합니다.
9393

9494
```js run
95-
alert( 1n || 2 ); // 1 (1n is considered truthy)
95+
alert( 1n || 2 ); // 1 (1n은 truthy로 판단됩니다.)
9696

97-
alert( 0n || 2 ); // 2 (0n is considered falsy)
97+
alert( 0n || 2 ); // 2 (0n은 falsy로 판단됩니다.)
9898
```
9999

100-
## Polyfills
100+
## 폴리필
101101

102-
Polyfilling bigints is tricky. The reason is that many JavaScript operators, such as `+`, `-` and so on behave differently with bigints compared to regular numbers.
102+
bigint 폴리필을 만드는 것은 꽤 까다롭습니다. `+`, `-`를 비롯한 다양한 연산자들이 bigint와 일반 숫자에서 다른 결과를 보이기 때문입니다.
103103

104-
For example, division of bigints always returns a bigint (rounded if necessary).
104+
bigint끼리 나누면 항상 bigint를 반환한다는 것을 앞서 말씀드린 바 있습니다.
105105

106-
To emulate such behavior, a polyfill would need to analyze the code and replace all such operators with its functions. But doing so is cumbersome and would cost a lot of performance.
106+
동일한 결과가 나오게 하려면 폴리필에서 기존 코드를 분석하고 내장 연산자 모두를 관련 함수로 대체해 줄 수 있어야 합니다. 그런데 이렇게 하려면 품이 많이 들고 성능 이슈도 생길 수 있습니다.
107107

108-
So, there's no well-known good polyfill.
108+
따라서 아직까진 제대로 된 bigint 폴리필이 나오지 않은 상황입니다.
109109

110-
Although, the other way around is proposed by the developers of [JSBI](https://github.com/GoogleChromeLabs/jsbi) library.
110+
잘 알려진 폴리필은 없지만 [JSBI](https://github.com/GoogleChromeLabs/jsbi) 라이브러리의 개발자들이 대안을 제시하긴 했습니다.
111111

112-
This library implements big numbers using its own methods. We can use them instead of native bigints:
112+
이 라이브러리는 자체적으로 만든 방법을 사용해 큰 숫자를 구현합니다. 순수 bigint대신 라이브러리에서 만든 숫자를 사용하는 게 대안이 될 수 있습니다.
113113

114-
| Operation | native `BigInt` | JSBI |
114+
| 연산 | 네이티브 `BigInt` | JSBI |
115115
|-----------|-----------------|------|
116-
| Creation from Number | `a = BigInt(789)` | `a = JSBI.BigInt(789)` |
117-
| Addition | `c = a + b` | `c = JSBI.add(a, b)` |
118-
| Subtraction | `c = a - b` | `c = JSBI.subtract(a, b)` |
116+
| 일반 숫자를 사용해 bigint만들기 | `a = BigInt(789)` | `a = JSBI.BigInt(789)` |
117+
| 덧셈 | `c = a + b` | `c = JSBI.add(a, b)` |
118+
| 뺄셈 | `c = a - b` | `c = JSBI.subtract(a, b)` |
119119
| ... | ... | ... |
120120

121-
...And then use the polyfill (Babel plugin) to convert JSBI calls to native bigints for those browsers that support them.
121+
이렇게 JSBI를 사용해 숫자를 만든 다음 바벨 플러그인에 있는 폴리필을 사용해 JSBI 호출을 네이티브 bigint로 변환하면 원하는 브라우저에서 연산을 수행할 수 있습니다.
122122

123123
In other words, this approach suggests that we write code in JSBI instead of native bigints. But JSBI works with numbers as with bigints internally, emulates them closely following the specification, so the code will be "bigint-ready".
124124

125125
We can use such JSBI code "as is" for engines that don't support bigints and for those that do support - the polyfill will convert the calls to native bigints.
126126

127-
## References
127+
## 참고 자료
128128

129129
- [MDN docs on BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
130130
- [Specification](https://tc39.es/ecma262/#sec-bigint-objects).

0 commit comments

Comments
 (0)