frexp()函數將浮點數x分解為其二進製有效位數,即絕對值介於[0.5,1.0)和2的整數 index 之間的浮點。
x =有效數*(2 ^ index )。
它曾經用於:
1. It is used to find significand which is always between 0.5 and 1.0 2. It is used to find exponent which is power of 2.
用法:
double frexp (double x); float frexp (float x); long double frexp (long double x);
參數:
- The frexp() function takes a single argument.
返回:
- The frexp() function returns the binary significand whose absolute value lies in the interval [0.5, 1).
- If x is zero, both significand and exponent are zero.
錯誤和異常:
- 必須提供兩個參數,否則將產生錯誤的不匹配函數,無法調用“ frexp()”。
- 如果我們將字符串作為參數傳遞,則將出現錯誤,沒有匹配的函數調用'frexp(const char [n])。
-
- 如果x = 0,則有效數為零, index 為零
- x> = 1,則有效位數為正數, index 為正數
- X
- -1
- 0
#代碼1
// CPP implementation of
// above function
#include <cmath>
#include <iostream>
using namespace std;
// Driver program
int main()
{
double x = 5.35, significand;
int exponent;
significand = frexp(x, &exponent);
cout << x << " = " << significand
<< " * 2^" << exponent << endl;
return 0;
}
輸出:
5.35 = 0.66875 * 2^3
#代碼2
// CPP implementation of the
// above function
#include <cmath>
#include <iostream>
using namespace std;
// Driver program
int main()
{
double significand;
int exponent, x = 5;
significand = frexp(x, &exponent);
cout << x << " = " << significand
<< " * 2^" << exponent << endl;
return 0;
}
輸出:
5 = 0.625 * 2^3
相關用法
注:本文由純淨天空篩選整理自pawan_asipu大神的英文原創作品 frexp() in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。