हिंदी माध्यम नोट्स
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 “)
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 को पढेगे |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
21 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
21 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
3 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
3 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago