cmake/Tests/Tutorial/Step5/tutorial.cxx

34 lines
729 B
C++
Raw Normal View History

// A simple program that computes the square root of a number
2016-07-09 11:21:54 +02:00
#include "TutorialConfig.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef USE_MYMATH
2018-08-09 18:06:22 +02:00
# include "MathFunctions.h"
#endif
2016-07-09 11:21:54 +02:00
int main(int argc, char* argv[])
{
2016-07-09 11:21:54 +02:00
if (argc < 2) {
fprintf(stdout, "%s Version %d.%d\n", argv[0], Tutorial_VERSION_MAJOR,
Tutorial_VERSION_MINOR);
2016-07-09 11:21:54 +02:00
fprintf(stdout, "Usage: %s number\n", argv[0]);
return 1;
2016-07-09 11:21:54 +02:00
}
double inputValue = atof(argv[1]);
2015-04-27 22:25:09 +02:00
double outputValue = 0;
2016-07-09 11:21:54 +02:00
if (inputValue >= 0) {
#ifdef USE_MYMATH
2015-04-27 22:25:09 +02:00
outputValue = mysqrt(inputValue);
#else
2015-04-27 22:25:09 +02:00
outputValue = sqrt(inputValue);
#endif
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
return 0;
}