blob: 35ef87585b0bc2a694bc898be51cbeb5783b6a45 [file]
<html lang="en">
<head>
<title>logb - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Math.html#Math" title="Math">
<link rel="prev" href="log2.html#log2" title="log2">
<link rel="next" href="lrint.html#lrint" title="lrint">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="logb"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="lrint.html#lrint">lrint</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="log2.html#log2">log2</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Math.html#Math">Math</a>
<hr>
</div>
<h3 class="section">1.37 <code>logb</code>, <code>logbf</code>&ndash;get exponent of floating-point number</h3>
<p><a name="index-logb-106"></a><a name="index-logbf-107"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;math.h&gt;
double logb(double <var>x</var>);
float logbf(float <var>x</var>);
</pre>
<p><strong>Description</strong><br>
The <code>logb</code> functions extract the exponent of <var>x</var>, as a signed integer value
in floating-point format. If <var>x</var> is subnormal it is treated as though it were
normalized; thus, for positive finite <var>x</var>,
1 &lt;= (<var>x</var> * FLT_RADIX to the power (-logb(<var>x</var>))) &lt; FLT_RADIX.
A domain error may occur if the argument is zero.
In this floating-point implementation, FLT_RADIX is 2. Which also means
that for finite <var>x</var>, <code>logb</code>(<var>x</var>) = <code>floor</code>(<code>log2</code>(<code>fabs</code>(<var>x</var>))).
<p>All nonzero, normal numbers can be described as
<var>m</var> * 2**<var>p</var>, where 1.0 &lt;= <var>m</var> &lt; 2.0.
The <code>logb</code> functions examine the argument <var>x</var>, and return <var>p</var>.
The <code>frexp</code> functions are similar to the <code>logb</code> functions, but
returning <var>m</var> adjusted to the interval [.5, 1) or 0, and <var>p</var>+1.
<p><br>
<strong>Returns</strong><br>
<!-- Formatting note: "$@" forces a new line -->
When <var>x</var> is:<br>
+inf or -inf, +inf is returned;<br>
NaN, NaN is returned;<br>
0, -inf is returned, and the divide-by-zero exception is raised;<br>
otherwise, the <code>logb</code> functions return the signed exponent of <var>x</var>.
<p><br>
<strong>Portability</strong><br>
ANSI C, POSIX
<p><br>
<strong>See Also</strong><br>
frexp, ilogb
<p><br>
</body></html>