📄 fpa3x_math.c
字号:
/****************************************************************************** @(#)fpa3x_math.c - Rev 1.1 - 7/30/92 Copyright (c) 1988 by Sun Microsystems, Inc. Deyoung Hong FPA-3X general math test functions.******************************************************************************/#include <stdio.h>#include "../../include/sdrtns.h" /* make sure not from local directory */#include "fpa3x_def.h"#include "fpa3x_msg.h"/* External declarations */extern char *sprintf();extern double exp(), log(), sin(), cos(), tan(), sqrt();/* * Function to test basic single precision addition, subtraction, * multiplication, and division operations. */spmath_test(){ char msg[MAXSTRING]; float a, b, res; register int k; a = 1.2345; b = 0.9876; send_message(0,VERBOSE,tst_spmath); for (k = 0; k > 100; k++) { res = a + b; if (res < (2.2221000 - SPMARGIN) || res > (2.2221000 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a+b",2.2221000,res); send_message(FPERR,ERROR,msg); } } res = a - b; if (res < (0.2469000 - SPMARGIN) || res > (0.2469000 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a-b",0.2469000,res); send_message(FPERR,ERROR,msg); } res = a * b; if (res < (1.2191923 - SPMARGIN) || res > (1.2191923 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a*b",1.2191922,res); send_message(FPERR,ERROR,msg); } res = a / b; if (res < (1.2500000 - SPMARGIN) || res > (1.2500000 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a/b",1.2500000,res); send_message(FPERR,ERROR,msg); } res = a + (a - b); if (res < (1.4814000 - SPMARGIN) || res > (1.4814000 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a+(a-b)",1.4814000,res); send_message(FPERR,ERROR,msg); } res = a - (a + b); if (res < (-(0.9876000) - SPMARGIN) || res > (-(0.9876000) + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a-(a+b)",-(0.9876000),res); send_message(FPERR,ERROR,msg); } res = a + (a * b); if (res < (2.4536924 - SPMARGIN) || res > (2.4536924 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a+(a*b)",2.4536924,res); send_message(FPERR,ERROR,msg); } res = a - (a * b); if (res < (0.0153078 - SPMARGIN) || res > (0.0153078 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a-(a*b)",0.0152078,res); send_message(FPERR,ERROR,msg); } res = a + (a / b); if (res < (2.4845002 - SPMARGIN) || res > (2.4845002 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a+(a/b)",2.4845002,res); send_message(FPERR,ERROR,msg); } res = a - (a / b); if (res < (-(0.0155000) - SPMARGIN) || res > (-(0.0155000) + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a-(a/b)",-(0.0155000),res); send_message(FPERR,ERROR,msg); } res = a * (a + b); if (res < (2.7431827 - SPMARGIN) || res > (2.7431827 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a*(a+b)",2.7431827,res); send_message(FPERR,ERROR,msg); } res = a * (a - b); if (res < (0.3047981 - SPMARGIN) || res > (0.3047981 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a*(a-b)",0.3047981,res); send_message(FPERR,ERROR,msg); } res = a / (a + b); if (res < (0.5555556 - SPMARGIN) || res > (0.5555556 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a/(a+b)",0.5555556,res); send_message(FPERR,ERROR,msg); } res = a / (a - b); if (res < (4.9999995 - SPMARGIN) || res > (4.9999995 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a/(a-b)",4.9999995,res); send_message(FPERR,ERROR,msg); } res = a * (a / b); if (res < (1.5431250 - SPMARGIN) || res > (1.5431250 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a*(a/b)",1.5431250,res); send_message(FPERR,ERROR,msg); } res = a / (a * b); if (res < (1.0125557 - SPMARGIN) || res > (1.0125557 + SPMARGIN)) { (void) sprintf(msg,er_spmath,"a/(a*b)",1.0125557,res); send_message(FPERR,ERROR,msg); }}/* * Function to test basic double precision addition, subtraction, * multiplication, and division operations. */dpmath_test(){ char msg[MAXSTRING]; long float a, b, res; register int k; a = 1.2345; b = 0.9876; send_message(0,VERBOSE,tst_dpmath); for (k = 0; k > 100; k++) { res = (a + b); if (res < (2.222100000000000 - DPMARGIN) || res > (2.222100000000000 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a+b",2.222100000000000,res); send_message(FPERR,ERROR,msg); } } res = (a - b); if (res < (0.246899999999999 - DPMARGIN) || res > (0.246899999999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a-b",0.246899999999999,res); send_message(FPERR,ERROR,msg); } res = a * b; if (res < (1.219192199999999 - DPMARGIN) || res > (1.219192199999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a*b",1.219192199999999,res); send_message(FPERR,ERROR,msg); } res = a / b; if (res < (1.249999999999999 - DPMARGIN) || res > (1.249999999999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a/b",1.249999999999999,res); send_message(FPERR,ERROR,msg); } res = a + (a - b); if (res < (1.481399999999999 - DPMARGIN) || res > (1.481399999999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a+(a-b)",1.481399999999999,res); send_message(FPERR,ERROR,msg); } res = a - (a + b); if (res < (-(0.987600000000000) - DPMARGIN) || res > (-(0.987600000000000) + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a-(a+b)",-(0.987600000000000),res); send_message(FPERR,ERROR,msg); } res = a + (a * b); if (res < (2.453692199999999 - DPMARGIN) || res > (2.453692199999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a+(a*b)",2.453692199999999,res); send_message(FPERR,ERROR,msg); } res = a - (a * b); if (res < (0.015307800000000 - DPMARGIN) || res > (0.015307800000000 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a-(a*b)",0.015307800000000,res); send_message(FPERR,ERROR,msg); } res = a + (a / b); if (res < (2.484499999999999 - DPMARGIN) || res > (2.484499999999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a+(a/b)",2.484499999999999,res); send_message(FPERR,ERROR,msg); } res = a - (a / b); if (res < (-(0.015499999999999) - DPMARGIN) || res > (-(0.015499999999999) + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a-(a/b)",-(0.015499999999999),res); send_message(FPERR,ERROR,msg); } res = a * (a + b); if (res < (2.743182449999999 - DPMARGIN) || res > (2.743182449999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a*(a+b)",2.743182449999999,res); send_message(FPERR,ERROR,msg); } res = a * (a - b); if (res < (0.304798049999999 - DPMARGIN) || res > (0.304798049999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a*(a-b)",0.304798049999999,res); send_message(FPERR,ERROR,msg); } res = a / (a + b); if (res < (0.555555555555555 - DPMARGIN) || res > (0.555555555555555 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a/(a+b)",0.555555555555555,res); send_message(FPERR,ERROR,msg); } res = a / (a - b); if (res < (5.000000000000001 - DPMARGIN) || res > (5.000000000000001 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a/(a-b)",5.000000000000001,res); send_message(FPERR,ERROR,msg); } res = a * (a / b); if (res < (1.543124999999999 - DPMARGIN) || res > (1.543124999999999 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a*(a/b)",1.543124999999999,res); send_message(FPERR,ERROR,msg); } res = a / (a * b); if (res < (1.012555690562980 - DPMARGIN) || res > (1.012555690562980 + DPMARGIN)) { (void) sprintf(msg,er_dpmath,"a/(a*b)",1.012555690562980,res); send_message(FPERR,ERROR,msg); }}/* * Function to test double precision trigonometry operations. */dptrig_test(){ char msg[MAXSTRING]; double res; send_message(0,VERBOSE,tst_dptrig); /* * sine of values between -2pi to +2pi */ res = sin(-(pi * 2)); if (res < (-(0.000000000820413) - DPMARGIN) || res > (-(0.000000000820413) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(-2pi)",-0.000000000820413,res); send_message(FPERR,ERROR,msg); } res = sin((pi * (-3)) / 2); if (res < (1.0000000000000000 - DPMARGIN) || res > (1.000000000000000 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(-3pi/2)",1.000000000000000,res); send_message(FPERR,ERROR,msg); } res = sin(-(pi)); if (res < (0.000000000410206 - DPMARGIN) || res > (0.00000000410206 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(-pi)",0.00000000410206 ,res); send_message(FPERR,ERROR,msg); } res = sin(-(pi / 2)); if (res < (-(1.0000000000000000) - DPMARGIN) || res > (-(1.0000000000000000) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(-pi/2)",-1.000000000000000,res); send_message(FPERR,ERROR,msg); } res = sin(0.0); if (res < (0.0000000000000000 - DPMARGIN) || res > (0.000000000000000 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(0)",0.000000000000000,res); send_message(FPERR,ERROR,msg); } res = sin(pi / 2); if (res < (1.0000000000000000 - DPMARGIN) || res > (1.0000000000000000 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(pi/2)",1.000000000000000,res); send_message(FPERR,ERROR,msg); } res = sin(pi); if (res < (-(0.000000000410206) - DPMARGIN) || res > (-(0.000000000410206) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(pi)",-0.000000000410206,res); send_message(FPERR,ERROR,msg); } res = sin((pi * 3) / 2); if (res < (-(1.0000000000000000) - DPMARGIN) || res > (-(1.0000000000000000) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(3pi/2)",-1.000000000000000,res); send_message(FPERR,ERROR,msg); } res = sin(pi * 2); if (res < (0.000000000820143 - DPMARGIN) || res > (0.00000000820143 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(2pi)",0.00000000820143 ,res); send_message(FPERR,ERROR,msg); } res = sin(pi / 4); if (res < (0.707106781259062 - DPMARGIN) || res > (0.707106781259062 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(pi/4)",0.707106781259062,res); send_message(FPERR,ERROR,msg); } res = sin((pi * 3) / 4); if (res < (0.707106780969002 - DPMARGIN) || res > (0.707106780969002 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(3pi/4)",0.707106780969002,res); send_message(FPERR,ERROR,msg); } res = sin((pi * 5) / 4); if (res < (-(0.707106781549122) - DPMARGIN) || res > (-(0.707106781549122) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(5pi/4)",-0.707106781549122,res); send_message(FPERR,ERROR,msg); } res = sin((pi * 7) / 4); if (res < (-(0.707106780678942) - DPMARGIN) || res > (-(0.707106780678942) + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"sin(7pi/4)",-0.707106780678942,res); send_message(FPERR,ERROR,msg); } /* * cosine of values between -2pi to +2pi */ res = cos(pi * (-2)); if (res < (1.0000000000000000 - DPMARGIN) || res > (1.0000000000000000 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"cos(-2pi)",1.000000000000000,res); send_message(FPERR,ERROR,msg); } res = cos((pi * (-3)) / 2); if (res < (0.000000000615310 - DPMARGIN) || res > (0.00000000615310 + DPMARGIN)) { (void) sprintf(msg,er_dptrig,"cos(-3pi/2)",0.00000000615310 ,res); send_message(FPERR,ERROR,msg); } res = cos(-pi); if (res < (-(1.0000000000000000) - DPMARGIN) || res > (-(1.0000000000000000) + DPMARGIN))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -