JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

C 99 : Floating Point Macro (Part 2) in c language in hindi , FEGETROUND ,FESETROUND , FEGETENV ,FESETENV

FEGETROUND ,FESETROUND , FEGETENV ,FESETENV , C 99 : Floating Point Macro (Part 2) in c language in hindi :-
इससे पहले वाले article मे , हमने arthmatic operation related error को पढ़ा |अब इस article मे , floating number को rounding को पढेगे |सबसे पहले recap करेगे |
इस header file मे निन्म  macro होते है |
1. FE_DIVBYZERO : ये तब occur होती है जब किसी integer को ‘0’ से डिवाइड किया जाता |है
2. FE_INEXACT :ये तब occur होती है जब किसी expression का आउटपुट अशांत flaoting number हो |
3. FE_INVALID : जब किसी function मे invalid argument को pass किया जाता है जिसका आउटपुट  floating point number हो |
4. FE_OVERFLOW: जब किसी expression के आउटपुट की range ओवर हो जाती है |
5.FE_UNDERFLOW:जब किसी expression के आउटपुट की range,float number की range से बहुत कम  होती है |
इनके अलावा इस header file मे  floating number के rounding के लिए macro होते है :-
1. FE_DOWNWORD : इस macro का use , floating number को negative infinity की तरफ movement करने के लिए किया जता है |
2. FE_TONEAREST : इस macro का use , floating number को nearest represtable number की ओर movement के लिए किया जाता है |
3. FE_TOWARDZERO : इस macro का use , floating number को zero की ओर movement करने के लिए किया जाता है |
4. FE_UPWARD: इस macro का use , floating number को positive infinity की तरफ movement करने  के लिए किया जाता है |
ये सभी macro constant , non negative integer constant expression  से expand किया जाता है | इस use करने के लिए std:: fesetround और std:: fegetround को use किया जाता है |
l सभी floating rounding का use किया जाता है :-
1.किसी arithmatic operation जिसका type constant expression होता है |
2. किसी standard function के आउटपुट मे |
3.floating point से floating point implicit conversion मे |
4.string conversion मे |
5.Libarary rounding function (nearbyint , rint , lrint आदि) मे |
इसकेअलावा rounding निन्म को effect नहीं करता है |
1.floating point तो integer type conversion
2.किसी airthmatic operation जो run time पर execute होता है |
3.libary  rounding function ( round, lround , llround , ceil, floor आदि ) मे

Function

1. fegetround ,fesetround

इन macro statement से किसी floating point के rounding mode को set/ reset करने के लिए  किया जाता है |इन्हें set/reset करने के बाद libary rounding function को use किया जाता है |
1.i)fegetround
इस macro का use , किसी floating point variable के mode को उपर दिए  गये चार modes मे से एक mode को सेलेक्ट करने के लिए  किया जाता है |इस function मे एक ही argument pass होते है | (i) mode का नाम | ये macro ‘0’ return करता है अगर rounding success हो जाती है |अन्यथा ‘1’ return होता है |
1.ii)fesetround
इस macro का use , किसी floating point variable के mode को उपर दिए  गये चार modes मे से एक mode को reset करने के लिए  किया जाता है |इस function मे एक ही argument pass होते है | (i) mode का नाम | ये macro ‘0’ return करता है अगर rounding success हो जाती है |अन्यथा ‘1’ return होता है |
उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
#include<cfenv.h>
#include<math.h>
void main()
{
float a , b;
printf(“Enter a Floating Number”);
scnaf(“%f”, & a);
printf(“Enter another Floating Number “);
scanf(“%f”,&b);
fegetround (FE_DOWNWORD);
printf(“Value =%f”, floor(a));
printf(“Value =%f”, nerbyint(a));
printf(“Value =%f”, nerbyint(b));
printf(“Value =%f”, floor(b));
fesetround(FE_TONEAREST)
printf(“Value =%f”, floor(a));
printf(“Value =%f”, nerbyint(a));
printf(“Value =%f”, nerbyint(b));
printf(“Value =%f”, floor(b));
getch()
}
इस उदाहरण मे , सबसे पहले FE_DOWNWARD rounding को set किया गया है फिर floor और nearbyint function को call किया है |
बाद मे , FE_TONEAREST rounding को  FE_DOWNWARD के जगह रिसेट किया गया है और  floor और nearbyint function को call किया है |
इसका आउटपुट होगा |
Enter a Floating Number 23.3
Enter another Floating Number 45.5
Value =23
Value =23
Value =45
Value =45
Value =24
Value =24
Value =24
Value =24

2. fegetenv ,fesetenv

इन macro statement से किसी floating point के rounding mode को access करके use किसी भी समय पर set  करने के लिए  किया जाता है |इन्हें set करने के बाद libary rounding function को use किया जाता है |
1.i)fegetenv
इस macro का use , किसी floating point variable के current mode को copy करने के लिए  किया जाता है |इस function मे एक ही argument pass होते है | (i)fenv_t type का pointer को pass किया जाता जो current mode को hold करता है  | ये macro ‘0’ return करता है अगर rounding success हो जाती है |अन्यथा ‘1’ return होता है |
1.ii)fesetround
इस macro का use , fegetenv से copy किया गया mode को  set करने के लिए  किया जाता है |इस function मे एक ही argument pass होते है | (i) fenv_t type का pointer को pass किया जाता जिसमे  current mode को hold है  | | ये macro ‘0’ return करता है अगर rounding success हो जाती है |अन्यथा ‘1’ return होता है |
उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
#include<cfenv.h>
#include<math.h>
void main()
{
fenv_t *type;
float a , b;
printf(“Enter a Floating Number”);
scnaf(“%f”, & a);
printf(“Enter another Floating Number “);
scanf(“%f”,&b);
fegetround (FE_DOWNWORD);
printf(“Value =%f”, floor(a));
printf(“Value =%f”, nerbyint(-12.56));
printf(“Value =%f”, nerbyint(b));
printf(“Value =%f”, floor( 12.70));
fegetenv(type);
fesetround(FE_TONEAREST)
printf(“Value =%f”, floor(a));
printf(“Value =%f”, nerbyint(12.65));
printf(“Value =%f”, nerbyint(b));
printf(“Value =%f”, floor(b));
fesetround(type)
printf(“Value =%f”, floor(a));
printf(“Value =%f”, nerbyint(34.6));
printf(“Value =%f”, nerbyint(b));
printf(“Value =%f”, floor(b));
getch()
}
इस उदाहरण मे , सबसे पहले FE_DOWNWARD rounding को set किया गया है फिर floor और nearbyint function को call किया है |
बाद मे , FE_TONEAREST rounding को  FE_DOWNWARD के जगह रिसेट किया गया है और  floor और nearbyint function को call किया है |
इसका आउटपुट होगा |
Enter a Floating Number 23.3
Enter another Floating Number 45.5
Value =23
Value = -13
Value =45
Value =12
Value =24
Value =12
Value =45
Value =45
Value =24
Value =34
Value =45
Value =45
इस प्रकार से floating point मे rounding mode को set करने की facility C99 मे होती  है |
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