Avoid passing float argument for "%f" printf specifier

"%f" takes a double. Eliminates some -Wdouble-promotion warnings.
This commit is contained in:
Paul Cornett 2020-04-21 11:59:36 -07:00
parent 62372d4337
commit c5faf9cfac
10 changed files with 21 additions and 21 deletions

View File

@ -51,7 +51,7 @@ public:
static wxString MakeString(const int& v) { return wxString::Format(wxT("%d"), v); } static wxString MakeString(const int& v) { return wxString::Format(wxT("%d"), v); }
static wxString MakeString(const long& v) { return wxString::Format(wxT("%ld"), v); } static wxString MakeString(const long& v) { return wxString::Format(wxT("%ld"), v); }
static wxString MakeString(const double& v) { return wxString::Format(wxT("%.2f"), (float) v); } static wxString MakeString(const double& v) { return wxString::Format(wxS("%.2f"), v); }
static wxString MakeString(const wxString& s) { return s; } static wxString MakeString(const wxString& s) { return s; }
static wxString MakeString(const wxColour& col) { return wxT("#") + ColourToHexString(col); } static wxString MakeString(const wxColour& col) { return wxT("#") + ColourToHexString(col); }
@ -101,7 +101,7 @@ public:
static void AddString(wxString& str, const int& v) { str << wxString::Format(wxT("%d"), v); } static void AddString(wxString& str, const int& v) { str << wxString::Format(wxT("%d"), v); }
static void AddString(wxString& str, const long& v) { str << wxString::Format(wxT("%ld"), v); } static void AddString(wxString& str, const long& v) { str << wxString::Format(wxT("%ld"), v); }
static void AddString(wxString& str, const double& v) { str << wxString::Format(wxT("%.2f"), (float) v); } static void AddString(wxString& str, const double& v) { str << wxString::Format(wxS("%.2f"), v); }
static void AddString(wxString& str, const wxChar* s) { str << s; } static void AddString(wxString& str, const wxChar* s) { str << s; }
static void AddString(wxString& str, const wxString& s) { str << s; } static void AddString(wxString& str, const wxString& s) { str << s; }
static void AddString(wxString& str, const wxColour& col) { str << wxT("#") << ColourToHexString(col); } static void AddString(wxString& str, const wxColour& col) { str << wxT("#") << ColourToHexString(col); }

View File

@ -2027,7 +2027,7 @@ public:
#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
// insert a float into string // insert a float into string
wxString& operator<<(float f) wxString& operator<<(float f)
{ return (*this) << Format(wxT("%f"), f); } { return *this << static_cast<double>(f); }
// insert a double into string // insert a double into string
wxString& operator<<(double d) wxString& operator<<(double d)
{ return (*this) << Format(wxT("%g"), d); } { return (*this) << Format(wxT("%g"), d); }

View File

@ -146,8 +146,8 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
text_output << d << "\n"; text_output << d << "\n";
std_file_output << d << "\n"; std_file_output << d << "\n";
float f = (float)0.00001; float f = 0.00001f;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( "Float: %f\n", double(f) );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_output << f << "\n"; text_output << f << "\n";
std_file_output << f << "\n"; std_file_output << f << "\n";
@ -177,7 +177,7 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
std_file_input >> f; std_file_input >> f;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( "Float: %f\n", double(f) );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
char std_buf[200]; char std_buf[200];
@ -207,7 +207,7 @@ void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> f; text_input >> f;
tmp.Printf( "Float: %f\n", f ); tmp.Printf( "Float: %f\n", double(f) );
textCtrl.WriteText( tmp ); textCtrl.WriteText( tmp );
text_input >> str; text_input >> str;

View File

@ -224,7 +224,7 @@ void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
m_listbox->Append(wxString::Format("integer value: %d", g_data.m_intValue)); m_listbox->Append(wxString::Format("integer value: %d", g_data.m_intValue));
m_listbox->Append(wxString::Format("small int value: %u", g_data.m_smallIntValue)); m_listbox->Append(wxString::Format("small int value: %u", g_data.m_smallIntValue));
m_listbox->Append(wxString::Format("double value: %.3f", g_data.m_doubleValue)); m_listbox->Append(wxString::Format("double value: %.3f", g_data.m_doubleValue));
m_listbox->Append(wxString::Format("percent value: %.4f", g_data.m_percentValue)); m_listbox->Append(wxString::Format("percent value: %.4f", double(g_data.m_percentValue)));
} }
} }

View File

@ -141,7 +141,7 @@ wxString GetPenPattern(const wxPen& pen)
// When the pen width increases, lines become thicker and unrecognizable. // When the pen width increases, lines become thicker and unrecognizable.
// Multiplying with 1/3th of the width creates line styles matching the appearance of wxDC. // Multiplying with 1/3th of the width creates line styles matching the appearance of wxDC.
// The pen width is not used to modify user provided dash styles. // The pen width is not used to modify user provided dash styles.
float w = pen.GetWidth(); double w = pen.GetWidth();
if (pen.GetWidth() == 0) if (pen.GetWidth() == 0)
w = 1; w = 1;
w = w / 3; w = w / 3;

View File

@ -349,7 +349,7 @@ bool wxGenericValidator::TransferToWindow()
} }
else if (m_pFloat) else if (m_pFloat)
{ {
pControl->SetValue(wxString::Format(wxT("%g"), *m_pFloat)); pControl->SetValue(wxString::Format(wxS("%g"), double(*m_pFloat)));
return true; return true;
} }
else if (m_pDouble) else if (m_pDouble)

View File

@ -315,7 +315,7 @@ wxDbgHelpDLL::DumpBaseType(BasicType bt, DWORD64 length, PVOID pAddress)
if ( bt == BASICTYPE_FLOAT ) if ( bt == BASICTYPE_FLOAT )
{ {
s.Printf(wxT("%f"), *(PFLOAT)pAddress); s.Printf(wxS("%f"), double(*(PFLOAT)pAddress));
handled = true; handled = true;
} }

View File

@ -615,7 +615,7 @@ void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension& dim, wxT
else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM) else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM)
{ {
unitsIdx = 1; // By default, the 2nd in the list. unitsIdx = 1; // By default, the 2nd in the list.
float value = dim.GetValue() / 100.0f; double value = dim.GetValue() / 100.0;
valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value)); valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value));
} }
else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE) else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE)
@ -626,7 +626,7 @@ void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension& dim, wxT
else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_HUNDREDTHS_POINT) else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_HUNDREDTHS_POINT)
{ {
unitsIdx = 3; // By default, the 4th in the list. unitsIdx = 3; // By default, the 4th in the list.
float value = dim.GetValue() / 100.0f; double value = dim.GetValue() / 100.0;
valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value)); valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value));
} }
else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_POINTS) else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_POINTS)

View File

@ -325,29 +325,29 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxRichTextAttr& WXUNU
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore()) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore())
{ {
float spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0f; double spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0;
styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM); styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM);
} }
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter()) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter())
{ {
float spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0f; double spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0;
styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM); styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM);
} }
float indentLeftMM = (thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent())/10.0f; double indentLeftMM = (thisStyle.GetLeftIndent() + thisStyle.GetLeftSubIndent()) / 10.0;
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (indentLeftMM > 0.0)) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (indentLeftMM > 0.0))
{ {
styleStr += wxString::Format(wxT("margin-left: %.2fmm; "), indentLeftMM); styleStr += wxString::Format(wxT("margin-left: %.2fmm; "), indentLeftMM);
} }
float indentRightMM = thisStyle.GetRightIndent()/10.0f; double indentRightMM = thisStyle.GetRightIndent() / 10.0;
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasRightIndent() && (indentRightMM > 0.0)) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasRightIndent() && (indentRightMM > 0.0))
{ {
styleStr += wxString::Format(wxT("margin-right: %.2fmm; "), indentRightMM); styleStr += wxString::Format(wxT("margin-right: %.2fmm; "), indentRightMM);
} }
// First line indentation // First line indentation
float firstLineIndentMM = - thisStyle.GetLeftSubIndent() / 10.0f; double firstLineIndentMM = - thisStyle.GetLeftSubIndent() / 10.0;
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (firstLineIndentMM > 0.0)) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && (firstLineIndentMM > 0.0))
{ {
styleStr += wxString::Format(wxT("text-indent: %.2fmm; "), firstLineIndentMM); styleStr += wxString::Format(wxT("text-indent: %.2fmm; "), firstLineIndentMM);
@ -385,13 +385,13 @@ void wxRichTextHTMLHandler::BeginParagraphFormatting(const wxRichTextAttr& WXUNU
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore()) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingBefore())
{ {
float spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0f; double spacingBeforeMM = thisStyle.GetParagraphSpacingBefore() / 10.0;
styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM); styleStr += wxString::Format(wxT("margin-top: %.2fmm; "), spacingBeforeMM);
} }
if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter()) if ((GetFlags() & wxRICHTEXT_HANDLER_USE_CSS) && thisStyle.HasParagraphSpacingAfter())
{ {
float spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0f; double spacingAfterMM = thisStyle.GetParagraphSpacingAfter() / 10.0;
styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM); styleStr += wxString::Format(wxT("margin-bottom: %.2fmm; "), spacingAfterMM);
} }

View File

@ -2033,7 +2033,7 @@ void wxRichTextXMLHelper::AddAttribute(wxString& str, const wxString& name, cons
void wxRichTextXMLHelper::AddAttribute(wxString& str, const wxString& name, const double& v) void wxRichTextXMLHelper::AddAttribute(wxString& str, const wxString& name, const double& v)
{ {
str << wxT(" ") << name << wxT("=\"") << wxString::Format(wxT("%.2f"), (float) v) << wxT("\""); str << wxS(" ") << name << wxS("=\"") << wxString::Format(wxS("%.2f"), v) << wxS("\"");
} }
void wxRichTextXMLHelper::AddAttribute(wxString& str, const wxString& name, const wxChar* s) void wxRichTextXMLHelper::AddAttribute(wxString& str, const wxString& name, const wxChar* s)