الوقت/الأرقام
محول IEEE 754 float
رقم عشري ↔ تمثيل ثنائي وفق IEEE 754 (دقة أحادية أو مزدوجة) — الإشارة، الأس، الجزء العشري (mantissa)، القيم الخاصة.
Computers store fractional numbers in binary under the IEEE 754 standard — a sign, an exponent, and a mantissa, packed into a fixed number of bits. This tool shows that representation for any decimal number and parses it back into a number.
How to use it
- Number → bits: enter a decimal number to get its breakdown into sign, exponent, and mantissa for single (32-bit) or double (64-bit) precision.
- Bits → number: paste a bit representation to get the decimal value back.
- Special values (infinity, NaN, signed zero) are recognized and explained separately.
Common uses
- Understanding why 0.1 + 0.2 doesn't exactly equal 0.3 in most programming languages — a concrete demonstration of rounding error.
- Studying float's internal representation to understand precision limits in financial or scientific calculations.
- Parsing a binary dump or network packet where numbers are transmitted in IEEE 754 format.
Things to keep in mind
Most decimal fractions (0.1, for example) have no exact binary representation — that's the root cause of the typical rounding errors seen in calculation results.
Comparing floating-point numbers for exact equality (===) is unreliable — check instead whether the difference is smaller than a small threshold (epsilon).
مقالة عن هذه الأداة: IEEE 754: لماذا لا يساوي 0.1 + 0.2 القيمة 0.3 في الكود
الأسئلة الشائعة
ما الفرق بين الدقة المفردة والمزدوجة؟
تعطي الدقة المفردة (float، 32 بت) حوالي 7 أرقام عشرية من الدقة، بينما تعطي المزدوجة (double، 64 بت) حوالي 15-17. يستخدم نوع Number في JavaScript الدقة المزدوجة.
لماذا تفقد بعض الأعداد العشرية دقتها؟
يخزّن معيار IEEE 754 الأعداد بالنظام الثنائي، والعديد من الكسور العشرية (مثل 0.1) ليس لها تمثيل ثنائي منته دقيق — لذا يُخزَّن أقرب قيمة ممكنة مع خطأ تقريب ضئيل.
ماذا تعني NaN وInfinity وَ-0؟
NaN هو نتيجة عملية غير صالحة مثل 0/0. تظهر Infinity/-Infinity عندما تتجاوز قيمة النطاق القابل للتمثيل (مثل القسمة على 0). أما +0 وَ-0 فهما تمثيلان مختلفان لصفر مُوقَّع، لكنهما متساويان كأعداد.
ما هي الأعداد شبه الطبيعية (denormalized)؟
وضع تمثيل خاص للأعداد الصغيرة جدًا قيمةً مطلقة بالنسبة للصيغة العادية — يُسقَط الواحد الضمني في مقدمة المعامل، ما يتيح الاقتراب تدريجيًا من الصفر على حساب فقدان جزء من الدقة.
كيف تُقارَن الأعداد الكسرية بشكل صحيح بدلًا من التحقق من التساوي التام؟
بدلًا من a === b، يُتحقَّق مما إذا كان الفرق بين الرقمين أصغر من عتبة صغيرة (إبسيلون): Math.abs(a - b) < 1e-9. التساوي التام شبه مضمون أبدًا بسبب أخطاء التقريب.