Remove CFGAS_Decimal implicit conversion operators.
And fix a few needless conversions as exposed by the change.
Change-Id: I4cca149dd74cc727c83bef7a2b82611677e01c8d
Reviewed-on: https://pdfium-review.googlesource.com/c/50611
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 00ae76f..6fb3459 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -1753,7 +1753,7 @@
}
CFGAS_Decimal decimalValue(static_cast<float>(dValue), uPrecision);
- args.GetReturnValue()->SetDouble(decimalValue);
+ args.GetReturnValue()->SetDouble(decimalValue.ToDouble());
}
// static
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index 53cf91b..1b41a27 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -283,7 +283,7 @@
pValue->SetString(content.ToUTF8().AsStringView());
} else {
CFGAS_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
+ pValue->SetFloat(decimal.ToFloat());
}
} else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
pValue->SetInteger(FXSYS_wtoi(content.c_str()));
@@ -291,7 +291,7 @@
pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
} else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
CFGAS_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
+ pValue->SetFloat(decimal.ToFloat());
} else {
pValue->SetString(content.ToUTF8().AsStringView());
}
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 860a612..3ae47cc 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -1460,7 +1460,7 @@
pValue->SetInteger(FXSYS_wtoi(content.c_str()));
} else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
CFGAS_Decimal decimal(content.AsStringView());
- pValue->SetFloat((float)(double)decimal);
+ pValue->SetFloat(decimal.ToFloat());
} else {
pValue->SetString(content.ToUTF8().AsStringView());
}
diff --git a/xfa/fgas/BUILD.gn b/xfa/fgas/BUILD.gn
index e2f84c6..76db6a1 100644
--- a/xfa/fgas/BUILD.gn
+++ b/xfa/fgas/BUILD.gn
@@ -49,6 +49,7 @@
pdfium_unittest_source_set("unittests") {
sources = [
+ "crt/cfgas_decimal_unittest.cpp",
"crt/cfgas_formatstring_unittest.cpp",
]
deps = [
diff --git a/xfa/fgas/crt/cfgas_decimal.cpp b/xfa/fgas/crt/cfgas_decimal.cpp
index f83d46f..4783ca1 100644
--- a/xfa/fgas/crt/cfgas_decimal.cpp
+++ b/xfa/fgas/crt/cfgas_decimal.cpp
@@ -329,7 +329,7 @@
m_uFlags = FXMATH_DECIMAL_MAKEFLAGS(negmet && IsNotZero(), scale);
}
-CFGAS_Decimal::operator WideString() const {
+WideString CFGAS_Decimal::ToWideString() const {
WideString retString;
WideString tmpbuf;
uint64_t phi = m_uHi;
@@ -355,7 +355,11 @@
return retString;
}
-CFGAS_Decimal::operator double() const {
+float CFGAS_Decimal::ToFloat() const {
+ return static_cast<float>(ToDouble());
+}
+
+double CFGAS_Decimal::ToDouble() const {
double pow = (double)(1 << 16) * (1 << 16);
double base = static_cast<double>(m_uHi) * pow * pow +
static_cast<double>(m_uMid) * pow + static_cast<double>(m_uLo);
diff --git a/xfa/fgas/crt/cfgas_decimal.h b/xfa/fgas/crt/cfgas_decimal.h
index e48e076..1b524b5 100644
--- a/xfa/fgas/crt/cfgas_decimal.h
+++ b/xfa/fgas/crt/cfgas_decimal.h
@@ -18,8 +18,9 @@
CFGAS_Decimal(float val, uint8_t scale);
explicit CFGAS_Decimal(WideStringView str);
- operator WideString() const;
- operator double() const;
+ WideString ToWideString() const;
+ float ToFloat() const;
+ double ToDouble() const;
CFGAS_Decimal operator*(const CFGAS_Decimal& val) const;
CFGAS_Decimal operator/(const CFGAS_Decimal& val) const;
diff --git a/xfa/fgas/crt/cfgas_decimal_unittest.cpp b/xfa/fgas/crt/cfgas_decimal_unittest.cpp
new file mode 100644
index 0000000..b1581b5
--- /dev/null
+++ b/xfa/fgas/crt/cfgas_decimal_unittest.cpp
@@ -0,0 +1,16 @@
+// Copyright 2019 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "xfa/fgas/crt/cfgas_decimal.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/ptr_util.h"
+#include "xfa/fxfa/parser/cxfa_localemgr.h"
+
+TEST(CFGAS_Decimal, Empty) {
+ CFGAS_Decimal empty;
+ EXPECT_EQ(L"0", empty.ToWideString());
+ EXPECT_EQ(0.0f, empty.ToFloat());
+ EXPECT_EQ(0.0, empty.ToDouble());
+}
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index b1b2f41..7cc6d93 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -1537,7 +1537,7 @@
if (bHavePercentSymbol)
decimal = decimal / CFGAS_Decimal(100);
- *wsValue = decimal;
+ *wsValue = decimal.ToWideString();
}
if (bNeg)
wsValue->InsertAtFront(L'-');
@@ -1877,7 +1877,7 @@
CFGAS_Decimal decimal = CFGAS_Decimal(wsSrcNum.AsStringView());
if (dwNumStyle & FX_NUMSTYLE_Percent) {
decimal = decimal * CFGAS_Decimal(100);
- wsSrcNum = decimal;
+ wsSrcNum = decimal.ToWideString();
}
int32_t exponent = 0;
@@ -1901,17 +1901,17 @@
threshold *= 10;
fixed_count--;
}
- if (decimal != CFGAS_Decimal(0)) {
- if (decimal < CFGAS_Decimal(threshold)) {
+ if (decimal.ToDouble() != 0.0) {
+ if (decimal.ToDouble() < threshold) {
decimal = decimal * CFGAS_Decimal(10);
exponent = -1;
- while (decimal < CFGAS_Decimal(threshold)) {
+ while (decimal.ToDouble() < threshold) {
decimal = decimal * CFGAS_Decimal(10);
exponent -= 1;
}
- } else if (decimal > CFGAS_Decimal(threshold)) {
+ } else if (decimal.ToDouble() > threshold) {
threshold *= 10;
- while (decimal > CFGAS_Decimal(threshold)) {
+ while (decimal.ToDouble() > threshold) {
decimal = decimal / CFGAS_Decimal(10);
exponent += 1;
}
@@ -1925,7 +1925,7 @@
int32_t scale = decimal.GetScale();
if (iTreading < scale) {
decimal.SetScale(iTreading);
- wsSrcNum = decimal;
+ wsSrcNum = decimal.ToWideString();
}
if (bTrimTailZeros && scale > 0 && iTreading > 0) {
wsSrcNum.TrimRight(L"0");
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 90acafb..eab72cb 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4892,7 +4892,7 @@
if (iTread != -1) {
CFGAS_Decimal wsDeci = CFGAS_Decimal(wsValue.AsStringView());
wsDeci.SetScale(iTread);
- wsRet = wsDeci;
+ wsRet = wsDeci.ToWideString();
}
return wsRet;
}