fp-test.c revision 169690
12089Ssos/* fp-test.c - Check that all floating-point operations are available. 216565Ssos Copyright (C) 1995, 2000, 2003 Free Software Foundation, Inc. 32089Ssos Contributed by Ronald F. Guilmette <rfg@monkeys.com>. 42089Ssos 52089Ssos This file is part of GCC. 62089Ssos 72089Ssos GCC is free software; you can redistribute it and/or modify it 82089Ssos under the terms of the GNU General Public License as published by 95994Ssos the Free Software Foundation; either version 2, or (at your option) 105994Ssos any later version. 112089Ssos 122089Ssos GCC is distributed in the hope that it will be useful, but WITHOUT 132089Ssos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 142089Ssos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 152089Ssos License for more details. 162089Ssos 172089Ssos You should have received a copy of the GNU General Public License 182089Ssos along with GCC; see the file COPYING. If not, write to the Free 192089Ssos Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 202089Ssos 02110-1301, USA. */ 212089Ssos 222089Ssos/* This is a trivial test program which may be useful to people who are 232089Ssos porting the GCC or G++ compilers to a new system. The intent here is 242089Ssos merely to check that all floating-point operations have been provided 252089Ssos by the port. (Note that I say ``provided'' rather than ``implemented''.) 262089Ssos 272089Ssos To use this file, simply compile it (with GCC or G++) and then try to 282089Ssos link it in the normal way (also using GCC or G++ respectively). If 2930764Scharnier all of the floating -point operations (including conversions) have 3030764Scharnier been provided, then this file will link without incident. If however 3139287Ssos one or more of the primitive floating-point operations have not been 3230764Scharnier properly provided, you will get link-time errors indicating which 3330764Scharnier floating-point operations are unavailable. 342089Ssos 3530764Scharnier This file will typically be used when porting the GNU compilers to 362089Ssos some system which lacks floating-point hardware, and for which 3723457Sbrian software emulation routines (for FP ops) are needed in order to 3830764Scharnier complete the port. */ 3923702Speter 402089Ssos#if 0 412089Ssos#include <math.h> 422089Ssos#endif 4323457Sbrian 442089Ssosextern double acos (double); 452089Ssosextern double asin (double); 462089Ssosextern double atan (double); 472089Ssosextern double atan2 (double, double); 482089Ssosextern double cos (double); 492089Ssosextern double sin (double); 506628Ssosextern double tan (double); 512089Ssosextern double cosh (double); 526047Ssosextern double sinh (double); 532089Ssosextern double tanh (double); 542089Ssosextern double exp (double); 552089Ssosextern double frexp (double, int *); 562089Ssosextern double ldexp (double, int); 5730764Scharnierextern double log (double); 586628Ssosextern double log10 (double); 596628Ssosextern double modf (double, double *); 6030764Scharnierextern double pow (double, double); 6130764Scharnierextern double sqrt (double); 6230764Scharnierextern double ceil (double); 6330764Scharnierextern double fabs (double); 6430764Scharnierextern double floor (double); 656628Ssosextern double fmod (double, double); 666628Ssos 672089Ssosint i1, i2 = 2; 682089Ssos 692089Ssosvolatile signed char sc; 702089Ssosvolatile unsigned char uc; 712089Ssos 7230764Scharniervolatile signed short ss; 732089Ssosvolatile unsigned short us; 742089Ssos 752089Ssosvolatile signed int si; 762089Ssosvolatile unsigned int ui; 772089Ssos 782089Ssosvolatile signed long sl; 796628Ssosvolatile unsigned long ul; 806628Ssos 816628Ssosvolatile float f1 = 1.0, f2 = 1.0, f3 = 1.0; 822089Ssosvolatile double d1 = 1.0, d2 = 1.0, d3 = 1.0; 832089Ssosvolatile long double D1 = 1.0, D2 = 1.0, D3 = 1.0; 842089Ssos 852089Ssosint 862089Ssosmain (void) 872089Ssos{ 882089Ssos /* TYPE: float */ 892089Ssos 902089Ssos f1 = -f2; 912089Ssos f1 = f2 + f3; 922089Ssos f1 = f2 - f3; 932089Ssos f1 = f2 * f3; 942089Ssos f1 = f2 / f3; 952089Ssos f1 += f2; 962089Ssos f1 -= f2; 972089Ssos f1 *= f2; 982089Ssos f1 /= f2; 992089Ssos 1002089Ssos si = f1 == f2; 1012089Ssos si = f1 != f2; 1022089Ssos si = f1 > f2; 1032089Ssos si = f1 < f2; 10423457Sbrian si = f1 >= f2; 1052089Ssos si = f1 <= f2; 1062089Ssos 1072089Ssos si = __builtin_isgreater (f1, f2); 1082089Ssos si = __builtin_isgreaterequal (f1, f2); 1092089Ssos si = __builtin_isless (f1, f2); 1102089Ssos si = __builtin_islessequal (f1, f2); 1112089Ssos si = __builtin_islessgreater (f1, f2); 1122089Ssos si = __builtin_isunordered (f1, f2); 11323457Sbrian 11423457Sbrian sc = f1; 1152089Ssos uc = f1; 1162089Ssos ss = f1; 1172089Ssos us = f1; 11830764Scharnier si = f1; 1192089Ssos ui = f1; 1202089Ssos sl = f1; 1212089Ssos ul = f1; 12223457Sbrian d1 = f1; 1232089Ssos D1 = f1; 1242089Ssos 12530764Scharnier f1 = sc; 12623457Sbrian f1 = uc; 1272089Ssos f1 = ss; 1282089Ssos f1 = us; 1292089Ssos f1 = si; 1302089Ssos f1 = ui; 13130764Scharnier f1 = sl; 13223457Sbrian f1 = ul; 1332089Ssos f1 = d1; 1342089Ssos f1 = D1; 1352089Ssos 1362089Ssos d1 = -d2; 1372089Ssos d1 = d2 + d3; 1386628Ssos d1 = d2 - d3; 1392089Ssos d1 = d2 * d3; 1402089Ssos d1 = d2 / d3; 1412089Ssos d1 += d2; 1422089Ssos d1 -= d2; 1432089Ssos d1 *= d2; 14430764Scharnier d1 /= d2; 1452089Ssos 1462089Ssos si = d1 == d2; 1472089Ssos si = d1 != d2; 1482089Ssos si = d1 > d2; 1492089Ssos si = d1 < d2; 1502089Ssos si = d1 >= d2; 1512089Ssos si = d1 <= d2; 1522089Ssos 1532089Ssos si = __builtin_isgreater (d1, d2); 15430764Scharnier si = __builtin_isgreaterequal (d1, d2); 1552089Ssos si = __builtin_isless (d1, d2); 1562089Ssos si = __builtin_islessequal (d1, d2); 1572089Ssos si = __builtin_islessgreater (d1, d2); 1582089Ssos si = __builtin_isunordered (d1, d2); 1592089Ssos 1602089Ssos sc = d1; 1618857Srgrimes uc = d1; 1622089Ssos ss = d1; 1632089Ssos us = d1; 1642089Ssos si = d1; 1652089Ssos ui = d1; 1662089Ssos sl = d1; 1672089Ssos ul = d1; 1682089Ssos f1 = d1; 1698857Srgrimes D1 = d1; 1702089Ssos 1712089Ssos d1 = sc; 17223457Sbrian d1 = uc; 17337636Sbde d1 = ss; 17437636Sbde d1 = us; 1752089Ssos d1 = si; 1762089Ssos d1 = ui; 1772089Ssos d1 = sl; 1782089Ssos d1 = ul; 1792089Ssos d1 = f1; 1802089Ssos d1 = D1; 18123457Sbrian 18223457Sbrian D1 = -D2; 1832089Ssos D1 = D2 + D3; 1842089Ssos D1 = D2 - D3; 1852089Ssos D1 = D2 * D3; 18630764Scharnier D1 = D2 / D3; 1872089Ssos D1 += D2; 1882089Ssos D1 -= D2; 1892089Ssos D1 *= D2; 1902089Ssos D1 /= D2; 1912089Ssos 1922089Ssos si = D1 == D2; 1932089Ssos si = D1 != D2; 1942089Ssos si = D1 > D2; 1952089Ssos si = D1 < D2; 1962089Ssos si = D1 >= D2; 1972089Ssos si = D1 <= D2; 1982089Ssos 1992089Ssos si = __builtin_isgreater (D1, D2); 2002089Ssos si = __builtin_isgreaterequal (D1, D2); 2012089Ssos si = __builtin_isless (D1, D2); 20230764Scharnier si = __builtin_islessequal (D1, D2); 20323457Sbrian si = __builtin_islessgreater (D1, D2); 2042089Ssos si = __builtin_isunordered (D1, D2); 2052089Ssos 2062089Ssos sc = D1; 2072089Ssos uc = D1; 2082089Ssos ss = D1; 2092089Ssos us = D1; 21030764Scharnier si = D1; 21123457Sbrian ui = D1; 2122089Ssos sl = D1; 2132089Ssos ul = D1; 2142089Ssos f1 = D1; 2152089Ssos d1 = D1; 2162089Ssos 21730764Scharnier D1 = sc; 21823457Sbrian D1 = uc; 2192089Ssos D1 = ss; 2202089Ssos D1 = us; 2212089Ssos D1 = si; 2222089Ssos D1 = ui; 2232089Ssos D1 = sl; 2242089Ssos D1 = ul; 2252089Ssos D1 = f1; 2262089Ssos D1 = d1; 2272089Ssos 2282089Ssos d1 = acos (d2); 2292089Ssos d1 = asin (d2); 2302089Ssos d1 = atan (d2); 2312089Ssos d1 = atan2 (d2, d3); 23230764Scharnier d1 = cos (d2); 2332089Ssos d1 = sin (d2); 2342089Ssos d1 = tan (d2); 2352089Ssos d1 = cosh (d2); 2362089Ssos d1 = sinh (d2); 23730764Scharnier d1 = tanh (d2); 2382089Ssos d1 = exp (d2); 2392089Ssos d1 = frexp (d2, &i1); 2402089Ssos d1 = ldexp (d2, i2); 2415536Ssos d1 = log (d2); 2422089Ssos d1 = log10 (d2); 2435536Ssos d1 = modf (d2, &d3); 2442089Ssos d1 = pow (d2, d3); 2456230Ssos d1 = sqrt (d2); 2466230Ssos d1 = ceil (d2); 2476230Ssos d1 = fabs (d2); 2485536Ssos d1 = floor (d2); 2496230Ssos d1 = fmod (d2, d3); 2506230Ssos 2515536Ssos return 0; 25230764Scharnier} 2532089Ssos