JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

C 99 : Floating Point Macro (Part -1 ) in c language in hindi , feclearexcept , fetestexcept , feraiseexcept

feclearexcept , fetestexcept , feraiseexcept , C 99 : Floating Point Macro (Part -1 ) in c language in hindi :-
C 99 मे , floating point variable को handle करने के लिए कई सारे macro को define किया गया है | इन macro से floating point variable के status ,flags और control modes से float point पर control किया जा सकता है |इसमें thread होते है |सभी thread ,प्रोग्राम के initial stage पर अपने parent thread से initial होते  है|floating point operation से इन floating flag के status change हो जाता है |और floating point control signal की value , floating operation के आउटपुट से effect होती है |
floating point macro को use तभी कर सकते है जब pragma_STDC_FENV_ACCESS ,on condition मे होती है |अगर ‘on ‘ condition नहीं होती तब प्रोग्राम नार्मल प्रोग्राम की तरह कार्य करता है |
कुछ C Complier जैसे HP aCC ,Oracle studio और IBM XL मे pragma_STDC_FENV_ACCESS को define करना होता है लेकिन most of the COMPLIER  मे floating point को access कर सकते है |
floating point macro को प्रोग्राम मे add करने के लिए दो प्रकार के declarationको use कर सकते है :-
fenv _t : इस प्रकार के declaration से पुरे floating type macro को use कर सकते है |
fexcept_t : इस प्रकार के declaration से floating type environment मे से flag को ही access कर सकते है |
इस environment मे , निन्म function include होते है :-
1. feclearexcept
इस function का use floating point environment के सभी floating point exception clear करने के लिए किया जाता है |floating point exception का मतलब है floating point related error |अगर सभी flaoting point error clear हो जाती है तब function से ‘0’ return होगा अन्यथा ‘1’ return होगा |
इस function मे excepts( bitmask listing the exception flags  to clear) ,argument की तरह pass होता है और बिट ‘0’ या ‘1’ return होता है |
#include<stdio.h>
#include<conio.h>
#include<fenv.h>
#include<math.h>
# pragma_STDC_FENV_ACCESS on
void main()

 

{
int a;

 

printf(“Enter Data”);
scanf(“%d”,&a);
float b=sqrt(a);
feclearexcept (FE_ALL_EXCEPT);
if(feclearexcept (FE_INVALID))
{
printf(“User input negative value.\n”);
printf(“Sqrt(input) can not calculate.”);
}
else
{
printf(“sqrt(input) = %f”,b);
}
getch();
}
अगर द्वारा input की गयी value नेगेटिव होती है तब square root find नहीं हो सकता है |और error message print हो जाता है |
आउटपुट होगा :
Enter data -4
User input negative value
Sqrt(input) can not calculate.
2. fetestexcept
इस macro का use , floating point error को find करने के लिए किया जाता है |इस macro से floating point
error को specify किया जाता है |इसमें pre set floating point code होते है जिनके occur होने पर हम error को indentify किया जा सकता है |
इसके लिए pre set error codes होते है :
1.FE_DIVBYZERO : ये तब occur होती है जब किसी integer को ‘0’ से डिवाइड किया जाता |है
2.FE_INEXACT :ये तब occur होती है जब किसी expression का आउटपुट अशांत floating number हो |
3.FE_INVALID : जब किसी function मे invalid argument को pass किया जाता है जिसका आउटपुट  floating point number हो |
4.FE_OVERFLOW: जब किसी expression के आउटपुट की range ओवर हो जाती है |
5.FE_UNDERFLOW:जब किसी expression के आउटपुट की range,float number की range से बहुत कम  होती है |
इसका उदाहरण होगा
#include<stdio.h>
#include<conio.h>
#include<fenv.h>
#include<math.h>
# pragma_STDC_FENV_ACCESS on
void main()

 

{
int a;

 

printf(“Enter Data”);
scanf(“%d”,&a);
printf(“square root = %f “, sqrt (a));
int d=a/0;
printf(” %d/0 = %f  “, a,d );
printf(“Power Function = %f”,a/pow(2,45));
error();
getch();
}
void error()
{
printf(“Error”);
if ( fetestexcept (FE_DIVBYZERO) )
printf(“Divide by zero”);
if ( fetestexcept (FE_INEXACT) )
printf(” Inexact error “);
if ( fetestexcept (FE_INVALID) )
printf(“Invalid argument error”);
if ( fetestexcept (FE_OVERFLOW) )
printf(“Overflow Error”);
if ( fetestexcept (FE_UNDERFLOW) )
printf (” Underflow Error”);
}
आउटपुट होगा :
Enter data -3
square root = -nan
-3/0 = inf
Power Function = inf
Error
Invalid argument error
Divide by zero
Overflow Error
3. feraiseexcept
इस function का use सभी error को find करने के लिए के लिए किया जाता है | इसमें macro मे सभी error codes लॉजिकल OR operation के pass होती है | जैसे अगर किसी प्रोग्राम मे , overflow या underflow error आती है तब Inexact error  भी जरुर होगी इसलिए in दोनों error message को print किया जाता है |
इसका उदहारण है :-
#include<stdio.h>
#include<conio.h>
#include<fenv.h>
#include<math.h>
# pragma_STDC_FENV_ACCESS on
void main()

 

{
int a;

 

printf(“Enter Data”);
printf(“Power Function = %f”,a/pow(2,45));
if(feraiseexcept (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW )
{
printf(“Feraiseexcept Happend “)
error();
}
getch();
}
void error()
{
printf(“Error”);
if ( fetestexcept (FE_DIVBYZERO) )
printf(“Divide by zero”);
if ( fetestexcept (FE_INEXACT) )
printf(” Inexact error “);
if ( fetestexcept (FE_INVALID) )
printf(“Invalid argument error”);
if ( fetestexcept (FE_OVERFLOW) )
printf(“Overflow Error”);
if ( fetestexcept (FE_UNDERFLOW) )
printf (” Underflow Error”);
}
आउटपुट होगा :
Enter data -3
Power Function = inf
Feraiseexcept Happend
Error
Inexact error
Overflow Error
4. fegetexceptflag ,fesetexceptflag
इन macro statement से किसी floating point environment से current flag के status को copy किया जाता है |in status को प्रोग्राम मे बाद मे use किया जा सकता है |
4.i)fegetexceptflag
इस macro का use , किसी floating point environment से flag के status को copy किया जाता है |इस function मे दो argument pass होते है | (i) fexcept_t type का variable जिसमे current flag का status store होता है | (ii) excepts का नाम |
4.ii) fesetexceptflag
इस macro का use , किसी floating point environment से flag के status को paste किया  जाता है |इस function मे दो argument pass होते है | (i) fexcept_t type का variable जिसमे current flag का status store होते है | (ii) excepts का नाम जिसमे flag के status को paste करना है  |
उदाहरण के लिए
#include<stdio.h>
#include<conio.h>
#include<fenv.h>
#include<math.h>
# pragma_STDC_FENV_ACCESS on
void main()

 

{
fexcept_t exc;
feraiseexcept(FE_DIVBYZERO)
error();
fegetexceptflag(&exc , FE_ALL_EXCEPT);
feclearexcept (FE_ALL_EXCEPT);
feraiseexcept(FE_DIVBYZERO | FE_OVERFLOW)
error();
feclearexcept (FE_ALL_EXCEPT);
fesetexceptflag (&exc , FE_ALL_EXCEPT );
error();
feclearexcept (FE_ALL_EXCEPT);
getch();
}
void error()
{
printf(“Error”);
if ( fetestexcept (FE_DIVBYZERO) )
printf(“Divide by zero”);
if ( fetestexcept (FE_INEXACT) )
printf(” Inexact error “);
if ( fetestexcept (FE_INVALID) )
printf(“Invalid argument error”);
if ( fetestexcept (FE_OVERFLOW) )
printf(“Overflow Error”);
if ( fetestexcept (FE_UNDERFLOW) )
printf (” Underflow Error”);
}
आउटपुट होगा :
Divide by zero
Divide by zero
Overflow Error
Overflow Error
इस article मे , asthmatic operation related exception को पढ़ा |अब हम C 99 : Floating Point Macro (Part -2 ) मे direction related exception को पढेगे |
Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now