📄 math-library-compatibility-modes.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>Math library compatibility modes</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="C and math library overview"HREF="c-and-math-library-overview.html"><LINKREL="PREVIOUS"TITLE="C and math library overview"HREF="c-and-math-library-overview.html"><LINKREL="NEXT"TITLE="Some implementation details"HREF="libc-implementation-details.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="c-and-math-library-overview.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 13. C and math library overview</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="libc-implementation-details.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="MATH-LIBRARY-COMPATIBILITY-MODES">Math library compatibility modes</H1><P>This math library is capable of being operated in severaldifferent compatibility modes. These options deal solely with howerrors are handled. </P><P>There are 4 compatibility modes: ANSI/POSIX 1003.1;IEEE-754; X/Open Portability Guide issue 3 (XPG3); andSystem V Interface Definition Edition 3. </P><P>In IEEE mode, the <TTCLASS="FUNCTION">matherr()</TT> function(see below) is never called, no warning messages are printed onthe stderr output stream, and errno is never set. </P><P>In ANSI/POSIX mode, errno is set correctly,but <TTCLASS="FUNCTION">matherr()</TT> is never called and no warning messagesare printed on the stderr output stream. </P><P>In X/Open mode, errno is set correctly,<TTCLASS="FUNCTION">matherr()</TT> is called, but no warning messages are printedon the stderr output stream. </P><P>In SVID mode, functions which overflow returna value HUGE (defined in <TTCLASS="FILENAME">math.h</TT>), which is the maximumsingle precision floating point value (as opposed toHUGE_VAL which is meant to stand for infinity). errno isset correctly and <TTCLASS="FUNCTION">matherr()</TT> is called. If<TTCLASS="FUNCTION">matherr()</TT> returns 0, warning messages are printed onthe stderr output stream for some errors. </P><P>The mode can be compiled-in as IEEE-only, or any one of theabove methods settable at run-time. </P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>This math library assumes that the hardware (or software floatingpoint emulation) supports IEEE-754 style arithmetic, 32-bit 2'scomplement integer arithmetic, doubles are in 64-bit IEEE-754 format.</P></BLOCKQUOTE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN10153">matherr()</H2><P>As mentioned above, in X/Open or SVID modes, the user can supply a function <TTCLASS="FUNCTION">matherr()</TT> of the form:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">int <TTCLASS="FUNCTION">matherr</TT>( struct exception *e )</PRE></TD></TR></TABLE><P>where struct exception is defined as:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct exception { int type; char *name; double arg1, arg2, retval;}; </PRE></TD></TR></TABLE><P>type is the exception type and is one of:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT>DOMAIN</DT><DD><P>argument domain exception</P></DD><DT>SING</DT><DD><P>argument singularity</P></DD><DT>OVERFLOW</DT><DD><P>overflow range exception</P></DD><DT>UNDERFLOW</DT><DD><P>underflow range exception</P></DD><DT>TLOSS</DT><DD><P>total loss of significance</P></DD><DT>PLOSS</DT><DD><P>partial loss of significance</P></DD></DL></DIV><P><TTCLASS="PARAMETER"><I>name</I></TT> is a string containing the name of thefunction</P><P><TTCLASS="PARAMETER"><I>arg1</I></TT> and <TTCLASS="PARAMETER"><I>arg2</I></TT> are thearguments passed to the function</P><P><TTCLASS="PARAMETER"><I>retval</I></TT> is the default value that will be returnedby the function, and can be changed by <TTCLASS="FUNCTION">matherr()</TT></P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>matherr must have “C” linkage, not “C++” linkage.</P></BLOCKQUOTE></DIV><P>If matherr returns zero, or the user doesn't supplytheir own matherr, then the following <SPANCLASS="emphasis"><ICLASS="EMPHASIS">usually</I></SPAN> happensin SVID mode:</P><DIVCLASS="TABLE"><ANAME="AEN10199"><P><B>Table 13-1. Behavior of math exception handling</B></P><TABLEBORDER="1"CLASS="CALSTABLE"><THEAD><TR><THALIGN="LEFT"VALIGN="TOP">Type</TH><THALIGN="LEFT"VALIGN="TOP">Behavior</TH></TR></THEAD><TBODY><TR><TDALIGN="LEFT"VALIGN="TOP">DOMAIN</TD><TDALIGN="LEFT"VALIGN="TOP">0.0 returned,errno=EDOM, and a message printed on stderr</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">SING</TD><TDALIGN="LEFT"VALIGN="TOP">HUGE of appropriatesign is returned, errno=EDOM, and a message is printedon stderr</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">OVERFLOW</TD><TDALIGN="LEFT"VALIGN="TOP">HUGE ofappropriate sign is returned, and errno=ERANGE</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">UNDERFLOW</TD><TDALIGN="LEFT"VALIGN="TOP">0.0 isreturned and errno=ERANGE</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">TLOSS</TD><TDALIGN="LEFT"VALIGN="TOP">0.0 is returned,errno=ERANGE, and a message is printed on stderr</TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP">PLOSS</TD><TDALIGN="LEFT"VALIGN="TOP">The currentimplementation doesn't return this type</TD></TR></TBODY></TABLE></DIV><P>X/Open mode is similar except that the message isnot printed on stderr and HUGE_VAL is used in place ofHUGE</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN10226">Thread-safety and re-entrancy</H2><P>With the appropriate configuration options set below, themath library is fully thread-safe if:</P><P></P><UL><LI><P>Depending on the compatibility mode, the setting of the errno variable from the C library is thread-safe</P></LI><LI><P>Depending on the compatibility mode, sending error messagesto the stderr output stream using the C library <TTCLASS="FUNCTION">fputs()</TT> function is thread-safe </P></LI><LI><P>Depending on the compatibility mode, the user-supplied <TTCLASS="FUNCTION">matherr()</TT> function and anything it depends on are thread-safe </P></LI></UL><P>In addition, with the exception of the <TTCLASS="FUNCTION">gamma*()</TT> and <TTCLASS="FUNCTION">lgamma*()</TT> functions,the math library is reentrant (and thus safe to use from interrupt handlers)if the Math library is always in IEEE mode.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="c-and-math-library-overview.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="libc-implementation-details.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">C and math library overview</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="c-and-math-library-overview.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Some implementation details</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -