summaryrefslogtreecommitdiffstats
path: root/Tests/Tutorial/Step2
diff options
context:
space:
mode:
authorDaniele E. Domenichelli <daniele.domenichelli@iit.it>2014-10-30 11:23:27 (GMT)
committerBrad King <brad.king@kitware.com>2014-10-31 15:32:24 (GMT)
commit36cf8a1eb9eaa6d01a434d007f707be972e6e383 (patch)
tree2d758e3bd6ee68983c3a64de834b2b891ba75421 /Tests/Tutorial/Step2
parent5c5c1e3c7dee614ab108a8809507a907a629a9d3 (diff)
downloadCMake-36cf8a1eb9eaa6d01a434d007f707be972e6e383.zip
CMake-36cf8a1eb9eaa6d01a434d007f707be972e6e383.tar.gz
CMake-36cf8a1eb9eaa6d01a434d007f707be972e6e383.tar.bz2
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/Step2')
-rw-r--r--Tests/Tutorial/Step2/tutorial.cxx8
1 files changed, 6 insertions, 2 deletions
diff --git a/Tests/Tutorial/Step2/tutorial.cxx b/Tests/Tutorial/Step2/tutorial.cxx
index 82b416f..c27da0b 100644
--- a/Tests/Tutorial/Step2/tutorial.cxx
+++ b/Tests/Tutorial/Step2/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);