📄 exp.cpp
字号:
/* --------------------------------------------------------------
Test for exponent functions.
Home page: www.imach.uran.ru/exp
Copyright 2001-2002 by Dr. Raul N.Shakirov, IMach of RAS(UB).
All Rights Reserved.
Permission has been granted to copy, distribute and modify
software in any context without fee, including a commercial
application, provided that the aforesaid copyright statement
is present here as well as exhaustive description of changes.
THE SOFTWARE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND
IS EXPRESSED OR IMPLIED. YOU USE AT YOUR OWN RISK. THE AUTHOR
WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR
ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
-------------------------------------------------------------- */
#include <fstream.h> /* Header file for standard io functions */
#include <strstrea.h> /* Header file for standard io functions */
#include <iomanip.h> /* Header file for standard io functions */
#include <math.h> /* Header file for standard math functions */
#include "t2exp.h" /* Header file for t2exp function */
#include "fexp.h" /* Header file for fexp function */
#include "gettimer.h" /* Header file for GetTimer() function */
int main (int argc, char **argv)
{
/*
Comment out this code if you have changed key values
of t2exp(), but and have not yet rebuild file t2exp.inl.
t2expini();
*/
/*
To rebuild file t2exp.inl comment out this code, build
the program and run the program redirecting its output
to t2exp.inl.
t2expinl();
return 0;
*/
do
{
double num = 0;
if (argc > 1)
{
istrstream fin (argv [1]);
if (!fin) return 1;
fin >> num;
}
else
{
cout <<"Please, type argument of exp()"
" and press Enter or type Ctrl-C to exit\n";
cin >> num;
if (!cin) break;
}
#define CYCLES 1000000
cout << dec << setprecision (15);
/* Test standard exp() */
cout << " exp(" << num << ")=" << flush;
{
double expval = 0;
volatile double arg = num; /* Prevent optimization */
long timer = GetTimer (0);
for (long i = 0; i < CYCLES; i++) expval = exp (arg);
timer = GetTimer (timer);
cout << setiosflags (ios::showpoint) << expval << " "
<< resetiosflags (ios::showpoint)
<<"Time=" << setw (6) << timer << " mls" << endl;
}
/* Test t2exp() */
cout << "t2exp(" << num << ")=" << flush;
{
double expval = 0;
volatile double arg = num; /* Prevent optimization */
long timer = GetTimer (0);
for (long i = 0; i < CYCLES; i++) expval = t2exp (arg);
timer = GetTimer (timer);
cout << setiosflags (ios::showpoint) << expval << " "
<< resetiosflags (ios::showpoint)
<<"Time=" << setw (6) << timer << " mls" << endl;
}
/* Test fexp() */
cout << " fexp(" << num << ")=" << flush;
{
double expval = 0;
volatile double arg = num; /* Prevent optimization */
long timer = GetTimer (0);
for (long i = 0; i < CYCLES; i++) expval = fexp (arg);
timer = GetTimer (timer);
cout << setiosflags (ios::showpoint) << expval << " "
<< resetiosflags (ios::showpoint)
<<"Time=" << setw (6) << timer << " mls" << endl;
}
}
while (argc <= 1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -