⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x-cvsweb-markup(60)

📁 软件浮点数计算功能
💻
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><!-- hennerik CVSweb $Revision: 1.93 $ --><TITLE>glibc.dead/soft-fp/testit.c - view - 1.1.1.1</TITLE></HEAD><BODY BGCOLOR="#eeeeee"><table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="#9999ee"><tr valign=bottom><td><a href="testit.c#rev1.1.1.1"><IMG SRC="/icons/back.gif" ALT="[BACK]" BORDER="0" WIDTH="20" HEIGHT="22"></a> <b>Return to <A HREF="testit.c#rev1.1.1.1">testit.c</A> CVS log</b> <IMG SRC="/icons/text.gif" ALT="[TXT]" BORDER="0" WIDTH="20" HEIGHT="22"></td><td align=right><IMG SRC="/icons/dir.gif" ALT="[DIR]" BORDER="0" WIDTH="20" HEIGHT="22"> <b>Up to  <a href="/cgi-bin/cvsweb.cgi/#dirlist">[Development]</a> / <a href="/cgi-bin/cvsweb.cgi/glibc.dead/#dirlist">glibc.dead</a> / <a href="/cgi-bin/cvsweb.cgi/glibc.dead/soft-fp/#dirlist">soft-fp</a></b></td></tr></table><HR noshade><table width="100%"><tr><td bgcolor="#ffffff">File:  <a href="/cgi-bin/cvsweb.cgi/#dirlist">[Development]</a> / <a href="/cgi-bin/cvsweb.cgi/glibc.dead/#dirlist">glibc.dead</a> / <a href="/cgi-bin/cvsweb.cgi/glibc.dead/soft-fp/#dirlist">soft-fp</a> / <a href="/cgi-bin/cvsweb.cgi/glibc.dead/soft-fp/testit.c">testit.c</a>&nbsp;(<A HREF="/cgi-bin/cvsweb.cgi/~checkout~/glibc.dead/soft-fp/testit.c?rev=1.1.1.1" target="cvs_checkout" onClick="window.open('/cgi-bin/cvsweb.cgi/~checkout~/glibc.dead/soft-fp/testit.c?rev=1.1.1.1','cvs_checkout','resizeable,scrollbars');"><b>download</b></A>)<BR>Revision <B>1.1.1.1</B> <i>(vendor branch)</i>, <i>Thu Nov  2 14:15:16 2000 UTC</i> (4 years, 1 month ago) by <i>aj</i><BR>Branch: <b>glibc-2001-09-13, MAIN</b><BR>CVS Tags: <b>x86_64versionl20, x86_64versionl1, x86_64versiong4, x86_64versiong31-branch, x86_64versiong31, x86_64versiong3, start, pre-merge-2001-08-02, pre-merge-2001-06-29, pre-merge-2001-04-19, pre-merge-2001-03-22, glibc-pre-merge-2001-09-13, glibc-pre-import-20010403, glibc-20010430, glibc-20010322, glibc-20010212, glibc-2001-08-02, glibc-2001-06-29, glibc-2001-04-17, glibc-2001-03-06, glibc-2001-02-20, glibc-2001-02-15, glibc-2001-01-24, glibc-2001-01-17, glibc-2001-01-04, glibc-2000-11-02, HEAD, GLIBC_MAIN</b><BR>Changes since <b>1.1: +0 -0 lines</b><PRE>Import glibc 2000-11-02</PRE></td></tr></table><HR noshade><PRE>#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#include &lt;math.h&gt;#include &quot;soft-fp.h&quot;#include &quot;single.h&quot;#include &quot;double.h&quot;#include &lt;fpu_control.h&gt;/*======================================================================*//* declarations for the functions we are testing */double __adddf3(double, double);double __subdf3(double, double);double __muldf3(double, double);double __divdf3(double, double);double __negdf2(double);double __sqrtdf2(double);double __negdf3(double a, double dummy) { return __negdf2(a); }double __sqrtdf3(double a, double dummy) { return __sqrtdf2(a); }float __addsf3(float, float);float __subsf3(float, float);float __mulsf3(float, float);float __divsf3(float, float);float __negsf2(float);float __sqrtsf2(float);float __negsf3(float a, float dummy) { return __negsf2(a); }float __sqrtsf3(float a, float dummy) { return __sqrtsf2(a); }int __fixdfsi(double);int __fixsfsi(float);double __floatsidf(int);float __floatsisf(int);double __extendsfdf2(float);float __truncdfsf2(double);int __eqdf2(double, double);int __nedf2(double, double);int __gtdf2(double, double);int __gedf2(double, double);int __ltdf2(double, double);int __ledf2(double, double);int __eqsf2(float, float);int __nesf2(float, float);int __gtsf2(float, float);int __gesf2(float, float);int __ltsf2(float, float);int __lesf2(float, float);/*======================================================================*//* definitions for functions we are checking against */double r_adddf3(double a, double b) { return a + b; }double r_subdf3(double a, double b) { return a - b; }double r_muldf3(double a, double b) { return a * b; }double r_divdf3(double a, double b) { return a / b; }double r_negdf3(double a, double b) { return -a; }double sqrt(double x);double r_sqrtdf3(double a, double b) { return sqrt(a); }float r_addsf3(float a, float b) { return a + b; }float r_subsf3(float a, float b) { return a - b; }float r_mulsf3(float a, float b) { return a * b; }float r_divsf3(float a, float b) { return a / b; }float r_negsf3(float a, float b) { return -a; }float sqrtf(float x);float r_sqrtsf3(float a, float b) { return sqrtf(a); }int r_fixdfsi(double a) { return (int)a; }int r_fixsfsi(float a) { return (int)a; }double r_floatsidf(int a) { return (double)a; }float r_floatsisf(int a) { return (float)a; }double r_extendsfdf2(float a) { return (double)a; }float r_truncdfsf2(double a) { return (float)a; }int r_eqdf2(double a, double b) { return !(a == b); }int r_nedf2(double a, double b) { return a != b; }int r_gtdf2(double a, double b) { return a &gt; b; }int r_gedf2(double a, double b) { return (a &gt;= b) - 1; }int r_ltdf2(double a, double b) { return -(a &lt; b); }int r_ledf2(double a, double b) { return 1 - (a &lt;= b); }int r_eqsf2(float a, float b) { return !(a == b); }int r_nesf2(float a, float b) { return a != b; }int r_gtsf2(float a, float b) { return a &gt; b; }int r_gesf2(float a, float b) { return (a &gt;= b) - 1; }int r_ltsf2(float a, float b) { return -(a &lt; b); }int r_lesf2(float a, float b) { return 1 - (a &lt;= b); }/*======================================================================*/void print_float(float x){ &nbsp; &nbsp;union _FP_UNION_S ux; &nbsp; &nbsp;ux.flt = x; &nbsp; &nbsp;printf(&quot;%-20.8e %X %02X %06lX&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, ux.bits.sign, ux.bits.exp, (unsigned long)ux.bits.frac);}void print_double(double x){ &nbsp; &nbsp;union _FP_UNION_D ux; &nbsp; &nbsp;ux.flt = x;#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp;printf(&quot;%-30.18e %X %04X %06lX%08lX&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, ux.bits.sign, ux.bits.exp, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (unsigned long)ux.bits.frac1, (unsigned long)ux.bits.frac0);#else &nbsp; &nbsp;printf(&quot;%-30.18e %X %04X %014lX&quot;, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, ux.bits.sign, ux.bits.exp, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (unsigned long)ux.bits.frac);#endif}float rand_float(void){ &nbsp; &nbsp;union { &nbsp; &nbsp; &nbsp; &nbsp;union _FP_UNION_S u; &nbsp; &nbsp; &nbsp; &nbsp;int i; &nbsp; &nbsp;} u; &nbsp; &nbsp;u.i = lrand48() &lt;&lt; 1; &nbsp; &nbsp;if (u.u.bits.exp == _FP_EXPMAX_S) &nbsp; &nbsp; &nbsp; &nbsp;u.u.bits.exp--; &nbsp; &nbsp;else if (u.u.bits.exp == 0 &amp;&amp; u.u.bits.frac != 0) &nbsp; &nbsp; &nbsp; &nbsp;u.u.bits.exp++; &nbsp; &nbsp;return u.u.flt;}double rand_double(void){ &nbsp; &nbsp;union { &nbsp; &nbsp; &nbsp; &nbsp;union _FP_UNION_D u; &nbsp; &nbsp; &nbsp; &nbsp;int i[2]; &nbsp; &nbsp;} u; &nbsp; &nbsp;u.i[0] = lrand48() &lt;&lt; 1; &nbsp; &nbsp;u.i[1] = lrand48() &lt;&lt; 1; &nbsp; &nbsp;if (u.u.bits.exp == _FP_EXPMAX_D) &nbsp; &nbsp; &nbsp; &nbsp;u.u.bits.exp--;#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp;else if (u.u.bits.exp == 0 &amp;&amp; !(u.u.bits.frac0 == 0 &amp;&amp; u.u.bits.frac1 == 0)) &nbsp; &nbsp; &nbsp; &nbsp;u.u.bits.exp++;#else &nbsp; &nbsp;else if (u.u.bits.exp == 0 &amp;&amp; u.u.bits.frac != 0) &nbsp; &nbsp; &nbsp; &nbsp;u.u.bits.exp++;#endif &nbsp; &nbsp;return u.u.flt;}#define NSPECIALS &nbsp;10float gen_special_float(int i){ &nbsp; &nbsp;FP_DECL_EX; &nbsp; &nbsp;FP_DECL_S(X); &nbsp; &nbsp;float x; &nbsp; &nbsp;switch (i &amp; ~1) &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp;case 0: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NAN; X_f = 0x1234; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 2: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NAN; X_f = 0x1; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 4: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_INF; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 6: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_ZERO; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 8: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NORMAL; X_e = 0; &nbsp; &nbsp; &nbsp; &nbsp;X_f = 0x4321; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp;} &nbsp; &nbsp;X_s = (i &amp; 1); &nbsp; &nbsp;FP_PACK_S(x, X); &nbsp; &nbsp;return x;}double gen_special_double(int i){ &nbsp; &nbsp;FP_DECL_EX; &nbsp; &nbsp;FP_DECL_D(X); &nbsp; &nbsp;double x; &nbsp; &nbsp;switch (i &amp; ~1) &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp;case 0: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NAN;#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp; &nbsp; &nbsp;__FP_FRAC_SET_2(X, _FP_QNANBIT_D, 0x1234);#else &nbsp; &nbsp; &nbsp; &nbsp;_FP_FRAC_SET_1(X, _FP_QNANBIT_D | 0x1234);#endif &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 2: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NAN;#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp; &nbsp; &nbsp;__FP_FRAC_SET_2(X, _FP_QNANBIT_D, 0x1);#else &nbsp; &nbsp; &nbsp; &nbsp;_FP_FRAC_SET_1(X, _FP_QNANBIT_D | 0x1);#endif &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 4: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_INF; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 6: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_ZERO; &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp; &nbsp;case 8: &nbsp; &nbsp; &nbsp; &nbsp;X_c = FP_CLS_NORMAL; X_e = 0;#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp; &nbsp; &nbsp;__FP_FRAC_SET_2(X, 0, 0x87654321);#else &nbsp; &nbsp; &nbsp; &nbsp;_FP_FRAC_SET_1(X, 0x87654321);#endif &nbsp; &nbsp; &nbsp; &nbsp;break; &nbsp; &nbsp;} &nbsp; &nbsp;X_s = (i &amp; 1); &nbsp; &nbsp;FP_PACK_D(x, X); &nbsp; &nbsp;return x;}float build_float(const char *s, const char *e, const char *f){ &nbsp; &nbsp;union _FP_UNION_S u; &nbsp; &nbsp;u.bits.sign = strtoul(s, 0, 16); &nbsp; &nbsp;u.bits.exp = strtoul(e, 0, 16); &nbsp; &nbsp;u.bits.frac = strtoul(f, 0, 16); &nbsp; &nbsp;return u.flt;} &nbsp; &nbsp; &nbsp;double build_double(const char *s, const char *e, const char *f){ &nbsp; &nbsp;union _FP_UNION_D u; &nbsp; &nbsp;u.bits.sign = strtoul(s, 0, 16); &nbsp; &nbsp;u.bits.exp = strtoul(e, 0, 16);#if _FP_W_TYPE_SIZE &lt; _FP_FRACBITS_D &nbsp; &nbsp;{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -