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

📄 vector_support.h

📁 ecos为实时嵌入式操作系统
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef CYGONCE_LIBM_VECTOR_SUPPORT_H#define CYGONCE_LIBM_VECTOR_SUPPORT_H//========================================================================////      vector_support.h////      Support for testing of the math library using test vectors////========================================================================//####COPYRIGHTBEGIN####//// -------------------------------------------// The contents of this file are subject to the Cygnus eCos Public License// Version 1.0 (the "License"); you may not use this file except in// compliance with the License.  You may obtain a copy of the License at// http://sourceware.cygnus.com/ecos// // Software distributed under the License is distributed on an "AS IS"// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the// License for the specific language governing rights and limitations under// the License.// // The Original Code is eCos - Embedded Cygnus Operating System, released// September 30, 1998.// // The Initial Developer of the Original Code is Cygnus.  Portions created// by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions.  All Rights Reserved.// -------------------------------------------////####COPYRIGHTEND####//========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):     jlarmour// Contributors:  jlarmour// Date:          1999-01-21// Purpose:     // Description: // Usage:         #include "vectors/vector_support.h"////####DESCRIPTIONEND####////========================================================================// CONFIGURATION#include <pkgconf/libm.h>   // Configuration header// Include the Math library?#ifdef CYGPKG_LIBM     // INCLUDES#include <cyg/infra/cyg_type.h>   // Common type definitions and support#include <cyg/infra/testcase.h>   // Test infrastructure#include <math.h>                 // Header for this package#include <sys/ieeefp.h>           // Cyg_libm_ieee_double_shape_type#include <cyg/infra/diag.h>#ifndef CYGSEM_LIBM_COMPAT_IEEE_ONLY# include <errno.h>                // For Cyg_ErrNo#endif// CONSTANTS#define PROBLEM_THRESHOLD 10      // Number of test vectors allowed to fail                                  // before we give up completely// HOW TO START TESTS#ifndef CYGPKG_LIBMexternC int main( int, char ** );externC voidcyg_user_start( void ){    (void) main(0, NULL);} // cyg_user_start()# define START_TEST( test ) CYG_MACRO_START                         \                            CYG_ADDRESS _foo_ = (CYG_ADDRESS)&test; \                            CYG_UNUSED_PARAM( CYG_ADDRESS, _foo_ ); \                            CYG_MACRO_END  #elif defined(CYGPKG_LIBC)# include <sys/cstartup.h>externC voidcyg_package_start( void ){    cyg_iso_c_start();} // cyg_package_start()# define START_TEST( test ) test(0)#elif defined(CYGFUN_KERNEL_API_C)# include <cyg/kernel/kapi.h># define STACKSIZE 32768static cyg_uint8 stack[STACKSIZE];static cyg_handle_t thr_handle;static cyg_thread thr;# define START_TEST( test ) CYG_MACRO_START \    cyg_thread_create( 4, &test, (cyg_addrword_t)0, "test", \                       &stack[0],  STACKSIZE, &thr_handle, &thr ); \    cyg_thread_resume( thr_handle ); \    cyg_scheduler_start(); \    CYG_MACRO_ENDexternC int main( int, char ** );externC voidcyg_user_start( void ){    (void) main(0, NULL);} // cyg_user_start()#elseexternC int main( int, char ** );externC voidcyg_user_start( void ){    (void) main(0, NULL);} // cyg_user_start()# define START_TEST( test ) CYG_MACRO_START                         \                            CYG_ADDRESS _foo_ = (CYG_ADDRESS)&test; \                            CYG_UNUSED_PARAM( CYG_ADDRESS, _foo_ ); \                            CYG_MACRO_END  #endif// TYPE DEFINITIONStypedef enum {    CYG_LIBM_TEST_VEC_NONE,         // this indicates whether the "double"    CYG_LIBM_TEST_VEC_INT,          // is being used to store a double, an    CYG_LIBM_TEST_VEC_DOUBLE,       // int, or its not being used at all!    CYG_LIBM_TEST_VEC_INT_P,        // int pointer    CYG_LIBM_TEST_VEC_DOUBLE_P      // double pointer} Cyg_libm_test_arg_type;                              // Define a type for a test vector recordtypedef struct {    cyg_ucount32 vector_num;        // id number of this test vector record        // if any of the following arguments are ints rather than doubles, then    // use the lsw part to store it    cyg_uint32 arg1_msw;   // first argument    cyg_uint32 arg1_lsw;    cyg_uint32 arg2_msw;   // second argument    cyg_uint32 arg2_lsw;    cyg_uint32 result_msw; // expected return value    cyg_uint32 result_lsw;#ifndef CYGSEM_LIBM_COMPAT_IEEE_ONLY    Cyg_ErrNo errno_val;           // expected value of errno. 0==unchanged#else    cyg_uint32 errno_val;#endif    double tolerance;              // relative amount that it is allowed                                   // to vary. i.e. the value should be                                   // plus or minus result*tolerance    int matherr_type;              // if testing the matherr() function,                                   // what type should the exception be} Cyg_libm_test_double_vec_t;// types to cope with the different forms of function to be called by the// test vectortypedef double (*ddfn)( double, double );typedef double (*difn)( double, int );typedef double (*dfn)( double );typedef double (*ddpfn)( double, double *);typedef double (*dipfn)( double, int *);// STATIC FUNCTIONS// equivalent of abs() for doubles. We want to be independent of fabs()static doublemy_abs_d( double x ){    Cyg_libm_ieee_double_shape_type t;    t.value = x;    t.number.sign = 0;    return t.value;} // my_abs_d()static cyg_boolcheckErrorAcceptable( Cyg_libm_ieee_double_shape_type is,                      Cyg_libm_ieee_double_shape_type shouldbe,                      double tolerance) // _relative_ amount it can vary{    Cyg_libm_ieee_double_shape_type temp_doub;    // first do a short-circuit check if its identical    if ( (is.parts.lsw == shouldbe.parts.lsw) &&         (is.parts.msw == shouldbe.parts.msw) )        return false;        // now check special cases        // +0 == -0    if ( (is.parts.lsw == 0) && (shouldbe.parts.lsw == 0) &&         ((is.parts.msw & 0x7fffffff) == 0) &&         ((shouldbe.parts.msw & 0x7fffffff) == 0) )        return false;    // +-infinity == +-infinity    if ((is.parts.lsw == 0) && (shouldbe.parts.lsw == 0) &&        (is.number.fraction0 == 0) && (shouldbe.number.fraction0 == 0) &&        (is.number.exponent == 2047) && (shouldbe.number.exponent == 2047))    {        return (is.number.sign != shouldbe.number.sign);    } // if    // both NaN. Assumes isnan works, but its pretty safe    if ( isnan(is.value) && isnan(shouldbe.value) )        return false;    else if (isnan(is.value) || isnan(shouldbe.value) )        return true;    // check same sign. Even around small values close to 0 we would want    // it to be on the right _side_ of 0    if ( is.number.sign != shouldbe.number.sign )        return true;    // okay, now work out what tolerance means for us    // find out what the difference is in the first place    temp_doub.value = my_abs_d( shouldbe.value - is.value );    // Check "both ways round" to deal with both under and overflow cases    if ( ((temp_doub.value / tolerance) < my_abs_d(shouldbe.value)) ||         (temp_doub.value < (my_abs_d(shouldbe.value) * tolerance)) )        return false;    else        return true; // so its not close enough    

⌨️ 快捷键说明

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