上传cppreference

This commit is contained in:
2025-08-01 12:57:54 +08:00
parent e29892f8cd
commit 196e706fe4
5485 changed files with 982007 additions and 3 deletions

View File

@@ -0,0 +1,182 @@
<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_numeric_fenv_FE_exceptions skin-cppreference2 action-view cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><small>FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT</small></h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-numeric.html">numeric</a>&lrm; | <a href="cpp-numeric-fenv.html">fenv</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<table class="t-dcl-begin">
<tbody>
<tr class="t-dsc-header">
<td>
<div>&#23450;&#20041;&#20110;&#22836;&#25991;&#20214; <code><a href="cpp-header-cfenv.html">&lt;cfenv&gt;</a></code></div>
</td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_DIVBYZERO &nbsp; &nbsp;/*implementation defined power of 2*/</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_INEXACT &nbsp; &nbsp; &nbsp;/*implementation defined power of 2*/</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_INVALID &nbsp; &nbsp; &nbsp;/*implementation defined power of 2*/</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_OVERFLOW &nbsp; &nbsp; /*implementation defined power of 2*/</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_UNDERFLOW &nbsp; &nbsp;/*implementation defined power of 2*/</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="co2">#define FE_ALL_EXCEPT &nbsp;FE_DIVBYZERO | FE_INEXACT | \<br /></span></span>
<p><span class="mw-geshi cpp source-cpp">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FE_INVALID | FE_OVERFLOW | &nbsp;\<br /></span></p>
<span class="mw-geshi cpp source-cpp">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FE_UNDERFLOW</span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#25152;&#26377;&#36825;&#20123;&#23439;&#24120;&#37327;&#65288;&#38500;&#20102; <span class="t-lc"><strong class="selflink">FE_ALL_EXCEPT</strong></span> &#65289;&#37117;&#23637;&#24320;&#25104;&#20540;&#20026; 2 &#30340;&#30456;&#24322;&#27425;&#24130;&#25972;&#25968;&#24120;&#37327;&#34920;&#36798;&#24335;&#65292;&#21807;&#19968;&#22320;&#37492;&#21035;&#25152;&#26377;&#21463;&#25903;&#25345;&#28014;&#28857;&#24322;&#24120;&#12290;&#27599;&#20010;&#23439;&#20165;&#33509;&#21463;&#25903;&#25345;&#25165;&#24471;&#21040;&#23450;&#20041;&#12290;</p>
<p>&#23439;&#24120;&#37327; <span class="t-lc"><strong class="selflink">FE_ALL_EXCEPT</strong></span> &#23637;&#24320;&#25104;&#25152;&#26377;&#20854;&#20182; <code>FE_*</code> &#30340;&#36880;&#20301;&#25110;&#65292;&#19988;&#22987;&#32456;&#26377;&#23450;&#20041;&#65292;&#33509;&#23454;&#29616;&#19981;&#25903;&#25345;&#28014;&#28857;&#24322;&#24120;&#65292;&#21017;&#20026;&#38646;&#12290;</p>
<table class="t-dsc-begin">
<tr class="t-dsc-hitem">
<td>&#24120;&#37327;</td>
<td>&#23450;&#20041;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_DIVBYZERO</code></td>
<td>&#20986;&#29616;&#20110;&#20043;&#21069;&#28014;&#28857;&#36816;&#31639;&#30340;&#26497;&#28857;&#38169;&#35823;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_INEXACT</code></td>
<td>&#19981;&#20934;&#30830;&#32467;&#26524;&#65306;&#24517;&#39035;&#33293;&#20837;&#20197;&#23384;&#20648;&#20043;&#21069;&#28014;&#28857;&#36816;&#31639;&#30340;&#32467;&#26524;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_INVALID</code></td>
<td>&#20986;&#29616;&#20110;&#20043;&#21069;&#28014;&#28857;&#36816;&#31639;&#30340;&#23450;&#20041;&#22495;&#38169;&#35823;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_OVERFLOW</code></td>
<td>&#20043;&#21069;&#28014;&#28857;&#36816;&#31639;&#30340;&#32467;&#26524;&#36807;&#22823;&#32780;&#26080;&#27861;&#34920;&#31034;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_UNDERFLOW</code></td>
<td>&#20043;&#21069;&#28014;&#28857;&#36816;&#31639;&#30340;&#32467;&#26524;&#20026;&#26377;&#31934;&#24230;&#25439;&#22833;&#30340;&#38750;&#27491;&#35268;&#20540;</td>
</tr>
<tr class="t-dsc">
<td><code>FE_ALL_EXCEPT</code></td>
<td>&#25152;&#26377;&#21463;&#25903;&#25345;&#28014;&#28857;&#24322;&#24120;&#30340;&#36880;&#20301;&#25110;</td>
</tr>
</table>
<p>&#23454;&#29616;&#21487;&#20110; <code>&lt;cfenv&gt;</code> &#23450;&#20041;&#38468;&#21152;&#23439;&#24120;&#37327;&#20197;&#37492;&#21035;&#38468;&#21152;&#28014;&#28857;&#24322;&#24120;&#12290;&#25152;&#26377;&#36825;&#31181;&#24120;&#37327;&#37117;&#20197; <code>FE_</code> &#21518;&#38543;&#33267;&#23569;&#19968;&#20010;&#22823;&#20889;&#23383;&#27597;&#24320;&#22987;&#12290;</p>
<p>&#36827;&#19968;&#27493;&#30340;&#32454;&#33410;&#35265; <span class="t-lc"><a href="cpp-numeric-math-math_errhandling.html">math_errhandling</a></span> &#12290;</p>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">&#31034;&#20363;</span></h3>
<div class="t-template-editlink" style=""></div>
<div class="t-example">
<div class="t-example-live-link"></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;">
<div class="cpp source-cpp">
<pre class="de1"><span class="co2">#include &lt;iostream&gt;</span>
<span class="co2">#include &lt;cfenv&gt;</span>
<span class="co2">#include &lt;cmath&gt;</span>
<span class="co2">#pragma STDC FENV_ACCESS ON</span>
<span class="kw4">volatile</span> <span class="kw4">double</span> zero <span class="sy1">=</span> <span class="nu16">0.0</span><span class="sy4">;</span> <span class="co1">// &#25903;&#25345; FENV_ACCESS &#22788;&#19981;&#38656;&#35201; volatile</span>
<span class="kw4">volatile</span> <span class="kw4">double</span> one <span class="sy1">=</span> <span class="nu16">1.0</span><span class="sy4">;</span> <span class="co1">// &#25903;&#25345; FENV_ACCESS &#22788;&#19981;&#38656;&#35201; volatile</span>
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
<a href="cpp-numeric-fenv-feclearexcept.html"><span class="kw1450">std::<span class="me2">feclearexcept</span></span></a><span class="br0">(</span>FE_ALL_EXCEPT<span class="br0">)</span><span class="sy4">;</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;1.0/0.0 = &quot;</span> <span class="sy1">&lt;&lt;</span> <span class="nu16">1.0</span> <span class="sy2">/</span> zero <span class="sy1">&lt;&lt;</span> <span class="st0">&#39;<span class="es1">\n</span>&#39;</span><span class="sy4">;</span>
<span class="kw1">if</span><span class="br0">(</span><a href="cpp-numeric-fenv-fetestexcept.html"><span class="kw1451">std::<span class="me2">fetestexcept</span></span></a><span class="br0">(</span>FE_DIVBYZERO<span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;division by zero reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span> <span class="kw1">else</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;divsion by zero not reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span>
<a href="cpp-numeric-fenv-feclearexcept.html"><span class="kw1450">std::<span class="me2">feclearexcept</span></span></a><span class="br0">(</span>FE_ALL_EXCEPT<span class="br0">)</span><span class="sy4">;</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;1.0/10 = &quot;</span> <span class="sy1">&lt;&lt;</span> one<span class="sy2">/</span><span class="nu0">10</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&#39;<span class="es1">\n</span>&#39;</span><span class="sy4">;</span>
<span class="kw1">if</span><span class="br0">(</span><a href="cpp-numeric-fenv-fetestexcept.html"><span class="kw1451">std::<span class="me2">fetestexcept</span></span></a><span class="br0">(</span>FE_INEXACT<span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;inexact result reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span> <span class="kw1">else</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;inexact result not reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span>
<a href="cpp-numeric-fenv-feclearexcept.html"><span class="kw1450">std::<span class="me2">feclearexcept</span></span></a><span class="br0">(</span>FE_ALL_EXCEPT<span class="br0">)</span><span class="sy4">;</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;sqrt(-1) = &quot;</span> <span class="sy1">&lt;&lt;</span> <a href="cpp-numeric-math-sqrt.html"><span class="kw1329">std::<span class="me2">sqrt</span></span></a><span class="br0">(</span><span class="sy2">-</span><span class="nu0">1</span><span class="br0">)</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&#39;<span class="es1">\n</span>&#39;</span><span class="sy4">;</span>
<span class="kw1">if</span><span class="br0">(</span><a href="cpp-numeric-fenv-fetestexcept.html"><span class="kw1451">std::<span class="me2">fetestexcept</span></span></a><span class="br0">(</span>FE_INVALID<span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;invalid result reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span> <span class="kw1">else</span> <span class="br0">{</span>
<a href="cpp-io-cout.html"><span class="kw1752">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;invalid result not reported<span class="es1">\n</span>&quot;</span><span class="sy4">;</span>
<span class="br0">}</span>
<span class="br0">}</span></pre></div>
</div>
<p>&#36755;&#20986;&#65306;</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;">
<div class="text source-text">
<pre class="de1">1.0/0.0 = inf
division by zero reported
1.0/10 = 0.1
inexact result reported
sqrt(-1) = -nan
invalid result reported</pre></div>
</div>
</div>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">&#21442;&#38405;</span></h3>
<table class="t-dsc-begin">
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-numeric-math-math_errhandling.html"><span class="t-lines"><span>math_errhandling</span><span>MATH_ERRNO</span><span>MATH_ERREXCEPT</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div>
</td>
<td>&#23450;&#20041;&#24120;&#29992;&#25968;&#23398;&#20989;&#25968;&#25152;&#29992;&#30340;&#38169;&#35823;&#22788;&#29702;&#26426;&#21046;<br />
<span class="t-mark">(&#23439;&#24120;&#37327;)</span></td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>