Skip to content

Commit f55afac

Browse files
authored
Merge pull request #78 from MostafaMahmoud93/master
BigInt
2 parents b71e88e + 5dc4107 commit f55afac

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed

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

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,133 @@
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+
لإنشاء قيمة من النوع `BigInt` ، يجب عليك إضافة `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` ترجع النتيجة مقربة إلى الصفر بدون الجزء العشري. جميع العمليات على `BigInts` ترجع `BigInts`.
2828

29-
We can't mix bigints and regular numbers:
29+
لا يمكننا مزج الأرقام الكبيرة والأرقام العادية:
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 تحويل number إلى
4242
alert(bigint + BigInt(number)); // 3
4343

44-
// bigint to number
44+
// number تحويل 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` إلى رقم دائمًا بشكل ضمني وبدون توليد أخطاء ، ولكن إذا كانت قيمة `bigint` كبيرة جدًا ولا تتناسب مع نوع الرقم ، فسيتم تجاهل `bits` الإضافية ، لذلك يجب توخي الحذر في مثل هذه التحويلات.
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="لا يتم دعم ميزة الزائد الأحادي (+) على `bigints`"
51+
يعد عامل تشغيل الزائد الأحادي `+value` طريقة معروفة لتحويل `value` إلى رقم.
5252

53-
On bigints it's not supported, to avoid confusion:
53+
لا يتم دعم عامل التشغيل هذا عند العمل مع أرقام `BigInt`:
5454
```js run
5555
let bigint = 1n;
5656

5757
alert( +bigint ); // error
5858
```
59-
So we should use `Number()` to convert a bigint to a number.
59+
لذلك يجب أن نستخدم `Number()` لتحويل `bigint` إلى رقم.
6060
````
6161
62-
## Comparisons
62+
## المقارنات
6363
64-
Comparisons, such as `<`, `>` work with bigints and numbers just fine:
64+
تعمل المقارنات ، مثل <،> مع الأحرف الكبيرة والأرقام كالمعتاد:
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+
عندما تكون داخل `if` أو العمليات المنطقية الأخرى ، يتصرف`bigints` مثل الأرقام.
8383
84-
For instance, in `if`, bigint `0n` is falsy, other values are truthy:
84+
على سبيل المثال ، في `if` ، تكون قيمة bigint` 0n` خاطئة ، والقيم الأخرى صحيحة:
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` المشابهة للأرقام
93+
:
9394
9495
```js run
95-
alert( 1n || 2 ); // 1 (1n is considered truthy)
96+
alert( 1n || 2 ); // 1 (1n ستكون `true`)
9697
97-
alert( 0n || 2 ); // 2 (0n is considered falsy)
98+
alert( 0n || 2 ); // 2 (0n ستكون `false`)
9899
```
99100
100-
## Polyfills
101+
## تعدد الأشكال
101102
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.
103+
تعدد أشكال `bigints` صعب. والسبب هو أن العديد من عوامل تشغيل `JavaScript` ، مثل` + `،` -` وما إلى ذلك تتصرف بشكل مختلف باستخدام `bigints` مقارنة بالأرقام العادية.
103104
104-
For example, division of bigints always returns a bigint (rounded if necessary).
105+
على سبيل المثال ، يؤدي قسمة رقم `bigint` إلى إرجاع `bigint` (يتم تقريبه إذا لزم الأمر).
105106
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.
107+
لمحاكاة مثل هذا السلوك ، سيحتاج الملء المتعدد إلى تحليل الشفرة واستبدال جميع هذه العوامل بوظائفها. لكن القيام بذلك أمر مرهق وسيكلف الكثير من الأداء.
107108
108-
So, there's no well-known good polyfill.
109+
لذا ، لا يوجد "تعدد أشكال" جيد معروف.
109110
110-
Although, the other way around is proposed by the developers of [JSBI](https://github.com/GoogleChromeLabs/jsbi) library.
111+
على الرغم من ذلك هناك حل عكسي اقترحه مطورو مكتبة [JSBI](https://github.com/GoogleChromeLabs/jsbi) .
111112
112-
This library implements big numbers using its own methods. We can use them instead of native bigints:
113+
تقوم هذه المكتبة بتنفيذ أعداد كبيرة باستخدام أساليبها الخاصة. يمكننا استخدامها بدلاً من "bigints" الأصلية
114+
:
113115
114-
| Operation | native `BigInt` | JSBI |
116+
| العملية | الأصلية `BigInt` | JSBI |
115117
|-----------|-----------------|------|
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)` |
118+
| إنشاء من رقم | `a = BigInt(789)` | `a = JSBI.BigInt(789)` |
119+
| الإضافة | `c = a + b` | `c = JSBI.add(a, b)` |
120+
| الطرح | `c = a - b` | `c = JSBI.subtract(a, b)` |
119121
| ... | ... | ... |
120122
121-
...And then use the polyfill (Babel plugin) to convert JSBI calls to native bigints for those browsers that support them.
123+
… ثم استخدم "تعدد أشكال" (مكوّن Babel الإضافي) لتحويل مكالمات JSBI إلى `bigint` الأصلية لتلك المتصفحات التي تدعمها
124+
.
122125
123-
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".
126+
بعبارة أخرى ، يقترح هذا النهج استخدام JSBI بدلاً من `BigInt` المدمج. تعمل JSBI داخليًا مع الأرقام كما هو الحال مع `BigInt` ، تحاكيها وفقًا لجميع متطلبات المواصفات. وبالتالي ، يمكننا تنفيذ كود JSBI في المترجمين الذين لا يدعمون `Bigint` ، وبالنسبة لأولئك الذين يدعمون ، يقوم تعدد الأشكال بتحويل المكالمات إلى `Bigint` العادية..
124127
125-
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.
128+
يمكننا استخدام رمز JSBI هذا "كما هو" للمحركات التي لا تدعم `bigint` وتلك التي تدعم - سيقوم تعدد الأشكال بتحويل المكالمات إلى `bigint` الأصلية
129+
.
126130
127-
## References
131+
## المراجع
128132
129-
- [MDN docs on BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
130-
- [Specification](https://tc39.es/ecma262/#sec-bigint-objects).
133+
- [MDN BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
134+
- [تخصيص](https://tc39.es/ecma262/#sec-bigint-objects).

1-js/99-js-misc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
# Miscellaneous
2+
# موضوعات متنوعة

0 commit comments

Comments
 (0)