summaryrefslogtreecommitdiff
path: root/Tests/Tutorial/Step5/tutorial.cxx
diff options
context:
space:
mode:
authorDaniele E. Domenichelli <daniele.domenichelli@iit.it>2014-10-30 12:23:27 +0100
committerBrad King <brad.king@kitware.com>2014-10-31 11:32:24 -0400
commit36cf8a1eb9eaa6d01a434d007f707be972e6e383 (patch)
tree2d758e3bd6ee68983c3a64de834b2b891ba75421 /Tests/Tutorial/Step5/tutorial.cxx
parent5c5c1e3c7dee614ab108a8809507a907a629a9d3 (diff)
downloadcmake-36cf8a1eb9eaa6d01a434d007f707be972e6e383.tar.gz
Tests/Tutorial: Fix when USE_MYMATH is OFF
Unit tests for the square root of "-25" currently fail when USE_MYMATH is disabled. The "mysqrt" method in the tutorials, returns "0" for a negative value, while "sqrt" returns "NaN", and therefore the output is not accepted by the test. This patch checks if the number is negative and eventually returns "0" before calling "sqrt" or "mysqrt" to fix this issue. Printing a NaN might cause issues with the string catched by the tests on some platform. Therefore assume that "0" is correct and "fix" the USE_MYMATH=OFF version by checking if the number is negative and eventually returning "0" before calling "sqrt" or "mysqrt".
Diffstat (limited to 'Tests/Tutorial/Step5/tutorial.cxx')
-rw-r--r--Tests/Tutorial/Step5/tutorial.cxx8
1 files changed, 6 insertions, 2 deletions
diff --git a/Tests/Tutorial/Step5/tutorial.cxx b/Tests/Tutorial/Step5/tutorial.cxx
index 82b416f11b..c27da0b847 100644
--- a/Tests/Tutorial/Step5/tutorial.cxx
+++ b/Tests/Tutorial/Step5/tutorial.cxx
@@ -21,12 +21,16 @@ int main (int argc, char *argv[])
}
double inputValue = atof(argv[1]);
+ double outputValue = 0;
+ if(inputValue >= 0)
+ {
#ifdef USE_MYMATH
- double outputValue = mysqrt(inputValue);
+ outputValue = mysqrt(inputValue);
#else
- double outputValue = sqrt(inputValue);
+ outputValue = sqrt(inputValue);
#endif
+ }
fprintf(stdout,"The square root of %g is %g\n",
inputValue, outputValue);