Consistently use math.h functions.
Use nan(), isnan(), isfinite() and friends from math.h, instead of their
std:: equivalents from cmath.
Change-Id: I4b787a809c2dddccfd32c497fbd27c7ad23bc7e4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83892
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp b/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
index 43f3811..8d4e756 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
@@ -4,6 +4,8 @@
#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
+#include <math.h>
+
#include <algorithm>
#include <limits>
#include <vector>
@@ -36,7 +38,7 @@
EXPECT_EQ(data[0], fMin);
EXPECT_EQ(data[1], fMax);
EXPECT_EQ(data[2], fInf);
- EXPECT_EQ(std::isnan(data[3]), std::isnan(fNan));
+ EXPECT_EQ(isnan(data[3]), isnan(fNan));
std::map<GraphicsData, int> graphics_map;
diff --git a/core/fpdfapi/page/cpdf_psengine.cpp b/core/fpdfapi/page/cpdf_psengine.cpp
index 7bb2803..ba41d95 100644
--- a/core/fpdfapi/page/cpdf_psengine.cpp
+++ b/core/fpdfapi/page/cpdf_psengine.cpp
@@ -6,8 +6,9 @@
#include "core/fpdfapi/page/cpdf_psengine.h"
+#include <math.h>
+
#include <algorithm>
-#include <cmath>
#include <limits>
#include <utility>
@@ -73,7 +74,7 @@
// Round half up is a nearest integer round with half-way numbers always rounded
// up. Example: -5.5 rounds to -5.
float RoundHalfUp(float f) {
- if (std::isnan(f))
+ if (isnan(f))
return 0;
if (f > std::numeric_limits<float>::max() - 0.5f)
return std::numeric_limits<float>::max();
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 8c12fac..53b0d84 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -6,7 +6,8 @@
#include "core/fxcrt/css/cfx_cssdeclaration.h"
-#include <cmath>
+#include <math.h>
+
#include <utility>
#include "core/fxcrt/css/cfx_csscolorvalue.h"
@@ -38,7 +39,7 @@
int32_t iUsedLen = 0;
*pValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen);
- if (iUsedLen <= 0 || !std::isfinite(*pValue))
+ if (iUsedLen <= 0 || !isfinite(*pValue))
return false;
iValueLen -= iUsedLen;
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index f747ee4..46eea98 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -7,10 +7,10 @@
#ifndef CORE_FXCRT_FX_EXTENSION_H_
#define CORE_FXCRT_FX_EXTENSION_H_
+#include <math.h>
#include <time.h>
#include <cctype>
-#include <cmath>
#include <cwctype>
#include <memory>
@@ -121,16 +121,16 @@
// All NaNs are treated as equal to each other and greater than infinity.
template <typename T>
bool FXSYS_SafeEQ(const T& lhs, const T& rhs) {
- return (std::isnan(lhs) && std::isnan(rhs)) ||
- (!std::isnan(lhs) && !std::isnan(rhs) && lhs == rhs);
+ return (isnan(lhs) && isnan(rhs)) ||
+ (!isnan(lhs) && !isnan(rhs) && lhs == rhs);
}
template <typename T>
bool FXSYS_SafeLT(const T& lhs, const T& rhs) {
- if (std::isnan(lhs) && std::isnan(rhs))
+ if (isnan(lhs) && isnan(rhs))
return false;
- if (std::isnan(lhs) || std::isnan(rhs))
- return std::isnan(lhs) < std::isnan(rhs);
+ if (isnan(lhs) || isnan(rhs))
+ return isnan(lhs) < isnan(rhs);
return lhs < rhs;
}
diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp
index fd03ab2..090c76b 100644
--- a/core/fxcrt/fx_extension_unittest.cpp
+++ b/core/fxcrt/fx_extension_unittest.cpp
@@ -4,6 +4,8 @@
#include "core/fxcrt/fx_extension.h"
+#include <math.h>
+
#include <limits>
#include "testing/gtest/include/gtest/gtest.h"
@@ -175,14 +177,14 @@
// Overflow to infinity.
used_len = 0;
- EXPECT_TRUE(std::isinf(FXSYS_wcstof(
+ EXPECT_TRUE(isinf(FXSYS_wcstof(
L"88888888888888888888888888888888888888888888888888888888888888888888888"
L"88888888888888888888888888888888888888888888888888888888888",
130, &used_len)));
EXPECT_EQ(130, used_len);
used_len = 0;
- EXPECT_TRUE(std::isinf(FXSYS_wcstof(
+ EXPECT_TRUE(isinf(FXSYS_wcstof(
L"-8888888888888888888888888888888888888888888888888888888888888888888888"
L"888888888888888888888888888888888888888888888888888888888888",
131, &used_len)));
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index 47d2db9..d8e02c9 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -6,7 +6,8 @@
#include "core/fxcrt/fx_system.h"
-#include <cmath>
+#include <math.h>
+
#include <limits>
#include "build/build_config.h"
@@ -89,7 +90,7 @@
} // namespace
int FXSYS_roundf(float f) {
- if (std::isnan(f))
+ if (isnan(f))
return 0;
if (f < static_cast<float>(std::numeric_limits<int>::min()))
return std::numeric_limits<int>::min();
@@ -99,7 +100,7 @@
}
int FXSYS_round(double d) {
- if (std::isnan(d))
+ if (isnan(d))
return 0;
if (d < static_cast<double>(std::numeric_limits<int>::min()))
return std::numeric_limits<int>::min();
diff --git a/fxjs/cfx_v8_unittest.cpp b/fxjs/cfx_v8_unittest.cpp
index 8deda61..bd6ce0a 100644
--- a/fxjs/cfx_v8_unittest.cpp
+++ b/fxjs/cfx_v8_unittest.cpp
@@ -4,7 +4,8 @@
#include "fxjs/cfx_v8.h"
-#include <cmath>
+#include <math.h>
+
#include <memory>
#include "testing/fxv8_unittest.h"
@@ -83,7 +84,7 @@
auto undef = cfx_v8()->NewUndefined();
EXPECT_FALSE(cfx_v8()->ToBoolean(undef));
EXPECT_EQ(0, cfx_v8()->ToInt32(undef));
- EXPECT_TRUE(std::isnan(cfx_v8()->ToDouble(undef)));
+ EXPECT_TRUE(isnan(cfx_v8()->ToDouble(undef)));
EXPECT_EQ("undefined", cfx_v8()->ToByteString(undef));
EXPECT_EQ(L"undefined", cfx_v8()->ToWideString(undef));
EXPECT_TRUE(cfx_v8()->ToObject(undef).IsEmpty());
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index db650e2..8fa8f1d 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -6,8 +6,9 @@
#include "fxjs/cjs_publicmethods.h"
+#include <math.h>
+
#include <algorithm>
-#include <cmath>
#include <cwctype>
#include <iomanip>
#include <iterator>
@@ -429,14 +430,14 @@
double CJS_PublicMethods::ParseDateUsingFormat(const WideString& value,
const WideString& format,
bool* bWrongFormat) {
- double dRet = std::nan("");
+ double dRet = nan("");
fxjs::ConversionStatus status = FX_ParseDateUsingFormat(value, format, &dRet);
if (status == fxjs::ConversionStatus::kSuccess)
return dRet;
if (status == fxjs::ConversionStatus::kBadDate) {
dRet = JS_DateParse(value);
- if (!std::isnan(dRet))
+ if (!isnan(dRet))
return dRet;
}
@@ -901,7 +902,7 @@
dDate = ParseDateUsingFormat(strValue, sFormat, nullptr);
}
- if (std::isnan(dDate)) {
+ if (isnan(dDate)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
AlertIfPossible(pContext, L"AFDate_FormatEx", swMsg);
@@ -942,7 +943,7 @@
int nYear = StringToFloat(wsArray[7].AsStringView());
double dRet = FX_MakeDate(FX_MakeDay(nYear, nMonth - 1, nDay),
FX_MakeTime(nHour, nMin, nSec, 0));
- if (std::isnan(dRet))
+ if (isnan(dRet))
dRet = JS_DateParse(strValue);
return dRet;
@@ -972,7 +973,7 @@
bool bWrongFormat = false;
WideString sFormat = pRuntime->ToWideString(params[0]);
double dRet = ParseDateUsingFormat(strValue, sFormat, &bWrongFormat);
- if (bWrongFormat || std::isnan(dRet)) {
+ if (bWrongFormat || isnan(dRet)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
AlertIfPossible(pContext, L"AFDate_KeystrokeEx", swMsg);
@@ -1233,7 +1234,7 @@
WideString sValue = pRuntime->ToWideString(params[0]);
WideString sFormat = pRuntime->ToWideString(params[1]);
double dDate = ParseDateUsingFormat(sValue, sFormat, nullptr);
- if (std::isnan(dDate)) {
+ if (isnan(dDate)) {
WideString swMsg = WideString::Format(
JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
AlertIfPossible(pRuntime->GetCurrentEventContext(), L"AFParseDateEx",
@@ -1252,7 +1253,7 @@
WideString sFunction = pRuntime->ToWideString(params[0]);
double arg1 = pRuntime->ToDouble(params[1]);
double arg2 = pRuntime->ToDouble(params[2]);
- if (std::isnan(arg1) || std::isnan(arg2))
+ if (isnan(arg1) || isnan(arg2))
return CJS_Result::Failure(JSMessage::kValueError);
Optional<double> result = ApplyNamedOperation(sFunction.c_str(), arg1, arg2);
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 3027b9d..95909fb 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -6,6 +6,8 @@
#include "fxjs/cjs_runtime.h"
+#include <math.h>
+
#include <algorithm>
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
@@ -224,7 +226,7 @@
return value;
v8::Local<v8::Number> num = maybeNum.ToLocalChecked();
- if (std::isnan(num->Value()) && !bAllowNaN)
+ if (isnan(num->Value()) && !bAllowNaN)
return value;
return num;
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 5440869..a66581a 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -6,10 +6,10 @@
#include "fxjs/cjs_util.h"
+#include <math.h>
#include <time.h>
#include <algorithm>
-#include <cmath>
#include <cwctype>
#include <string>
#include <vector>
@@ -171,7 +171,7 @@
return CJS_Result::Failure(JSMessage::kSecondParamNotDateError);
v8::Local<v8::Date> v8_date = params[1].As<v8::Date>();
- if (v8_date.IsEmpty() || std::isnan(pRuntime->ToDouble(v8_date)))
+ if (v8_date.IsEmpty() || isnan(pRuntime->ToDouble(v8_date)))
return CJS_Result::Failure(JSMessage::kSecondParamInvalidDateError);
double date = FX_LocalTime(pRuntime->ToDouble(v8_date));
@@ -377,7 +377,7 @@
double dDate = FX_GetDateTime();
if (sDate.GetLength() > 0)
dDate = CJS_PublicMethods::ParseDateUsingFormat(sDate, sFormat, nullptr);
- if (std::isnan(dDate))
+ if (isnan(dDate))
return CJS_Result::Success(pRuntime->NewUndefined());
return CJS_Result::Success(pRuntime->NewDate(dDate));
diff --git a/fxjs/fx_date_helpers.cpp b/fxjs/fx_date_helpers.cpp
index 2b0474f..74154d6 100644
--- a/fxjs/fx_date_helpers.cpp
+++ b/fxjs/fx_date_helpers.cpp
@@ -6,10 +6,9 @@
#include "fxjs/fx_date_helpers.h"
+#include <math.h>
#include <time.h>
-#include <cmath>
-
#include "build/build_config.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_system.h"
@@ -248,7 +247,7 @@
double mn = Mod(m, 12);
double t = TimeFromYearMonth(static_cast<int>(ym), static_cast<int>(mn));
if (YearFromTime(t) != ym || MonthFromTime(t) != mn || DateFromTime(t) != 1)
- return std::nan("");
+ return nan("");
return Day(t) + dt - 1;
}
@@ -262,8 +261,8 @@
}
double FX_MakeDate(double day, double time) {
- if (!std::isfinite(day) || !std::isfinite(time))
- return std::nan("");
+ if (!isfinite(day) || !isfinite(time))
+ return nan("");
return day * 86400000 + time;
}
@@ -542,7 +541,7 @@
dt = FX_MakeDate(FX_MakeDay(nYear, nMonth - 1, nDay),
FX_MakeTime(nHour, nMin, nSec, 0));
- if (std::isnan(dt))
+ if (isnan(dt))
return ConversionStatus::kBadDate;
*result = dt;
diff --git a/fxjs/js_define.cpp b/fxjs/js_define.cpp
index 950b287..e86330c 100644
--- a/fxjs/js_define.cpp
+++ b/fxjs/js_define.cpp
@@ -6,10 +6,10 @@
#include "fxjs/js_define.h"
+#include <math.h>
#include <stdarg.h>
#include <algorithm>
-#include <cmath>
#include <limits>
#include <vector>
@@ -54,7 +54,7 @@
return 0;
double date = value.As<v8::Number>()->Value();
- return std::isfinite(date) ? FX_LocalTime(date) : date;
+ return isfinite(date) ? FX_LocalTime(date) : date;
}
std::vector<v8::Local<v8::Value>> ExpandKeywordParams(
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index b8dd401..2cf112e 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -4484,8 +4484,7 @@
bsLocale = ValueToUTF8String(info.GetIsolate(), localeValue);
}
- if (std::isnan(fNumber) || fNumber < 0.0f ||
- fNumber > 922337203685477550.0f) {
+ if (isnan(fNumber) || fNumber < 0.0f || fNumber > 922337203685477550.0f) {
info.GetReturnValue().Set(fxv8::NewStringHelper(info.GetIsolate(), "*"));
return;
}
diff --git a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
index 64d535f..1241659 100644
--- a/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context_embeddertest.cpp
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <cmath>
+#include <math.h>
#include "fxjs/fxv8.h"
#include "fxjs/xfa/cfxjse_engine.h"
@@ -87,7 +87,7 @@
CFXJSE_ScopeUtil_IsolateHandleContext scope(GetJseContext());
v8::Local<v8::Value> value = GetValue();
EXPECT_TRUE(fxv8::IsNumber(value));
- EXPECT_TRUE(std::isnan(fxv8::ReentrantToDoubleHelper(isolate(), value)));
+ EXPECT_TRUE(isnan(fxv8::ReentrantToDoubleHelper(isolate(), value)));
}
void ExecuteExpectString(ByteStringView input, const char* expected) {
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.cpp b/xfa/fgas/graphics/cfgas_gegraphics.cpp
index a8e197b..f145d52 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.cpp
+++ b/xfa/fgas/graphics/cfgas_gegraphics.cpp
@@ -6,7 +6,8 @@
#include "xfa/fgas/graphics/cfgas_gegraphics.h"
-#include <cmath>
+#include <math.h>
+
#include <memory>
#include "core/fxcrt/fx_system.h"
@@ -305,7 +306,7 @@
float x = static_cast<float>(column);
scale = (((x - start_x) * x_span) + ((y - start_y) * y_span)) /
axis_len_square;
- if (std::isnan(scale) || scale < 0.0f) {
+ if (isnan(scale) || scale < 0.0f) {
if (!m_info.fillColor.GetShading()->IsExtendedBegin())
continue;
scale = 0.0f;
@@ -366,7 +367,7 @@
continue;
}
}
- if (std::isnan(s) || s < 0.0f) {
+ if (isnan(s) || s < 0.0f) {
if (!m_info.fillColor.GetShading()->IsExtendedBegin())
continue;
s = 0.0f;
diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp
index 81dab32..c188ef3 100644
--- a/xfa/fxfa/parser/cxfa_measurement.cpp
+++ b/xfa/fxfa/parser/cxfa_measurement.cpp
@@ -6,7 +6,7 @@
#include "xfa/fxfa/parser/cxfa_measurement.h"
-#include <cmath>
+#include <math.h>
#include "core/fxcrt/fx_extension.h"
#include "third_party/base/notreached.h"
@@ -45,7 +45,7 @@
int32_t iUsedLen = 0;
float fValue = FXSYS_wcstof(wsMeasure.unterminated_c_str(),
wsMeasure.GetLength(), &iUsedLen);
- if (!std::isfinite(fValue))
+ if (!isfinite(fValue))
fValue = 0.0f;
wsMeasure = wsMeasure.Last(wsMeasure.GetLength() - iUsedLen);