Skip to content

Commit

Permalink
tidy: Clean up integer division warnings.
Browse files Browse the repository at this point in the history
The clang-tidy "integer division result used by floating point" test
pointed out a number of potential rounding issues.  Fix most of these
by converting to a float/double before the division, whether by a an
explicit cast or by changing the integer divisor to a float divisor.

https://clang.llvm.org/extra/clang-tidy/checks/bugprone-integer-division.html
  • Loading branch information
linuxdude42 committed Nov 27, 2019
1 parent 20af35a commit 19545d3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmyth/audio/audiooutputjack.cpp
Expand Up @@ -447,7 +447,7 @@ int AudioOutputJACK::JackXRunCallback(void)
// All we want to do is chuck away some audio from the ring buffer
// to keep our audio output roughly where it should be if we didn't xrun
int fragments = (int)ceilf( ((delay / 1000000.0F) * m_samplerate )
/ (float)(m_fragment_size / m_output_bytes_per_frame) );
/ ((float)m_fragment_size / m_output_bytes_per_frame) );
m_jack_xruns += fragments; //should be at least 1...
VBERROR(QString("Jack XRun Callback: %1 usecs delayed, xruns now %2")
.arg(delay).arg(m_jack_xruns) );
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -6656,7 +6656,7 @@ void TV::DoArbSeek(PlayerContext *ctx, ArbSeekWhence whence,
if (!ok)
return;

float time = ((seek / 100) * 3600) + ((seek % 100) * 60);
float time = ((seek / 100.0F) * 3600) + ((seek % 100) * 60);

if (whence == ARBSEEK_FORWARD)
DoSeek(ctx, time, tr("Jump Ahead"),
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythtv/visualisations/goom/filters.c
Expand Up @@ -605,7 +605,11 @@ zoomFilterFastRGB (Uint * pix1, Uint * pix2, ZoomFilterData * zf, Uint resx, Uin
}

for (us = 0; us < 0xffff; us++) {
sintable[us] = (int) (1024 * sin ((double) us * 360 / (sizeof (sintable) / sizeof (sintable[0]) - 1) * 3.141592 / 180) + .5);
sintable[us] =
roundf(1024 * sin ((double) us * 360
/ ((float)sizeof (sintable)
/ sizeof (sintable[0]) - 1)
* 3.141592 / 180));
}

{
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythtv/visualisations/goom/goom_core.c
Expand Up @@ -252,16 +252,16 @@ guint32 * goom_update (gint16 data[2][512], int forceMode) {
((pointHeight - 6.0F) * largfactor + 5.0F),
i * 152.0F, 128.0F, s_loopVar + i * 2032);
pointFilter (p1 + c_offset, ORANGE,
((pointWidth / 2) * largfactor) / i + 10.0F * i,
((pointHeight / 2) * largfactor) / i + 10.0F * i,
((pointWidth / 2.0F) * largfactor) / i + 10.0F * i,
((pointHeight / 2.0F) * largfactor) / i + 10.0F * i,
96.0F, i * 80.0F, s_loopVar / i);
pointFilter (p1 + c_offset, VIOLET,
((pointHeight / 3 + 5.0F) * largfactor) / i + 10.0F * i,
((pointHeight / 3 + 5.0F) * largfactor) / i + 10.0F * i,
((pointHeight / 3.0F + 5.0F) * largfactor) / i + 10.0F * i,
((pointHeight / 3.0F + 5.0F) * largfactor) / i + 10.0F * i,
i + 122.0F, 134.0F, s_loopVar / i);
pointFilter (p1 + c_offset, BLACK,
((pointHeight / 3) * largfactor + 20.0F),
((pointHeight / 3) * largfactor + 20.0F),
((pointHeight / 3.0F) * largfactor + 20.0F),
((pointHeight / 3.0F) * largfactor + 20.0F),
58.0F, i * 66.0F, s_loopVar / i);
pointFilter (p1 + c_offset, WHITE,
(pointHeight * largfactor + 10.0F * i) / i,
Expand Down Expand Up @@ -887,7 +887,7 @@ void choose_a_goom_line (float *param1, float *param2, int *couleur, int *mode,
break;
case GML_HLINE:
if (iRAND (4) || far) {
*param1 = c_resoly / 7;
*param1 = c_resoly / 7.0F;
*param2 = 6.0F * c_resoly / 7.0F;
}
else {
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/visualisations/goom/surf3d.c
Expand Up @@ -32,9 +32,9 @@ grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) {
x = defx;
while (x) {
--x;
s->vertex[x+defx*y].x = (float)(x-defx/2)*sizex/defx;
s->vertex[x+defx*y].x = (x-defx/2.0F)*sizex/defx;
s->vertex[x+defx*y].y = 0;
s->vertex[x+defx*y].z = (float)(y-defz/2)*sizez/defz;
s->vertex[x+defx*y].z = (y-defz/2.0F)*sizez/defz;
}
}
return g;
Expand Down
8 changes: 3 additions & 5 deletions mythtv/libs/libmythui/mythuitext.cpp
Expand Up @@ -751,11 +751,10 @@ bool MythUIText::GetNarrowWidth(const QStringList & paragraphs,
too_narrow = width;

// Too narrow? How many lines didn't fit?
qreal lines = static_cast<int>
((height - m_drawRect.height()) / line_height);
qreal lines = roundf((height - m_drawRect.height()) / line_height);
lines -= (1.0 - last_line_width / width);
width += (lines * width) /
(m_drawRect.height() / line_height);
((double)m_drawRect.height() / line_height);

if (width > best_width || static_cast<int>(width) == last_width)
{
Expand All @@ -769,8 +768,7 @@ bool MythUIText::GetNarrowWidth(const QStringList & paragraphs,
if (best_width > width)
best_width = width;

qreal lines = static_cast<int>
(m_Area.height() - height) / line_height;
qreal lines = floor((m_Area.height() - height) / line_height);
if (lines >= 1)
{
// Too wide?
Expand Down

0 comments on commit 19545d3

Please sign in to comment.