YouTip
Home
JavaScript
PHP
Python3
HTML
C#
Python
Java
PyTorch
Linux
C
jQuery
CSS
XML
jQuery UI
Bootstrap
C++
Angular
HTML DOM
Redis
Web Building
Home
>
C
>
C Function Frexp
C Function Frexp
π 2026-06-14 | π C
[ C Standard Library -
](#) ## Description The C library function **double frexp(double x, int *exponent)** decomposes the floating-point number x into a mantissa and an exponent. It returns the mantissa and stores the exponent in **exponent**. The resulting relationship is **x = mantissa * 2 ^ exponent**. `frexp()` is a function from the C standard library `
` used to decompose a floating-point number into a normalized significand (mantissa) and a base-2 exponent. It is commonly employed for advanced floating-point operations such as normalization and numerical analysis. ## Declaration Below is the declaration of the frexp() function. #include
double frexp(double x, int *exp);float frexpf(float x, int *exp);long double frexpl(long double x, int *exp); ## Parameters * `x`: The floating-point number to be decomposed. * `exp`: A pointer to an integer where the base-2 exponent will be stored. ## Return Value * Returns the significand (mantissa) of `x`, such that `x = mantissa * 2^exp`, where `mantissa` is the return value and lies in the range [0.5, 1.0) or [-1.0, -0.5], and `exp` is the exponent. ## Example The following example demonstrates the usage of the frexp() function. ## Example #include #include
int main () { double x =1024, fraction; int e; fraction =frexp(x,&e); printf("x = %.2lf = %.2lf * 2^%dn", x, fraction, e); return(0); } Letβs compile and run the above program, which will produce the following output: x = 1024.00 = 0.50 * 2^11 ### Handling Multiple Floating-Point Numbers The following example shows how to process multiple floating-point numbers: ## Example #include #include
int main(){ double values[]={0.5,1.0,4.0,10.0,16.0}; int num_values =sizeof(values)/sizeof(values); for(int i =0; i < num_values; i++){ double x = values; int exponent; double mantissa =frexp(x,&exponent); printf("x = %f, mantissa = %f, exponent = %dn", x, mantissa, exponent); } return 0; } Letβs compile and run the above program, which will produce the following output: x = 0.500000, mantissa = 0.500000, exponent = 0 x = 1.000000, mantissa = 0.500000, exponent = 1 x = 4.000000, mantissa = 0.500000, exponent = 3 x = 10.000000, mantissa = 0.625000, exponent = 4 x = 16.000000, mantissa = 0.500000, exponent = 5 ### Code Explanation * Define an array `values` containing multiple floating-point numbers. * Use a `for` loop to iterate over each value, call `frexp()` to decompose it, and print the results. ### Practical Applications of `frexp()` `frexp()` is commonly used for normalized representation of floating-point numbers and various algorithms in numerical analysis. It helps avoid overflow and underflow issues that may arise when manipulating floating-point numbers directly. The following example demonstrates how to decompose and reconstruct a floating-point number using `frexp()` and `ldexp()` (a related function): ## Example #include #include
int main(){ double x =123.456; int exponent; double mantissa =frexp(x,&exponent); // Reconstruct the floating-point number double reconstructed_x =ldexp(mantissa, exponent); printf("Original x = %fn", x); printf("Mantissa = %f, Exponent = %dn", mantissa, exponent); printf("Reconstructed x = %fn", reconstructed_x); return 0; } Letβs compile and run the above program, which will produce the following output: Original x = 123.456000Mantissa = 0.964500, Exponent = 7Reconstructed x = 123.456000 ### Code Explanation * Define a floating-point number `x` with value 123.456. * Use `frexp()` to decompose `x` into its significand and exponent. * Use `ldexp()` to reconstruct the original floating-point number from the significand and exponent. * Print the original value, the significand, the exponent, and the reconstructed floating-point number. ### Summary The `frexp()` function decomposes a floating-point number into its significand and exponent, serving as an essential tool for floating-point arithmetic. By appropriately utilizing `frexp()`, efficient floating-point operations can be achieved in numerical analysis, scientific computing, and engineering applications. [ C Standard Library -
](#)
β C Function Ldexp
C Function Exp β
π Categories
β‘ JavaScript
(1589)
π PHP
(872)
π Python3
(810)
π HTML
(691)
βοΈ C#
(650)
π Python
(594)
β Java
(552)
βοΈ PyTorch
(534)
π§ Linux
(472)
βοΈ C
(432)
π¦ jQuery
(406)
π¨ CSS
(377)
π XML
(259)
π¦ jQuery UI
(231)
π― Bootstrap
(220)
βοΈ C++
(215)
π °οΈ Angular
(205)
π HTML DOM
(201)
π΄ Redis
(188)
π Web Building
(142)
π Vue.js
(141)
π R
(131)
πΌ Pandas
(124)
ποΈ SQL
(105)
βοΈ Docker
(86)
βοΈ TypeScript
(73)
βοΈ Highcharts
(70)
π AI Agent
(70)
βοΈ React
(68)
π Node.js
(65)
βοΈ Machine Learning
(60)
π Git
(59)
π΅ Go
(58)
π Markdown
(58)
π’ NumPy
(55)
π§ͺ Flask
(54)
βοΈ Scala
(53)
ποΈ SQLite
(52)
π JSTL
(52)
βοΈ VS Code
(51)
π MongoDB
(49)
π Perl
(48)
π Ruby
(47)
π Matplotlib
(47)
βοΈ Uncategorized
(46)
π Swift
(46)
ποΈ PostgreSQL
(46)
βοΈ Data Structures
(46)
π Playwright
(46)
π iOS
(45)
ποΈ MySQL
(44)
βοΈ LangChain
(43)
π FastAPI
(40)
βοΈ Ionic
(38)
π Design Patterns
(37)
βοΈ Eclipse
(37)
π¨ CSS3
(34)
π Lua
(34)
βοΈ Codex
(34)
πΈ Django
(32)
βοΈ OpenCV
(32)
π Rust
(31)
π JSP
(31)
βοΈ Claude Code
(31)
π Pillow
(30)
βοΈ OpenCode
(28)
π AI Skills
(27)
π Flutter
(26)
π Maven
(26)
π¨ Tailwind CSS
(25)
π§ TensorFlow
(25)
π Servlet
(24)
π Dart
(23)
π Assembly
(23)
βοΈ Memcached
(22)
βοΈ SVG
(22)
βοΈ Electron
(22)
π NLP
(22)
π Regex
(21)
π Android
(20)
π£ Kotlin
(19)
π Julia
(19)
π SOAP
(17)
π Selenium
(17)
π PowerShell
(17)
π Sass
(16)
π HTTP
(16)
π Zig
(15)
π AI
(15)
π AJAX
(14)
π Swagger
(14)
βοΈ Scikit-learn
(13)
βοΈ ECharts
(13)
βοΈ Chart.js
(13)
βοΈ Cursor
(13)
βοΈ SciPy
(12)
π RDF
(12)
π Ollama
(12)
π Next.js
(12)
π Plotly Dash
(12)
π JSON
(11)
π RESTful API
(11)
π WSDL
(9)
βοΈ CMake
(8)
π Firebug
(7)
π Nginx
(6)
βΈοΈ Kubernetes
(6)
π Jupyter
(6)
π LaTeX
(4)
π UniApp
(4)
ποΈ SQL Server
(1)