From b5f80643790b0f55500089b84b11cb28c169032c Mon Sep 17 00:00:00 2001
From: Kristof Szabados <Kristof.Szabados@ericsson.com>
Date: Sat, 4 Feb 2017 17:52:30 +0100
Subject: [PATCH] build experiment: lets use cmath in these files to be more
 C++11 compatible (needs to be tested on all platforms)

Signed-off-by: Kristof Szabados <Kristof.Szabados@ericsson.com>
---
 core/Float.cc            | 14 +++++++-------
 core/Snapshot.cc         |  4 ++--
 xsdconvert/SimpleType.cc | 13 ++++++-------
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/core/Float.cc b/core/Float.cc
index c0f7a9ff3..a741a0ffb 100644
--- a/core/Float.cc
+++ b/core/Float.cc
@@ -23,7 +23,7 @@
  *
  ******************************************************************************/
 #include <string.h>
-#include <math.h>
+#include <cmath>
 #include <float.h>
 
 #include "../common/memory.h"
@@ -459,7 +459,7 @@ FLOAT::BER_encode_TLV(const TTCN_Typedescriptor_t& p_td,
       new_tlv=ASN_BER_TLV_t::construct(1, NULL);
       new_tlv->V.str.Vstr[0]=0x41;
     }
-    else if(isnan((double)float_value)) {
+    else if(std::isnan((double)float_value)) {
       TTCN_EncDec_ErrorContext::error_internal("Value is NaN.");
     }
     else {
@@ -673,7 +673,7 @@ int FLOAT::RAW_encode(const TTCN_Typedescriptor_t& p_td, RAW_enc_tree& myleaf) c
       "Encoding an unbound value.");
     tmp = 0.0;
   }
-  if (isnan(tmp)) {
+  if (std::isnan(tmp)) {
     TTCN_EncDec_ErrorContext::error_internal("Value is NaN.");
   }
   if (myleaf.must_free) Free(myleaf.body.leaf.data_ptr);
@@ -786,7 +786,7 @@ int FLOAT::RAW_decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& buff,
 #else
     for (int i = 0, k = 7; i < 8; i++, k--) dv[i] = data[k];
 #endif
-    if (isnan(tmp)) {
+    if (std::isnan(tmp)) {
       if (no_err) return -1;
       TTCN_EncDec_ErrorContext::error(TTCN_EncDec::ET_LEN_ERR,
         "Not a Number received for type %s.", p_td.name);
@@ -848,7 +848,7 @@ int FLOAT::XER_encode(const XERdescriptor_t& p_td,
   if (exer && (p_td.xer_bits & XER_DECIMAL)) {
     char buf[312];
     int n = 0;
-    if (isnan((double)float_value)) {
+    if (std::isnan((double)float_value)) {
       n = snprintf(buf, sizeof(buf), "%s", XER_NAN_STR);
     } else if ((double)float_value == (double)INFINITY) {
       n = snprintf(buf, sizeof(buf), "%s", XER_POS_INF_STR);
@@ -869,7 +869,7 @@ int FLOAT::XER_encode(const XERdescriptor_t& p_td,
   }
   else {
     CHARSTRING value;
-    if (isnan((double)float_value)) {
+    if (std::isnan((double)float_value)) {
       value = XER_NAN_STR;
     } else if ((double)float_value == (double)INFINITY) {
       value = XER_POS_INF_STR;
@@ -1074,7 +1074,7 @@ int FLOAT::JSON_encode(const TTCN_Typedescriptor_t&, JSON_Tokenizer& p_tok) cons
   if (-(double)INFINITY == value) {
     return p_tok.put_next_token(JSON_TOKEN_STRING, NEG_INF_STR);
   }
-  if (isnan(value)) {
+  if (std::isnan(value)) {
     return p_tok.put_next_token(JSON_TOKEN_STRING, NAN_STR);
   }
   
diff --git a/core/Snapshot.cc b/core/Snapshot.cc
index 7cf570f38..4d8f497b7 100644
--- a/core/Snapshot.cc
+++ b/core/Snapshot.cc
@@ -22,7 +22,7 @@
 #include <string.h>
 #include <time.h>
 #include <sys/time.h>
-#include <math.h>
+#include <cmath>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -1086,7 +1086,7 @@ void TTCN_Snapshot::take_new(boolean block_execution)
           // the first timeout is in the future: blocking is needed
           // filling up tv with appropriate values
           if (block_time < (double)MAX_BLOCK_TIME) {
-            pollTimeout = static_cast<int>(floor(block_time*1000));
+            pollTimeout = static_cast<int>(std::floor(block_time*1000));
             handleTimer = TRUE;
           } else {
             // issue a warning: the user probably does not want such
diff --git a/xsdconvert/SimpleType.cc b/xsdconvert/SimpleType.cc
index 72b7ebf43..0cc34b95b 100644
--- a/xsdconvert/SimpleType.cc
+++ b/xsdconvert/SimpleType.cc
@@ -23,8 +23,7 @@
 #include "ComplexType.hh"
 #include "Constant.hh"
 
-// TODO: once we can use C++11 as the base platform replace with cmath
-#include <math.h> // for using "pow" function
+#include <cmath>
 #include <cfloat>
 
 extern bool g_flag_used;
@@ -1373,12 +1372,12 @@ void EnumerationType::printToFile(FILE * file, unsigned int indent_level) const
         fprintf(file, "infinity");
       } else if (itemFloat->Data == MINUS_INFINITY) {
         fprintf(file, "-infinity");
-      } else if (isnan(itemFloat->Data)) {
+      } else if (std::isnan(itemFloat->Data)) {
         fprintf(file, "not_a_number");
       } else {
         double intpart = 0;
         double fracpart = 0;
-        fracpart = modf(itemFloat->Data, &intpart);
+        fracpart = std::modf(itemFloat->Data, &intpart);
         if (fracpart == 0) {
           fprintf(file, "%lld.0", (long long int) (itemFloat->Data));
         } else {
@@ -1548,7 +1547,7 @@ void ValueType::applyFacets() // only for integer and float types
   // totalDigits facet is only for integer types and decimal
   if (facet_totalDigits > 0) // if this facet is used
   {
-    double r = pow(10.0, facet_totalDigits);
+    double r = std::pow(10.0, facet_totalDigits);
 
     if (base == "integer") {
       lower = (int) -(r - 1);
@@ -1692,7 +1691,7 @@ void ValueType::printToFile(FILE * file) const {
     } else {
       double intpart = 0;
       double fracpart = 0;
-      fracpart = modf(lower, &intpart);
+      fracpart = std::modf(lower, &intpart);
       if (fracpart == 0) {
         fprintf(file, "%.1Lf", lower);
       } else {
@@ -1710,7 +1709,7 @@ void ValueType::printToFile(FILE * file) const {
     } else {
       double intpart = 0;
       double fracpart = 0;
-      fracpart = modf(upper, &intpart);
+      fracpart = std::modf(upper, &intpart);
       if (fracpart == 0) {
         fprintf(file, "%.1Lf", upper);
       } else {
-- 
GitLab