Majid Al-RaimiIEEE 754 FP32: normals, subnormals, zero, infinity and NaNIEEE 754 FP32: القيم العادية وتحت العادية والصفر واللانهاية وNaN

COE 592Lecture 5.1المحاضرة 5.1Part 02الجزء 02

IEEE 754 FP32: normals, subnormals, zero, infinity and NaNIEEE 754 FP32: القيم العادية وتحت العادية والصفر واللانهاية وNaN

How a 32-bit float splits into sign, 8-bit biased exponent and 23-bit fraction, how to encode a value, why zero and subnormals need a special rule, the smallest and largest representable values, and the exponent-255 codes for infinity and NaN.كيف ينقسم العدد العائم ذو 32 بت إلى إشارة وأس منحاز (biased exponent) من 8 بت وكسر من 23 بت، وكيف نرمّز قيمة، ولماذا يحتاج الصفر والقيم تحت العادية (subnormals) قاعدة خاصة، وأصغر وأكبر القيم القابلة للتمثيل، ورموز الأس 255 للانهاية وNaN.

Conceptsالمفاهيم
4
Slidesالشرائح
7-15
Readingمدة القراءة
24 min24 دقيقة
Understoodما فهمته
0/4 conceptsمفاهيم

Why this part mattersلماذا يهمّ هذا الجزء

Every weight in an unquantized network is a 32-bit float. Before you can judge what is lost when you squeeze that weight into 16, 8 or 4 bits, you need to know exactly what the 32 bits were buying. This part takes the FP32 format apart field by field.

The thread runs in four steps. First, how sign, exponent and fraction combine into a value, with a full encoding of 0.265625. Second, why that rule cannot express zero, and the special exponent-0 rule that fixes it. Third, the extreme values at the bottom of the range, which are favourite exam fill-ins. Fourth, the all-ones exponent for infinity and NaN, and the complete map of the format. Every later format in this lecture (FP16, BF16, FP8, FP4) reuses this exact machinery with different field widths, so time spent here pays off three times over.

كل وزن (weight) في شبكة غير مكمَّمة هو عدد عشري (float) من 32 bit. قبل أن تحكم على ما يضيع عندما تضغط هذا الوزن في 16 أو 8 أو 4 bits، عليك أن تعرف بالضبط ما الذي كانت تشتريه الـ 32 bit. هذا الجزء يفكّك صيغة FP32 حقلًا حقلًا.

يسير الخيط في أربع خطوات. أولًا، كيف تجتمع الإشارة (sign) والأس (exponent) والكسر (fraction) لتكوين قيمة، مع ترميز كامل للعدد 0.265625. ثانيًا، لماذا لا تستطيع تلك القاعدة التعبير عن الصفر، والقاعدة الخاصة بالأس 0 التي تحل المشكلة. ثالثًا، القيم القصوى في أسفل المدى، وهي من أسئلة الإكمال المفضلة في الامتحانات. رابعًا، الأس المكوّن من آحاد فقط (all-ones) الخاص بـ infinity وNaN، والخريطة الكاملة للصيغة. كل صيغة لاحقة في هذه المحاضرة (FP16 وBF16 وFP8 وFP4) تعيد استخدام الآلية نفسها تمامًا مع عروض حقول مختلفة، لذلك فإن الوقت الذي تقضيه هنا يعود عليك ثلاثة أضعاف.

By the end you canفي نهاية هذا الجزء ستستطيع

  1. Split a 32-bit word into sign, 8-bit biased exponent and 23-bit fraction, and state the bias 127 = 2^(8-1) - 1.تقسّم كلمة من 32 bit إلى sign وexponent متحيّز (biased) من 8 bits وfraction من 23 bit، وتذكر أن الـ bias يساوي 127 = 2^(8-1) - 1.
  2. Encode a decimal value such as 0.265625 or -6.5 into FP32 bits, and decode bits back to a value.تحوّل قيمة عشرية مثل 0.265625 أو -6.5 إلى bits بصيغة FP32، وتفكّ bits وتعيدها إلى قيمة.
  3. Explain why zero cannot be a normal number and how the exponent-0 rule (subnormals) fixes it.تشرح لماذا لا يمكن تمثيل الصفر كعدد normal، وكيف تحل قاعدة exponent = 0 (أي subnormals) هذه المشكلة.
  4. Derive the smallest and largest subnormal and the smallest and largest normal, and justify the forced exponent 1 - 127.تشتق أصغر وأكبر subnormal وأصغر وأكبر normal، وتبرّر لماذا يُفرض الأس 1 - 127.
  5. Read the exponent-class table: 00h, 01h to FEh and FFh, each with fraction zero or nonzero.تقرأ جدول أصناف الـ exponent: 00h، ومن 01h إلى FEh، وFFh، وكل منها مع fraction يساوي صفرًا أو لا يساوي صفرًا.

Take the number 0.265625. In binary it is 0.010001₂, because 0.25 + 0.015625 = 0.265625. Slide the binary point two places to the right and you get 1.0001₂ × 2⁻². That is scientific notation in base 2, and it is all a float stores: a sign, a power of two, and the digits after the leading 1.

خذ العدد 0.265625. في النظام الثنائي هو 0.010001₂، لأن 0.25 + 0.015625 = 0.265625. حرّك الفاصلة الثنائية خانتين إلى اليمين فتحصل على 1.0001₂ × 2⁻². هذا هو الترميز العلمي (scientific notation) بالأساس 2، وهو كل ما يخزّنه الـ float: إشارة، وقوة للعدد 2، والأرقام التي تأتي بعد الـ 1 الأول.

Three fields, one formulaثلاثة حقول، ومعادلة واحدة

A Floating-point number number in the IEEE 754 single precision format splits 32 bits into three fields. Bit 31 is the sign ss. Bits 30 to 23 hold an 8-bit exponent field EE, read as an unsigned integer from 0 to 255. Bits 22 to 0 hold the 23-bit Fraction (mantissa, significand), read as the binary digits after the point, so its value lies in [0, 1−2−23][0,\,1-2^{-23}]. For ordinary numbers the value is

عدد floating-point بصيغة الدقة الأحادية (single precision) في معيار IEEE 754 يقسّم الـ 32 bit إلى ثلاثة حقول. الـ bit رقم 31 هو الإشارة ss. الـ bits من 30 إلى 23 تحمل حقل أس (exponent) من 8 bits هو EE، ويُقرأ كعدد صحيح بلا إشارة (unsigned) من 0 إلى 255. والـ bits من 22 إلى 0 تحمل الـ fraction (mantissa) المكوّن من 23 bit، ويُقرأ على أنه الأرقام الثنائية بعد الفاصلة، لذلك تقع قيمته في [0, 1−2−23][0,\,1-2^{-23}]. وللأعداد العادية تكون القيمة

x=(−1)sign×(1+Fraction)×2 Exponent−127x = (-1)^{\text{sign}}\times(1+\text{Fraction})\times 2^{\,\text{Exponent}-127}
FP32 normal numbers: Exponent field from 1 to 254أعداد FP32 الطبيعية (normal): حقل الأس من 1 إلى 254
0.265625 in FP32: sign 0, stored exponent 125, fraction 0.0625العدد 0.265625 بصيغة FP32: الإشارة 0، والأس المخزَّن 125، والـ fraction يساوي 0.0625

Two design choices hide in that formula. The first is the Exponent bias. The field is unsigned, but real exponents must go negative to reach small numbers. Rather than spend a sign bit, IEEE stores E=e+127E = e + 127, where ee is the true exponent. The bias is 28−1−1=1272^{8-1}-1 = 127, the middle of the 8-bit range, so true exponents from -126 to +127 fit in stored values 1 to 254. A side effect worth knowing: because bigger exponents are bigger unsigned integers, positive floats sort in the same order as their bit patterns.

في تلك المعادلة قراران تصميميان مخفيّان. الأول هو exponent bias. الحقل بلا إشارة (unsigned)، لكن الأسس الحقيقية يجب أن تصبح سالبة لكي نصل إلى الأعداد الصغيرة. وبدلًا من إنفاق bit للإشارة، يخزّن IEEE القيمة E=e+127E = e + 127، حيث ee هو الأس الحقيقي. والـ bias يساوي 28−1−1=1272^{8-1}-1 = 127، أي منتصف مدى الـ 8 bits، لذلك تتسع الأسس الحقيقية من -126 إلى +127 في القيم المخزَّنة من 1 إلى 254. وهناك أثر جانبي يستحق المعرفة: لأن الأسس الأكبر تكون أعدادًا صحيحة بلا إشارة أكبر، فإن الأعداد العشرية الموجبة تُرتَّب بالترتيب نفسه الذي تُرتَّب به أنماط الـ bits الخاصة بها.

The second choice is the hidden bit. Any nonzero binary number can be shifted until it reads 1.something, so the leading 1 carries no information. FP32 does not store it, which buys one extra bit of precision for free: 23 stored fraction bits give a 24-bit significand.

القرار الثاني هو الـ bit المخفي (hidden bit). أي عدد ثنائي غير صفري يمكن إزاحته حتى يصبح على الشكل 1.something، لذلك فإن الـ 1 الأول لا يحمل أي معلومة. صيغة FP32 لا تخزّنه، وهذا يمنحها bit إضافيًا من الدقة مجانًا: 23 bit مخزَّنة في الـ fraction تعطي significand من 24 bit.

Worked exampleمثال محلول

Encode 0.265625 (slide 7)ترميز العدد 0.265625 (الشريحة 7)

  1. Convert to binaryالتحويل إلى النظام الثنائي

    0.265625 × 2 = 0.53125 gives digit 0, × 2 = 1.0625 gives 1, then 0, 0, 0, and 0.5 × 2 = 1.0 gives the final 1. So 0.265625 = 0.010001₂.
    0.265625 × 2 = 0.53125 يعطي الرقم 0، ثم × 2 = 1.0625 يعطي 1، ثم 0 و0 و0، وأخيرًا 0.5 × 2 = 1.0 يعطي الـ 1 الأخير. إذن 0.265625 = 0.010001₂.
  2. Normalizeالتطبيع (Normalize)

    Move the point to just after the first 1: 0.010001₂ = 1.0001₂ × 2⁻². True exponent e=−2e=-2.
    انقل الفاصلة إلى ما بعد أول 1 مباشرة: 0.010001₂ = 1.0001₂ × 2⁻². الأس الحقيقي e=−2e=-2.
  3. Bias the exponentإضافة الـ bias إلى الأس

    E=−2+127=125=011111012E = -2 + 127 = 125 = 01111101_2.
    E=−2+127=125=011111012E = -2 + 127 = 125 = 01111101_2.
  4. Read off sign and fractionاستخراج الإشارة والـ fraction

    Positive, so S=0S=0. The digits after the point are 0001, padded with zeros to 23 bits: 00010000000000000000000, worth 2−4=0.06252^{-4}=0.0625.
    العدد موجب، إذن S=0S=0. الأرقام بعد الفاصلة هي 0001، ونكملها بأصفار حتى 23 bit: 00010000000000000000000، وقيمتها 2−4=0.06252^{-4}=0.0625.
  5. Resultالنتيجة

    0 01111101 00010000000000000000000, which is 0x3E880000. Check: (1+0.0625)×2125−127=1.0625×0.25=0.265625(1+0.0625)\times 2^{125-127} = 1.0625\times 0.25 = 0.265625.
    0 01111101 00010000000000000000000، أي 0x3E880000. للتحقق: (1+0.0625)×2125−127=1.0625×0.25=0.265625(1+0.0625)\times 2^{125-127} = 1.0625\times 0.25 = 0.265625.

Recall

Decode 0 01111101 00010000000000000000000 back to a decimal value without looking at the example.فكّ النمط 0 01111101 00010000000000000000000 وأعده إلى قيمة عشرية دون النظر إلى المثال.

Sign 0, so positive. Exponent field 01111101 = 125, not 0 and not 255, so the number is normal and the true exponent is 125 - 127 = -2. The fraction has only the 4th bit set, worth 2⁻⁴ = 0.0625. Value (1 + 0.0625) × 2⁻² = 0.265625.

الإشارة 0، إذن العدد موجب. حقل الأس 01111101 = 125، وهو ليس 0 وليس 255، لذلك العدد normal والأس الحقيقي هو 125 - 127 = -2. في الـ fraction لا يوجد إلا الـ bit الرابع مضبوطًا على 1، وقيمته 2⁻⁴ = 0.0625. القيمة (1 + 0.0625) × 2⁻² = 0.265625.

Worked exampleمثال محلول

Practice: encode -6.5تمرين: ترميز العدد -6.5

  1. Binary and normalizeالتحويل الثنائي والتطبيع

    6.5 = 110.1₂ = 1.101₂ × 2², so e=2e = 2.
    6.5 = 110.1₂ = 1.101₂ × 2²، إذن e=2e = 2.
  2. Fieldsالحقول

    Negative, so S=1S = 1. E=2+127=129=100000012E = 2 + 127 = 129 = 10000001_2. Fraction digits 101 then zeros, worth 0.5 + 0.125 = 0.625.
    العدد سالب، إذن S=1S = 1. E=2+127=129=100000012E = 2 + 127 = 129 = 10000001_2. أرقام الـ fraction هي 101 ثم أصفار، وقيمتها 0.5 + 0.125 = 0.625.
  3. Resultالنتيجة

    1 10000001 10100000000000000000000 = 0xC0D00000. Check: −(1+0.625)×22=−6.5-(1+0.625)\times 2^{2} = -6.5.
    1 10000001 10100000000000000000000 = 0xC0D00000. للتحقق: −(1+0.625)×22=−6.5-(1+0.625)\times 2^{2} = -6.5.

Try it yourself. Load the 0.265625 and -6.5 presets in the explorer below, then flip single bits and watch which readout moves. Flipping the lowest exponent bit doubles or halves the value; flipping the lowest fraction bit barely moves it.

جرّب بنفسك. حمّل الإعدادين المسبقين 0.265625 و-6.5 في المستكشف أدناه، ثم اقلب bits منفردة وراقب أي قراءة تتغير. قلب أدنى bit في الأس يضاعف القيمة أو ينصّفها؛ أما قلب أدنى bit في الـ fraction فبالكاد يحرّكها.

ExplorerمستكشفClick any bit of an FP32 wordانقر أي بت في كلمة FP32

0 01111101 00010000000000000000000 = 0x3E880000

sign0positiveموجب
stored exponent12501111101
unbiased exponent-2stored minus 127القيمة المخزنة ناقص 127
significand1 + 0.0625hidden bit plus fractionالبت المخفي مضافا إليه الكسر
classnormal
value0.265625

Recall

Slide 8 asks: how should we represent 0 with the formula (-1)^sign x (1 + Fraction) x 2^(Exponent - 127)? Try before revealing.تسأل الشريحة 8: كيف نمثّل 0 بالمعادلة (-1)^sign x (1 + Fraction) x 2^(Exponent - 127)؟ حاول قبل كشف الإجابة.

You cannot. 1 + Fraction is at least 1, and 2^(Exponent - 127) is never 0, so the product is never 0. Setting every bit to 0 gives 1 × 2⁻¹²⁷, a tiny number but not zero. The format needs a separate rule.

لا يمكنك ذلك. 1 + Fraction لا يقل عن 1، و2^(Exponent - 127) لا يساوي 0 أبدًا، لذلك فإن حاصل الضرب لا يساوي 0 أبدًا. وجعل كل الـ bits أصفارًا يعطي 1 × 2⁻¹²⁷، وهو عدد صغير جدًا لكنه ليس صفرًا. تحتاج الصيغة إلى قاعدة منفصلة.

The hidden bit that bought free precision has a price: every normal number starts with 1, so the smallest magnitude the normal rule can reach is 1.0 × 2⁻¹²⁶, about 1.18 × 10⁻³⁸. Zero, and everything between zero and that floor, is out of reach.

الـ bit المخفي الذي منحنا دقة مجانية له ثمن: كل عدد normal يبدأ بـ 1، لذلك فإن أصغر مقدار تستطيع قاعدة الـ normal الوصول إليه هو 1.0 × 2⁻¹²⁶، أي نحو 1.18 × 10⁻³⁸. الصفر، وكل ما بين الصفر وذلك الحد الأدنى، خارج متناولها.

The exponent-0 ruleقاعدة الأس 0

IEEE reserves the exponent field 00000000 for a second rule. When the stored exponent is 0, the hidden bit becomes 0 instead of 1, and the scale is fixed at 21−1272^{1-127}:

يحجز IEEE حقل الأس 00000000 لقاعدة ثانية. عندما يكون الأس المخزَّن 0، يصبح الـ bit المخفي 0 بدلًا من 1، ويُثبَّت المقياس عند 21−1272^{1-127}:

x=(−1)sign×Fraction×2 1−127=(−1)sign×Fraction×2−126x = (-1)^{\text{sign}}\times \text{Fraction}\times 2^{\,1-127} = (-1)^{\text{sign}}\times \text{Fraction}\times 2^{-126}
FP32 subnormal numbers: Exponent field = 0أعداد FP32 دون الطبيعية (subnormal): حقل الأس = 0

Values produced this way are subnormal numbers (older texts say denormals). Everything with exponent field 1 to 254 is a Normal number. With fraction 0 the subnormal rule gives exactly 0×2−126=00\times 2^{-126}=0. Since the sign bit is still free, there are two zeros: 0 00000000 000...0 is +0 and 1 00000000 000...0 is -0. They compare equal, but 1 / +0 = +∞ while 1 / -0 = -∞, so the sign is not cosmetic. You met the same two-zero situation in Sign-magnitude integers, and for the same reason: a separate sign bit.

القيم الناتجة بهذه الطريقة هي subnormal numbers (وتسميها المراجع الأقدم denormals). وكل ما حقل أسه من 1 إلى 254 هو normal number. ومع fraction يساوي 0 تعطي قاعدة الـ subnormal بالضبط 0×2−126=00\times 2^{-126}=0. وبما أن bit الإشارة ما زال حرًا، يوجد صفران: 0 00000000 000...0 هو +0 و1 00000000 000...0 هو -0. هما متساويان عند المقارنة، لكن 1 / +0 = +∞ بينما 1 / -0 = -∞، لذلك فالإشارة ليست شكلية. لقد قابلت حالة الصفرين نفسها في الأعداد الصحيحة بتمثيل sign-magnitude، وللسبب نفسه: bit إشارة منفصل.

Why 1 - 127 and not 0 - 127لماذا 1 - 127 وليس 0 - 127

The slide says the exponent “should have been” 0 - 127, “but we force” it to 1 - 127. The reason is continuity. The smallest normal number is 2⁻¹²⁶, and normals in the first binade [2⁻¹²⁶, 2⁻¹²⁵) are spaced 2−23×2−126=2−1492^{-23}\times 2^{-126}=2^{-149} apart. With the forced scale 2⁻¹²⁶, subnormals are k×2−149k\times 2^{-149} for k=0,1,…,223−1k=0,1,\dots,2^{23}-1: the same step, ending one step below 2⁻¹²⁶. The grid runs straight from 0 into the normals without a seam.

تقول الشريحة إن الأس “كان يجب أن يكون” 0 - 127، “لكننا نفرض” أن يكون 1 - 127. السبب هو الاستمرارية. أصغر عدد normal هو 2⁻¹²⁶، والأعداد normal في أول binade [2⁻¹²⁶, 2⁻¹²⁵) تفصل بينها مسافة 2−23×2−126=2−1492^{-23}\times 2^{-126}=2^{-149}. ومع المقياس المفروض 2⁻¹²⁶ تكون الـ subnormals هي k×2−149k\times 2^{-149} حيث k=0,1,…,223−1k=0,1,\dots,2^{23}-1: الخطوة نفسها، وتنتهي قبل 2⁻¹²⁶ بخطوة واحدة. فتمتد الشبكة مباشرة من 0 إلى الأعداد normal دون أي فاصل.

Had IEEE used 2⁻¹²⁷, subnormals would be spaced 2⁻¹⁵⁰ and stop just below 2⁻¹²⁷. The whole interval from 2⁻¹²⁷ to 2⁻¹²⁶ would contain no representable numbers at all, and the spacing would jump by a factor of 2 at the boundary.

لو استخدم IEEE المقياس 2⁻¹²⁷، لكانت المسافة بين الـ subnormals 2⁻¹⁵⁰ ولتوقفت قبل 2⁻¹²⁷ بقليل. ولأصبحت الفترة كاملة من 2⁻¹²⁷ إلى 2⁻¹²⁶ خالية تمامًا من أي عدد قابل للتمثيل، ولقفزت المسافة بين الأعداد بمعامل 2 عند الحد الفاصل.

Forced scale 2^(1-127): subnormal steps continue straight into the first normal binade. Naive 2^(0-127): half the interval is left emptyالمقياس المفروض 2^(1-127): خطوات الـ subnormals تستمر مباشرة في أول binade من الأعداد normal. أما المقياس الساذج 2^(0-127): فيترك نصف الفترة فارغًا

Quick checkاختبار سريع

Why does an FP32 subnormal use the scale 2^(1 - 127) rather than 2^(0 - 127)?لماذا يستخدم الـ subnormal في FP32 المقياس 2^(1 - 127) بدلًا من 2^(0 - 127)؟

Recall

Slide 10 asks: what is the smallest positive subnormal value? Write the bit pattern and the value.تسأل الشريحة 10: ما أصغر قيمة subnormal موجبة؟ اكتب نمط الـ bits والقيمة.

Exponent 0, fraction with only the last bit set: 0 00000000 00000000000000000000001. Fraction = 2⁻²³, so the value is 2⁻²³ × 2⁻¹²⁶ = 2⁻¹⁴⁹, about 1.4 × 10⁻⁴⁵.

الأس 0، والـ fraction لا يحوي إلا الـ bit الأخير مضبوطًا: 0 00000000 00000000000000000000001. الـ Fraction = 2⁻²³، إذن القيمة هي 2⁻²³ × 2⁻¹²⁶ = 2⁻¹⁴⁹، أي نحو 1.4 × 10⁻⁴⁵.

Compare that with the smallest normal, 0 00000001 000...0. Its exponent field is 1, its fraction is 0, so it equals (1+0)×21−127=2−126(1+0)\times 2^{1-127}=2^{-126}. The subnormals stretch the bottom of the range by another 23 powers of two, from 2⁻¹²⁶ down to 2⁻¹⁴⁹, one power per fraction bit.

قارن ذلك بأصغر عدد normal، وهو 0 00000001 000...0. حقل أسه 1 والـ fraction فيه 0، لذلك يساوي (1+0)×21−127=2−126(1+0)\times 2^{1-127}=2^{-126}. الـ subnormals تمد أسفل المدى بـ 23 قوة أخرى للعدد 2، من 2⁻¹²⁶ نزولًا إلى 2⁻¹⁴⁹، قوة واحدة لكل bit في الـ fraction.

Notice what both patterns have in common: exponent field 1 for the normal and exponent field 0 for the subnormal both mean a true exponent of -126. That is the forced 1 - 127 at work. The only difference between the two cases is the hidden bit.

لاحظ القاسم المشترك بين النمطين: حقل الأس 1 في الـ normal وحقل الأس 0 في الـ subnormal كلاهما يعني أسًا حقيقيًا قدره -126. هذا هو أثر الأس المفروض 1 - 127. والفرق الوحيد بين الحالتين هو الـ bit المخفي.

Recall

Slide 12 asks: what is the largest positive subnormal value? Derive it before revealing.تسأل الشريحة 12: ما أكبر قيمة subnormal موجبة؟ اشتقها قبل كشف الإجابة.

Exponent 0, fraction all ones: 0 00000000 11111111111111111111111. Fraction = 2⁻¹ + 2⁻² + … + 2⁻²³ = 1 - 2⁻²³. Value (1 - 2⁻²³) × 2⁻¹²⁶ = 2⁻¹²⁶ - 2⁻¹⁴⁹, exactly one step of 2⁻¹⁴⁹ below the smallest normal.

الأس 0، والـ fraction كله آحاد: 0 00000000 11111111111111111111111. الـ Fraction = 2⁻¹ + 2⁻² + … + 2⁻²³ = 1 - 2⁻²³. القيمة (1 - 2⁻²³) × 2⁻¹²⁶ = 2⁻¹²⁶ - 2⁻¹⁴⁹، أي أقل من أصغر عدد normal بخطوة واحدة بالضبط مقدارها 2⁻¹⁴⁹.

The geometric sum is the step to remember: a run of nn ones after the binary point equals 1−2−n1-2^{-n}, just as 0.999 is 1 - 10⁻³ in decimal. Apply it to the top of the range and you get the largest normal. Exponent field 11111110 = 254 (255 is reserved) and fraction all ones give

المجموع الهندسي هو الخطوة التي يجب تذكرها: سلسلة من nn آحاد بعد الفاصلة الثنائية تساوي 1−2−n1-2^{-n}، تمامًا كما أن 0.999 تساوي 1 - 10⁻³ في النظام العشري. طبّقها على أعلى المدى فتحصل على أكبر عدد normal. حقل الأس 11111110 = 254 (لأن 255 محجوز) مع fraction كله آحاد يعطيان

(1+1−2−23)×2254−127=(2−2−23)×2127≈3.4×1038(1+1-2^{-23})\times 2^{254-127} = (2-2^{-23})\times 2^{127}\approx 3.4\times 10^{38}
Largest FP32 normal, bit pattern 0x7F7FFFFFأكبر عدد FP32 طبيعي، بنمط البتات 0x7F7FFFFF

FP32 values to know coldقيم FP32 التي يجب أن تحفظها جيدًا

smallest subnormalأصغر subnormal
0 00000000 000...01 = 2−23×2−126=2−1492^{-23}\times 2^{-126} = 2^{-149}, about 1.4 × 10⁻⁴⁵0 00000000 000...01 = 2−23×2−126=2−1492^{-23}\times 2^{-126} = 2^{-149}، أي نحو 1.4 × 10⁻⁴⁵
largest subnormalأكبر subnormal
0 00000000 111...11 = (1−2−23)×2−126=2−126−2−149(1-2^{-23})\times 2^{-126} = 2^{-126}-2^{-149}0 00000000 111...11 = (1−2−23)×2−126=2−126−2−149(1-2^{-23})\times 2^{-126} = 2^{-126}-2^{-149}
smallest normalأصغر normal
0 00000001 000...00 = (1+0)×21−127=2−126(1+0)\times 2^{1-127} = 2^{-126}, about 1.18 × 10⁻³⁸0 00000001 000...00 = (1+0)×21−127=2−126(1+0)\times 2^{1-127} = 2^{-126}، أي نحو 1.18 × 10⁻³⁸
largest normalأكبر normal
0 11111110 111...11 = (1+1−2−23)×2127=(2−2−23)×2127(1+1-2^{-23})\times 2^{127} = (2-2^{-23})\times 2^{127}, about 3.4 × 10³⁸0 11111110 111...11 = (1+1−2−23)×2127=(2−2−23)×2127(1+1-2^{-23})\times 2^{127} = (2-2^{-23})\times 2^{127}، أي نحو 3.4 × 10³⁸
zeroالصفر
0 00000000 000...00 is +0 and 1 00000000 000...00 is -00 00000000 000...00 هو +0، و1 00000000 000...00 هو -0

Quick checkاختبار سريع

Which FP32 bit pattern encodes the smallest positive normal number?أي نمط bits في FP32 يرمّز أصغر عدد normal موجب؟

Divide 1.0 by +0, or multiply 3 × 10³⁸ by 10. The true answer is beyond the largest normal, and the hardware still has to return 32 bits. Compute 0 / 0 or √-1 and there is no real answer at all. The all-ones exponent is reserved for exactly these cases.

اقسم 1.0 على +0، أو اضرب 3 × 10³⁸ في 10. الإجابة الحقيقية تتجاوز أكبر عدد normal، ومع ذلك يجب على العتاد أن يعيد 32 bit. واحسب 0 / 0 أو √-1 فلا توجد إجابة حقيقية أصلًا. الأس المكوّن من آحاد فقط محجوز لهذه الحالات بالضبط.

Exponent 255: infinity and NaNالأس 255: اللانهاية (infinity) وNaN

When the exponent field is 11111111 (FFh = 255), the bits no longer encode a number through either formula. With fraction 0 the pattern is infinity: 0 11111111 000...0 is +∞ (0x7F800000) and 1 11111111 000...0 is -∞. With any nonzero fraction it is NaN, “not a number”, and the sign bit is a don’t care, which is why slide 14 draws it as a dash. NaN propagates: any arithmetic with a NaN input yields NaN, so a single bad value in a training run poisons the loss rather than silently turning into a plausible number.

عندما يكون حقل الأس 11111111 (FFh = 255)، لا تعود الـ bits ترمّز عددًا عبر أي من المعادلتين. مع fraction يساوي 0 يكون النمط لانهاية (infinity): 0 11111111 000...0 هو +∞ (0x7F800000) و1 11111111 000...0 هو -∞. ومع أي fraction غير صفري يكون NaN، أي “ليس عددًا” (not a number)، ويكون bit الإشارة غير مهم (don’t care)، ولهذا ترسمه الشريحة 14 على شكل شرطة. وNaN ينتشر: أي عملية حسابية أحد مدخلاتها NaN تعطي NaN، لذلك فإن قيمة واحدة فاسدة أثناء التدريب تُفسد الـ loss بدلًا من أن تتحول بصمت إلى عدد يبدو معقولًا.

The slide’s remark “much waste” is a counting argument. Every nonzero 23-bit fraction is a NaN, so there are 223−12^{23}-1 NaN patterns per sign, 2²⁴ - 2 in total, about 16.8 million codes that name no number. In 32 bits that is under 0.4% of all patterns and nobody minds. In an 8-bit format the same rule would burn a whole exponent row out of only 256 codes, which is why FP8 E4M3 drops infinity and keeps a single NaN mantissa (you will see this in the next part).

ملاحظة الشريحة “much waste” (هدر كبير) هي حجة عدّ. كل fraction غير صفري من 23 bit هو NaN، لذلك يوجد 223−12^{23}-1 نمطًا لـ NaN لكل إشارة، أي 2²⁴ - 2 إجمالًا، وهي نحو 16.8 مليون رمز لا تسمّي أي عدد. في 32 bit يمثل ذلك أقل من 0.4% من كل الأنماط ولا أحد يهتم. أما في صيغة من 8 bits فإن القاعدة نفسها ستحرق صفًا كاملًا من الأس من بين 256 رمزًا فقط، ولهذا تتخلى FP8 E4M3 عن infinity وتحتفظ بـ mantissa واحد فقط لـ NaN (سترى ذلك في الجزء التالي).

The whole format in one tableالصيغة كاملة في جدول واحد

Exponent fieldحقل الأسFraction = 0Fraction = 0Fraction ≠ 0Fraction ≠ 0Equationالمعادلة
00h = 000h = 0±0±0subnormalsubnormal(−1)s×Fraction×21−127(-1)^{s}\times \text{Fraction}\times 2^{1-127}(−1)s×Fraction×21−127(-1)^{s}\times \text{Fraction}\times 2^{1-127}
01h ... FEh = 1 ... 25401h ... FEh = 1 ... 254normalnormalnormalnormal(−1)s×(1+Fraction)×2Exponent−127(-1)^{s}\times (1+\text{Fraction})\times 2^{\text{Exponent}-127}(−1)s×(1+Fraction)×2Exponent−127(-1)^{s}\times (1+\text{Fraction})\times 2^{\text{Exponent}-127}
FFh = 255FFh = 255±INF±INFNaNNaNno numeric valueلا قيمة عددية
FP32 classes by exponent field and fraction (slide 15)أصناف FP32 بحسب حقل الأس والـ fraction (الشريحة 15)

Read the table as a decision procedure. First look at the exponent field. If it is 0, apply the subnormal formula (and fraction 0 gives a signed zero). If it is 255, the answer is infinity or NaN depending on the fraction. Anything else is normal. Every one of the 2³² bit patterns lands in exactly one cell.

اقرأ الجدول كإجراء لاتخاذ القرار. انظر أولًا إلى حقل الأس. إذا كان 0، فطبّق معادلة الـ subnormal (والـ fraction الذي يساوي 0 يعطي صفرًا بإشارة). وإذا كان 255، فالإجابة infinity أو NaN بحسب الـ fraction. وأي قيمة أخرى تعني normal. وكل نمط من الـ 2³² نمطًا يقع في خلية واحدة بالضبط.

Where the values sit on the number lineأين تقع القيم على خط الأعداد

The bottom of slide 15 places the classes on the positive axis. Subnormals fill [0, 2⁻¹²⁶) with a uniform step of 2⁻¹⁴⁹: in that stretch FP32 behaves like a fixed-point format. From 2⁻¹²⁶ upward the normals take over, and each binade [2^e, 2^(e+1)) holds the same 2²³ values, so the absolute step doubles every time the exponent rises by one while the relative step stays about 2⁻²³. The line ends at (2 - 2⁻²³) × 2¹²⁷, after which comes only +∞.

يضع الجزء السفلي من الشريحة 15 الأصناف على المحور الموجب. الـ subnormals تملأ [0, 2⁻¹²⁶) بخطوة منتظمة قدرها 2⁻¹⁴⁹: في هذا الامتداد تتصرف FP32 مثل صيغة fixed-point. ومن 2⁻¹²⁶ فصاعدًا تتولى الأعداد normal الأمر، وكل binade [2^e, 2^(e+1)) يحوي العدد نفسه من القيم وهو 2²³، لذلك تتضاعف الخطوة المطلقة كلما زاد الأس بواحد، بينما تبقى الخطوة النسبية نحو 2⁻²³. وينتهي الخط عند (2 - 2⁻²³) × 2¹²⁷، ولا يأتي بعده إلا +∞.

Positive FP32 axis: evenly spaced subnormals, normals whose spacing doubles each binade, then infinityالمحور الموجب لصيغة FP32: subnormals متساوية المسافات، ثم أعداد normal تتضاعف المسافة بينها في كل binade، ثم اللانهاية

Recall

How many FP32 bit patterns are NaN, how many are infinities, and how many are zeros?كم نمطًا من أنماط bits في FP32 هو NaN، وكم منها infinity، وكم منها أصفار؟

NaN: exponent 255 with any of the 2²³ - 1 nonzero fractions, for both signs, so 2²⁴ - 2. Infinity: 2 (+∞ and -∞). Zero: 2 (+0 and -0).

NaN: الأس 255 مع أي من الـ 2²³ - 1 fraction غير الصفرية، وللإشارتين معًا، أي 2²⁴ - 2. Infinity: 2 (+∞ و-∞). الصفر: 2 (+0 و-0).

Quick checkاختبار سريع

An FP32 word has exponent field 11111111 and fraction 00000000000000000000001. What does it encode?كلمة FP32 حقل أسها 11111111 والـ fraction فيها 00000000000000000000001. ماذا ترمّز؟

Quick checkاختبار سريع

Decode 0 10000000 01000000000000000000000 into a decimal value.فكّ النمط 0 10000000 01000000000000000000000 إلى قيمة عشرية.

Recapالخلاصة

If you remember nothing elseإن لم تتذكر شيئاً آخر فتذكّر هذا

  • FP32 = 1 sign bit, 8 exponent bits, 23 fraction bits. Bias = 127 = 2^(8-1) - 1.صيغة FP32 = 1 bit للإشارة (sign)، و8 bits للأس (exponent)، و23 bit للكسر (fraction). والـ bias = 127 = 2^(8-1) - 1.
  • Normal (exponent 1 to 254): (-1)^sign x (1 + Fraction) x 2^(Exponent - 127). The leading 1 is implicit and not stored.العدد normal (الأس من 1 إلى 254): (-1)^sign x (1 + Fraction) x 2^(Exponent - 127). الـ 1 في البداية ضمني (implicit) ولا يُخزَّن.
  • Subnormal (exponent 0): (-1)^sign x Fraction x 2^(1 - 127) = (-1)^sign x Fraction x 2^-126. No implicit 1, so zero becomes encodable.العدد subnormal (الأس 0): (-1)^sign x Fraction x 2^(1 - 127) = (-1)^sign x Fraction x 2^-126. لا يوجد 1 ضمني، لذلك يصبح تمثيل الصفر ممكنًا.
  • The forced 1 - 127 keeps the step size 2^-149 on both sides of 2^-126, so subnormals meet normals with no gap.الأس المفروض 1 - 127 يُبقي حجم الخطوة 2^-149 على جانبي 2^-126، فتلتقي الـ subnormals بالـ normals بلا أي فجوة.
  • Smallest subnormal 2^-149; largest subnormal 2^-126 - 2^-149; smallest normal 2^-126; largest normal (2 - 2^-23) x 2^127, about 3.4 x 10^38.أصغر subnormal هو 2^-149؛ وأكبر subnormal هو 2^-126 - 2^-149؛ وأصغر normal هو 2^-126؛ وأكبر normal هو (2 - 2^-23) x 2^127، أي نحو 3.4 x 10^38.
  • Exponent 255: fraction 0 is plus or minus infinity, any other fraction is NaN, which spends 2^23 - 1 patterns per sign.الأس 255: إذا كان الـ fraction يساوي 0 فهو موجب أو سالب ما لا نهاية (infinity)، وأي fraction آخر هو NaN، وهذا يستهلك 2^23 - 1 نمطًا لكل إشارة.
  • Zero has two encodings, +0 and -0, both with exponent 0 and fraction 0.للصفر تمثيلان، +0 و-0، وكلاهما بأس 0 وfraction يساوي 0.

Sourcesالمصادر