मुख्य सामग्री पर जाएँ

सिलेबस · CS कंप्यूटर विज्ञान और सूचना प्रौद्योगिकी

विषय के सभी टॉपिक
C प्रोग्रामिंग की बुनियाद6
ऐरे और पॉइंटर7
रिकर्शन6
प्रायिकता और सांख्यिकी की बुनियाद9
डेटाबेस सिस्टम की बुनियाद15
रैखिक बीजगणित की बुनियाद6
कंप्यूटर नेटवर्क की बुनियाद9
कलन की बुनियाद6
संगणना सिद्धांत की बुनियाद9
कंपाइलर डिज़ाइन की बुनियाद9
लिंक्ड लिस्ट, स्टैक और क्यू3
ट्री, बाइनरी सर्च ट्री और हीप3
ग्राफ की बुनियाद3
एल्गोरिदम की बुनियाद12
असतत गणित की बुनियाद15
डिजिटल लॉजिक की बुनियाद22
कंप्यूटर संगठन की बुनियाद12
ऑपरेटिंग सिस्टम की बुनियाद15

Floating-point arithmetic alignment और rounding

पाठ 71 / 1678 मिनटमुफ़्त

पहले exact गणित फिर format का निर्णय

Floating-point arithmetic का अर्थ exponent fields को सामान्य binary integers की तरह बदलना नहीं है। उपयोगी model है: exact mathematical result निकालें, फिर बताए mode से destination format में एक बार round करें। Implementations अतिरिक्त जानकारी रखकर वही परिणाम दे सकती हैं; अनंत digits store करना जरूरी नहीं।

पूर्वज्ञान: binary fractions और पिछले पाठ का सात-bit floating format। वही sign s, bias 3 वाले तीन exponent bits, तीन stored fraction bits, normal precision p=4, positive normal range 1/4…15 और subnormal step 1/32 है। Numerical examples finite range के भीतर हैं। हर बताए operation के बाद round-to-nearest ties-to-even लगता है; hidden extra precision या fused operation नहीं। यह educational arithmetic contract है, हर programming language के evaluation rule का दावा नहीं।

Nearest ties to even

Exact result के सबसे पास representable neighbor चुनें। ठीक midpoint पर उस candidate को लें जिसके retained significand integer का अंतिम bit even है। Subnormal में stored fraction integer देखें। Negative sign का अर्थ हमेशा नीचे round करना नहीं; nearest mode zero के दोनों ओर distance कम करता है।

हल किया उदाहरण 1: [1,2) में values का अंतर 1/8 है। Exact 1.0625, 1.000₂=1 और 1.001₂=1.125 के बीच है। Retained चार-bit significand integers 8 और 9 हैं; even 8 से result 1। Midpoint 1.1875, 1.125 (integer 9) और 1.25 (integer 10) के बीच है, इसलिए 1.25। Tie को हमेशा ऊपर round करना अलग policy है।

Rounding से नए exponent में carry हो सकता है। 1.9375, 1.875 और 2 के बीच है। नीचे के binade की grid पर retained units 15 और 16 हैं; even 16 से 2 चुनें, जिसे 1.000₂×2¹ normalize करते हैं। केवल शुरुआती arithmetic के बाद नहीं, rounding के बाद भी exponent जाँचें।

Addition में binary points align करें

Normal operands को common exponent, प्रायः बड़े exponent, पर लिखें। छोटे significand को right-shift करें लेकिन जरूरी low-bit जानकारी रखें। फिर signed significands जोड़ें, normalize करें, round करें और range/classification जाँचें। Exponent का अंतर shift count है; addition में exponents जोड़ने का निर्देश नहीं।

हल किया उदाहरण 2: 1.5+0.375। 1.5=1.100₂×2⁰ और 0.375=1.100₂×2^−2। Exponent zero पर align करें: 1.10000₂+0.01100₂=1.11100₂। मान 1.875, यानी exact 1.111₂×2⁰ है। Result 2 से कम है, इसलिए exponent zero रहता है।

हल किया उदाहरण 3: 1+0.09375। दूसरा operand subnormal 3/32 के रूप में representable है। Common exact scale पर 1.00000₂+0.00011₂=1.00011₂=1.09375। p=4 में पड़ोसी 1 और 1.125 हैं; distances 0.09375 तथा 0.03125, इसलिए rounded result 1.125। निर्णय से पहले सभी low bits हटाने से गलत 1 मिलता। छोटा operand भी rounding बदल सकता है।

Guard round और sticky जानकारी

Retained significand के बाद अगला bit G यानी guard, फिर R यानी round, और बाकी सभी discarded bits का OR, S यानी sticky है। Retained अंतिम bit को L कहें। Nearest ties-to-even में retained magnitude ठीक तब बढ़ाएँ जब G=1 और R,S,L में कम-से-कम एक 1 हो। G=0 पर tail आधे से कम। G=1,R=S=0 पर exact tie है और L evenness तय करता है।

1.00011₂ को p=4 पर retained 1.000, G=1,R=1,S=0 मिलता है; बढ़ाकर 1.001। 1.00010₂ में G=1,R=0,S=0,L=0 है, इसलिए 1.000 रखें। Sticky पूरे बाकी tail का OR है, केवल अंतिम bit नहीं। यह final rounding समझाता है; पूरे arithmetic unit को alignment, subtraction और normalization में भी जरूरी जानकारी बचानी होगी।

Subtraction और cancellation

Signed opposite जोड़कर subtract करें, लेकिन leading bits cancel होते समय पर्याप्त जानकारी रखें। हल किया उदाहरण 4: 1.5−1.375=1.100₂−1.011₂=0.001₂=0.125। हमारे format में यह exact subnormal 0|000|100 है, क्योंकि 4/32=0.125। Normal threshold से नीचे परिणाम जरूरी नहीं zero या inexact हो।

Cancellation, leading significant bits हटाता है और पहले से मौजूद input error को छोटे answer की तुलना में बड़ा बना सकता है। इसका अर्थ हर close-number subtraction गलत rounded होना नहीं; ऊपर का exact उदाहरण सही है। पहले rounded operands में खोई जानकारी और current operation की rounding अलग रखें।

Zero के पास भी nearest rounding वास्तविक neighbors से होती है। Exact 1/64, zero और smallest subnormal 1/32 का midpoint है। Fraction integers 0 और 1 हैं, इसलिए ties-to-even से zero। Exact 3/64, 1/32 और 2/32 के बीच है; even 2 से 1/16। ये tiny और inexact examples हैं; 1/8 जैसा exact representable subnormal अलग है।

Multiplication और division

Normal multiplication में significands गुणा और true exponents जोड़ें, फिर normalize/round करें। Encoded exponents में E_out=E_a+E_b के लिए normalization adjustments से पहले e_out=e_a+e_b−bias है। एक bias हटाए बिना दोनों biased exponents जोड़ना गलत है। Nonzero finite operands में product sign, दोनों sign bits का XOR है।

हल किया उदाहरण 5: 1.625×1.375=(13/8)(11/8)=143/64=2.234375। [2,4) binade में spacing 1/4 है। पास के values 2 और 2.25 की distances 15/64 और 1/64 हैं, इसलिए result 2.25। यह 1.001₂×2¹ है; normalization और rounding दोनों देखें।

Normal division में significands भाग और true exponents घटाएँ, फिर normalize/round करें। उदाहरण 1/3 की binary expansion finite नहीं। इस format में neighbors 10/32=0.3125 और 11/32=0.34375 हैं। 1/3 से distances क्रमशः 1/48 और 1/96, इसलिए nearest result 11/32। दो representable operands का division जरूरी नहीं exact representable हो।

Rounding से algebraic व्यवहार बदलता है

हल किया उदाहरण 6: a=8,b=0.5,c=−8, तीनों representable हैं। हर operation के बाद rounding में a+b=8.5, 8 और 9 का tie है; even significand से 8 चुनते हैं। अतः (a+b)+c=0। लेकिन b+c=−7.5 exact है, इसलिए a+(b+c)=0.5 exact। Real addition associative है, लेकिन इस contract में floating addition नहीं।

इसी तरह product round करके फिर जोड़ना, fused multiply-add के एक ही final rounding जैसा जरूरी नहीं। Results की तुलना में evaluation contracts न मिलाएँ।

Exceptions और अंतिम checklist

Exact magnitude finite range से बाहर हो तो range/rounding समस्या पहचानकर चुने overflow-mode का नियम लगाएँ। Exponent bits truncate करना floating overflow handling नहीं है। IEEE-style arithmetic में infinity और NaN के अलग नियम हैं: 0/0 जैसी invalid form सामान्य finite division नहीं; infinity भी NaN नहीं। पूरे exception flags, signaling NaNs और trap handling इस पाठ के बाहर हैं।

Format/rounding mode लिखें; operands classify करें; addition में align या multiplication/division में true exponents जोड़ें/घटाएँ; low-bit जानकारी रखें; normalize; round; carry आए तो फिर normalize; result classify/range-check करें। छोटे cases exact fractions से जाँचें, किसी दूसरे अनिर्दिष्ट floating format के decimal display से नहीं।

मौलिक अभ्यास

ये छह single-correct MCQ सीखने के लिए बनाए गए मौलिक प्रश्न हैं, पिछले वर्षों के प्रश्न नहीं। हर प्रश्न में ठीक एक विकल्प चुनें।

C01. p=4 educational format में exact 1.0625 को nearest ties-to-even से round करें। परिणाम क्या है?

A. 1.125 B. 1 C. 1.0625 exact D. 0.9375

उत्तर: B

A गलत है: इस tie में odd retained significand चुना गया।

B सही है: पड़ोसियों के significand integers 8 और 9 हैं; even 8 से 1।

C गलत है: चार significant bits में 1.0001₂ exact नहीं समाता।

D गलत है: यह दो nearest neighbors में नहीं है।

C02. उसी format और rounding mode में 1+0.09375 का rounded sum क्या है?

A. 1 B. 1.25 C. 1.125 D. 0.09375

उत्तर: C

A गलत है: exact 1.09375, 1 की तुलना में 1.125 के अधिक पास है।

B गलत है: 1.25 तत्काल ऊपरी neighbor से दूर है।

C सही है: 1 और 1.125 से distances 0.09375 और 0.03125 हैं।

D गलत है: पहला operand ही छोड़ दिया।

C03. Retained अंतिम bit L और discarded G,R,S के लिए nearest ties-to-even में increment की शर्त क्या है?

A. G AND (R OR S OR L) B. अन्य bits कुछ भी हों, हमेशा G C. केवल R AND S D. NOT G

उत्तर: A

A सही है: आधे से ऊपर tail में increment; exact tie में केवल odd retained value बढ़ती है।

B गलत है: G=1,R=S=L=0 में retained value पहले से even है।

C गलत है: odd L वाले exact ties और कई above-half tails छूटते हैं।

D गलत है: G=0 का tail आधे से कम है।

C04. Educational format का subnormal step 1/32 है। Exact 3/64 nearest ties-to-even में क्या बनेगा?

A. 0 B. 1/32 C. 3/64 exact D. 1/16

उत्तर: D

A गलत है: zero दोनों पास के positive candidates से दूर है।

B गलत है: midpoint पर fraction integer 1 odd है।

C गलत है: 3/64 पूर्णांक subnormal steps नहीं, encoding नहीं।

D सही है: fraction integers 1 और 2 के tie में even 2 से 2/32=1/16।

C05. इस format में हर addition के बाद rounding है; a=8,b=0.5,c=−8। ((a+b)+c, a+(b+c)) की सही जोड़ी कौन-सी है?

A. 0.5, 0.5 B. 0, 0.5 C. 0, 0 D. 0.5, 0

उत्तर: B

A गलत है: a+b=8.5 से even-significand 8 मिलता है; उस grouping में b खोता है।

B सही है: बायाँ 8−8=0; b+c=−7.5 exact से दायाँ 0.5।

C गलत है: दाईं grouping के दोनों operations exact हैं।

D गलत है: छोटी contribution खोने वाली grouping उलट दी।

C06. Bias B वाले normal multiplication में special fields न हों तो normalization adjustments से पहले encoded output exponent क्या है?

A. e_a+e_b B. e_a−e_b+B C. e_a+e_b−B D. e_a+e_b−2B

उत्तर: C

A गलत है: एक अतिरिक्त bias बच जाता है।

B गलत है: यह normalization से पहले division का exponent संबंध है।

C सही है: true sum e_a+e_b−2B में destination bias जोड़ने से e_a+e_b−B।

D गलत है: यह true exponents का योग है, encoded exponent नहीं।

सीमा और स्रोत

यह Digital Logic के एक सीमित हिस्से का पाठ है, पूरे GATE CS की तैयारी नहीं। आधिकारिक पाठ्यक्रम केवल विषय की प्रासंगिकता की पुष्टि करता है; व्युत्पत्तियाँ, उदाहरण और अभ्यास मौलिक हैं। तकनीकी संदर्भों से representation और circuit की conventions जाँची गई हैं; उनके अभ्यास प्रश्न नहीं दोहराए गए।

स्रोत 14 अक्टूबर 2026 को जाँचे गए।

प्रगति सहेजने के लिए साइन इन करें। साइन इन