diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index b9e041b6a..173c27b40 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -210,7 +210,7 @@ void ServiceCheck::Generator::paintFrame( const auto frames = framesForStyle(st); auto &image = frames->image; const auto count = int(frames->ready.size()); - const auto index = int(std::round(toggled * (count - 1))); + const auto index = int(base::SafeRound(toggled * (count - 1))); Assert(index >= 0 && index < count); if (!frames->ready[index]) { frames->ready[index] = true; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp index b28428d9f..41b8e6e14 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp @@ -268,7 +268,8 @@ void Row::update(const InviteLinkData &data, TimeId now) { void Row::updateExpireProgress(TimeId now) { const auto updated = ComputeProgress(_data, now); - if (std::round(_progressTillExpire * 360) != std::round(updated * 360)) { + if (base::SafeRound(_progressTillExpire * 360) + != base::SafeRound(updated * 360)) { _progressTillExpire = updated; const auto color = ComputeColor(_data, _progressTillExpire); if (_color != color) { @@ -291,7 +292,8 @@ crl::time Row::updateExpireIn() const { if (_data.expireDate <= start) { return 0; } - return std::round((_data.expireDate - start) * crl::time(1000) / 720.); + return base::SafeRound( + (_data.expireDate - start) * crl::time(1000) / 720.); } QString Row::generateName() { diff --git a/Telegram/SourceFiles/calls/calls_video_bubble.cpp b/Telegram/SourceFiles/calls/calls_video_bubble.cpp index ff25f5b93..7432f7557 100644 --- a/Telegram/SourceFiles/calls/calls_video_bubble.cpp +++ b/Telegram/SourceFiles/calls/calls_video_bubble.cpp @@ -209,7 +209,7 @@ void VideoBubble::updateSizeToFrame(QSize frame) { size = frame.scaled((_min + _max) / 2, Qt::KeepAspectRatio); } else { const auto area = size.width() * size.height(); - const auto w = int(std::round(std::max( + const auto w = int(base::SafeRound(std::max( std::sqrt((frame.width() * float64(area)) / (frame.height() * 1.)), 1.))); const auto h = area / w; diff --git a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp index 22e1d21d9..a2d67fa9d 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp @@ -57,7 +57,7 @@ auto RowBlobs() -> std::array { } [[nodiscard]] QString StatusPercentString(float volume) { - return QString::number(int(std::round(volume * 200))) + '%'; + return QString::number(int(base::SafeRound(volume * 200))) + '%'; } [[nodiscard]] int StatusPercentWidth(const QString &percent) { @@ -492,7 +492,7 @@ int MembersRow::statusIconWidth(bool skipIcon) const { const auto full = iconWidth + _statusIcon->percentWidth + st::normalFont->spacew; - return int(std::round(shown * full)); + return int(base::SafeRound(shown * full)); } int MembersRow::statusIconHeight() const { diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp b/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp index e8f9cad8b..ea1849b1d 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport.cpp @@ -461,15 +461,15 @@ Viewport::Layout Viewport::countWide(int outerWidth, int outerHeight) const { const auto columns = slices; const auto sizew = (outerWidth + skip) / float64(columns); for (auto column = 0; column != columns; ++column) { - const auto left = int(std::round(column * sizew)); - const auto width = int(std::round(column * sizew + sizew - skip)) - - left; - const auto rows = int(std::round((count - index) + const auto left = int(base::SafeRound(column * sizew)); + const auto width = int( + base::SafeRound(column * sizew + sizew - skip)) - left; + const auto rows = int(base::SafeRound((count - index) / float64(columns - column))); const auto sizeh = (outerHeight + skip) / float64(rows); for (auto row = 0; row != rows; ++row) { - const auto top = int(std::round(row * sizeh)); - const auto height = int(std::round( + const auto top = int(base::SafeRound(row * sizeh)); + const auto height = int(base::SafeRound( row * sizeh + sizeh - skip)) - top; auto &geometry = sizes[index]; geometry.columns = { @@ -493,15 +493,15 @@ Viewport::Layout Viewport::countWide(int outerWidth, int outerHeight) const { const auto rows = slices; const auto sizeh = (outerHeight + skip) / float64(rows); for (auto row = 0; row != rows; ++row) { - const auto top = int(std::round(row * sizeh)); - const auto height = int(std::round(row * sizeh + sizeh - skip)) - - top; - const auto columns = int(std::round((count - index) + const auto top = int(base::SafeRound(row * sizeh)); + const auto height = int( + base::SafeRound(row * sizeh + sizeh - skip)) - top; + const auto columns = int(base::SafeRound((count - index) / float64(rows - row))); const auto sizew = (outerWidth + skip) / float64(columns); for (auto column = 0; column != columns; ++column) { - const auto left = int(std::round(column * sizew)); - const auto width = int(std::round( + const auto left = int(base::SafeRound(column * sizew)); + const auto width = int(base::SafeRound( column * sizew + sizew - skip)) - left; auto &geometry = sizes[index]; geometry.rows = { diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp index 54024aa44..a33e2f0f2 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp @@ -242,7 +242,7 @@ vec4 background() { QSize outer, float factor) { factor *= kBlurTextureSizeFactor; - const auto area = outer / int(std::round(factor * cScale() / 100)); + const auto area = outer / int(base::SafeRound(factor * cScale() / 100)); const auto scaled = unscaled.scaled(area, Qt::KeepAspectRatio); return (scaled.width() > unscaled.width() || scaled.height() > unscaled.height()) diff --git a/Telegram/SourceFiles/calls/group/calls_volume_item.cpp b/Telegram/SourceFiles/calls/group/calls_volume_item.cpp index d143a66a6..1bf505de5 100644 --- a/Telegram/SourceFiles/calls/group/calls_volume_item.cpp +++ b/Telegram/SourceFiles/calls/group/calls_volume_item.cpp @@ -92,7 +92,7 @@ MenuVolumeItem::MenuVolumeItem( const auto volume = _localMuted ? 0 - : std::round(_slider->value() * kMaxVolumePercent); + : base::SafeRound(_slider->value() * kMaxVolumePercent); const auto muteProgress = _crossLineAnimation.value((!volume) ? 1. : 0.); @@ -140,7 +140,7 @@ MenuVolumeItem::MenuVolumeItem( }; _slider->setChangeFinishedCallback([=](float64 value) { - const auto newVolume = std::round(value * _maxVolume); + const auto newVolume = base::SafeRound(value * _maxVolume); const auto muted = (value == 0); if (!_cloudMuted && muted) { @@ -175,7 +175,7 @@ MenuVolumeItem::MenuVolumeItem( } if (_waitingForUpdateVolume) { const auto localVolume = - std::round(_slider->value() * _maxVolume); + base::SafeRound(_slider->value() * _maxVolume); if ((localVolume != newVolume) && (_cloudVolume == newVolume)) { _changeVolumeRequests.fire(int(localVolume)); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_interactions.cpp b/Telegram/SourceFiles/chat_helpers/emoji_interactions.cpp index 907dfff7d..fa579ac6b 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_interactions.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_interactions.cpp @@ -186,7 +186,7 @@ void EmojiInteractions::startIncoming( } const auto now = crl::now(); for (const auto &single : bunch.interactions) { - const auto at = now + crl::time(std::round(single.time * 1000)); + const auto at = now + crl::time(base::SafeRound(single.time * 1000)); if (!animations.empty() && animations.back().scheduledAt >= at) { continue; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_image_loader.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_image_loader.cpp index 9829009fa..08a12fc7d 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_image_loader.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_image_loader.cpp @@ -68,7 +68,7 @@ QImage EmojiImageLoader::prepare(EmojiPtr emoji) const { { -1, 1 }, { 1, 1 }, } }; - const auto corrected = int(std::round(delta / sqrt(2.))); + const auto corrected = int(base::SafeRound(delta / sqrt(2.))); for (const auto &shift : diagonal) { for (auto i = 0; i != corrected; ++i) { p.drawImage(QPoint(delta, delta) + shift * (i + 1), tinted); diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index ad3e3a89f..f8a26f04d 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -617,7 +617,7 @@ public: [[nodiscard]] static bool ThirdColumnByDefault(); [[nodiscard]] static float64 DefaultDialogsWidthRatio(); [[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) { - return int(std::round(std::clamp(speed, 0.5, 2.0) * 100)); + return int(base::SafeRound(std::clamp(speed, 0.5, 2.0) * 100)); } [[nodiscard]] static float64 DeserializePlaybackSpeed(qint32 speed) { if (speed < 10) { diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index a43979dcd..645ccba1a 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -586,7 +586,7 @@ bool ParseCommonMap( } return string.toULongLong(); } else if ((*version).isDouble()) { - return uint64(std::round((*version).toDouble())); + return uint64(base::SafeRound((*version).toDouble())); } return 0ULL; }(); diff --git a/Telegram/SourceFiles/data/data_types.cpp b/Telegram/SourceFiles/data/data_types.cpp index 10c1debc6..7060ed334 100644 --- a/Telegram/SourceFiles/data/data_types.cpp +++ b/Telegram/SourceFiles/data/data_types.cpp @@ -80,8 +80,9 @@ Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location) { | (uint32(location.height) & 0xFFFFU); return Storage::Cache::Key{ Data::kGeoPointCacheTag | (uint64(zoomscale) << 32) | widthheight, - (uint64(std::round(std::abs(location.lat + 360.) * 1000000)) << 32) - | uint64(std::round(std::abs(location.lon + 360.) * 1000000)) + (uint64(base::SafeRound( + std::abs(location.lat + 360.) * 1000000)) << 32) + | uint64(base::SafeRound(std::abs(location.lon + 360.) * 1000000)) }; } diff --git a/Telegram/SourceFiles/editor/scene/scene_item_base.cpp b/Telegram/SourceFiles/editor/scene/scene_item_base.cpp index 0aaac899b..0e7484ea5 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_base.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_base.cpp @@ -150,7 +150,7 @@ void ItemBase::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { const auto angle = Normalized((isLeft ? 180 : 0) + (std::atan2(diff.y(), diff.x()) * 180 / M_PI)); setRotation(shift - ? (std::round(angle / kSnapAngle) * kSnapAngle) // Snap rotation. + ? (base::SafeRound(angle / kSnapAngle) * kSnapAngle) : angle); } else { QGraphicsItem::mouseMoveEvent(event); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index bfc6b2255..b6479f9d2 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -130,7 +130,7 @@ void PaintWaveform( const auto samplesCount = wf ? wf->size() : ::Media::Player::kWaveformSamplesCount; - const auto activeWidth = std::round(availableWidth * progress); + const auto activeWidth = base::SafeRound(availableWidth * progress); const auto &barWidth = st::historyRecordWaveformBar; const auto barFullWidth = barWidth + st::msgWaveformSkip; @@ -774,7 +774,7 @@ void RecordLock::drawProgress(Painter &p) { _lockToStopProgress); const auto blockRectTop = anim::interpolateF( size.height() - blockHeight, - std::round((size.height() - blockRectHeight) / 2.), + base::SafeRound((size.height() - blockRectHeight) / 2.), _lockToStopProgress); const auto blockRect = QRectF( diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index dc07d0849..399e1258c 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -477,7 +477,8 @@ void ListWidget::scrollToAnimationCallback( int relativeTo) { if (!attachToId) { // Animated scroll to bottom. - const auto current = int(std::round(_scrollToAnimation.value(0))); + const auto current = int(base::SafeRound( + _scrollToAnimation.value(0))); _delegate->listScrollTo(height() - (_visibleBottom - _visibleTop) + current); @@ -488,7 +489,7 @@ void ListWidget::scrollToAnimationCallback( if (!attachToView) { _scrollToAnimation.stop(); } else { - const auto current = int(std::round(_scrollToAnimation.value( + const auto current = int(base::SafeRound(_scrollToAnimation.value( relativeTo))); _delegate->listScrollTo(itemTop(attachToView) + current); } diff --git a/Telegram/SourceFiles/history/view/history_view_send_action.cpp b/Telegram/SourceFiles/history/view/history_view_send_action.cpp index a6948a07e..16e3a54da 100644 --- a/Telegram/SourceFiles/history/view/history_view_send_action.cpp +++ b/Telegram/SourceFiles/history/view/history_view_send_action.cpp @@ -308,7 +308,7 @@ bool SendActionPainter::updateNeedsAnimating(crl::time now, bool force) { // We have to use QFontMetricsF instead of // FontData::spacew for more precise calculation. const auto mf = QFontMetricsF(_st.font->f); - _spacesCount = std::round( + _spacesCount = base::SafeRound( _sendActionAnimation.widthNoMargins() / mf.horizontalAdvance(' ')); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 4226c72f0..c5cfc8b97 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -91,7 +91,7 @@ void PaintWaveform( const auto wfSize = wf ? wf->size() : ::Media::Player::kWaveformSamplesCount; - const auto activeWidth = std::round(availableWidth * progress); + const auto activeWidth = base::SafeRound(availableWidth * progress); const auto &barWidth = st::msgWaveformBar; const auto barCount = std::min( @@ -526,7 +526,7 @@ void Document::draw( }(); if (voice->seeking()) { voiceStatusOverride = Ui::FormatPlayedText( - std::round(progress * voice->_lastDurationMs) / 1000, + base::SafeRound(progress * voice->_lastDurationMs) / 1000, voice->_lastDurationMs / 1000); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index b9498e6a8..0d9e11984 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -182,7 +182,7 @@ QSize GroupedMedia::countCurrentSize(int newWidth) { const auto initialSpacing = st::historyGroupSkip; const auto factor = newWidth / float64(maxWidth()); const auto scale = [&](int value) { - return int(std::round(value * factor)); + return int(base::SafeRound(value * factor)); }; const auto spacing = scale(initialSpacing); for (auto &part : _parts) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 6c635a81c..917416b13 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -963,7 +963,7 @@ void Poll::paintCloseByTimer( const auto part = std::max( left / float64(radial), 1. / FullArcLength); - const auto length = int(std::round(FullArcLength * part)); + const auto length = int(base::SafeRound(FullArcLength * part)); auto pen = regular->p; pen.setWidth(st::historyPollRadio.thickness); pen.setCapStyle(Qt::RoundCap); @@ -1050,7 +1050,7 @@ int Poll::paintAnswer( } if (opacity > 0.) { const auto percent = QString::number( - int(std::round(animation->percent.current()))) + '%'; + int(base::SafeRound(animation->percent.current()))) + '%'; const auto percentWidth = st::historyPollPercentFont->width( percent); p.setOpacity(opacity); diff --git a/Telegram/SourceFiles/media/audio/media_audio.cpp b/Telegram/SourceFiles/media/audio/media_audio.cpp index ef34eb3c0..fa9ac0ddb 100644 --- a/Telegram/SourceFiles/media/audio/media_audio.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio.cpp @@ -49,7 +49,7 @@ int CoarseTuneForSpeed(float64 speed) { constexpr auto kTuneSteps = 12; const auto tuneRatio = std::log(speed) / std::log(2.); - return -int(std::round(kTuneSteps * tuneRatio)); + return -int(base::SafeRound(kTuneSteps * tuneRatio)); } } // namespace diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index b26c32092..954618ce4 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -654,7 +654,7 @@ void Instance::finishSeeking(AudioMsgId::Type type, float64 progress) { const auto &info = streamed->instance.info(); const auto duration = info.audio.state.duration; if (duration != kTimeUnknown) { - const auto position = crl::time(std::round( + const auto position = crl::time(base::SafeRound( std::clamp(progress, 0., 1.) * duration)); streamed->instance.play(streamingOptions( streamed->id, diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp index 07a9fe5f5..ee1da69a1 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_video_track.cpp @@ -12,8 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/concurrent_timer.h" #include "core/crash_reports.h" -#include - namespace Media { namespace Streaming { namespace { @@ -71,31 +69,6 @@ static_assert(kDisplaySkipped != kTimeUnknown); return result; } -[[nodiscard]] float64 SafeRound(float64 value) { - Expects(!std::isnan(value)); - - if (const auto result = std::round(value); !std::isnan(result)) { - return result; - } - const auto errors = std::fetestexcept(FE_ALL_EXCEPT); - if (const auto result = std::round(value); !std::isnan(result)) { - return result; - } - LOG(("Streaming Error: Got second NAN in std::round(%1), fe: %2." - ).arg(value - ).arg(errors)); - std::feclearexcept(FE_ALL_EXCEPT); - if (const auto result = std::round(value); !std::isnan(result)) { - return result; - } - CrashReports::SetAnnotation("FE-Error-Value", QString::number(value)); - CrashReports::SetAnnotation("FE-Errors-Were", QString::number(errors)); - CrashReports::SetAnnotation( - "FE-Errors-Now", - QString::number(std::fetestexcept(FE_ALL_EXCEPT))); - Unexpected("NAN after third std::round."); -} - } // namespace class VideoTrackObject final { @@ -713,7 +686,7 @@ TimePoint VideoTrackObject::trackTime() const { } const auto adjust = (result.worldTime - _syncTimePoint.worldTime); const auto adjustSpeed = adjust * _options.speed; - const auto roundAdjustSpeed = SafeRound(adjustSpeed); + const auto roundAdjustSpeed = base::SafeRound(adjustSpeed); const auto timeRoundAdjustSpeed = crl::time(roundAdjustSpeed); result.trackTime = _syncTimePoint.trackTime + timeRoundAdjustSpeed; return result; @@ -848,7 +821,7 @@ auto VideoTrack::Shared::presentFrame( } const auto trackLeft = position - time.trackTime; const auto adjustedBySpeed = trackLeft / playbackSpeed; - const auto roundedAdjustedBySpeed = SafeRound(adjustedBySpeed); + const auto roundedAdjustedBySpeed = base::SafeRound(adjustedBySpeed); frame->display = time.worldTime + addedWorldTimeDelay + crl::time(roundedAdjustedBySpeed); diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 1ed1da330..e84bf87d0 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -32,7 +32,7 @@ namespace { constexpr auto kThumbDuration = crl::time(150); int Round(float64 value) { - return int(std::round(value)); + return int(base::SafeRound(value)); } using Context = GroupThumbs::Context; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp index 29cbe950a..4055b0f9b 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp @@ -441,7 +441,7 @@ void OverlayWidget::RendererGL::paintControl( Assert(meta.icon == &icon); const auto &bg = st::mediaviewControlBg->c; - const auto bgAlpha = int(std::round(bg.alpha() * outerOpacity)); + const auto bgAlpha = int(base::SafeRound(bg.alpha() * outerOpacity)); const auto offset = kControlsOffset + (meta.index * kControlValues) / 4; const auto fgOffset = offset + 2; const auto bgRect = transformRect(outer); diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index abe40cfb3..1be7250a1 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -1396,7 +1396,7 @@ void Pip::paintProgressBar( float64 progress, int radius, float64 active) const { - const auto done = int(std::round(rect.width() * progress)); + const auto done = int(base::SafeRound(rect.width() * progress)); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); if (done > 0) { diff --git a/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp b/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp index d2f0006d4..813b159ad 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp @@ -485,9 +485,9 @@ void Pip::RendererGL::paintRadialLoading( const auto fadeAlpha = controlsShown * fade.alphaF(); const auto fgAlpha = 1. - fadeAlpha; const auto color = (fadeAlpha == 0.) ? fg : QColor( - int(std::round(fg.red() * fgAlpha + fade.red() * fadeAlpha)), - int(std::round(fg.green() * fgAlpha + fade.green() * fadeAlpha)), - int(std::round(fg.blue() * fgAlpha + fade.blue() * fadeAlpha)), + int(base::SafeRound(fg.red() * fgAlpha + fade.red() * fadeAlpha)), + int(base::SafeRound(fg.green() * fgAlpha + fade.green() * fadeAlpha)), + int(base::SafeRound(fg.blue() * fgAlpha + fade.blue() * fadeAlpha)), fg.alpha()); _owner->paintRadialLoadingContent(p, newInner, color); diff --git a/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp b/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp index 0a7acd0ea..1aab2ae2a 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp +++ b/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp @@ -102,7 +102,7 @@ MenuSpeedItem::MenuSpeedItem( enableMouseSelecting(_slider.get()); _slider->setAlwaysDisplayMarker(true); - _slider->setValue((std::round(startSpeed * 100.) - kMinSpeed) + _slider->setValue((base::SafeRound(startSpeed * 100.) - kMinSpeed) / (kMaxSpeed - kMinSpeed)); for (const auto &sticked : kSpeedStickedValues) { @@ -438,7 +438,7 @@ void PlaybackControls::setLoadingProgress(int ready, int total) { _loadingPercent = -1; } const auto progress = total ? (ready / float64(total)) : 0.; - const auto percent = int(std::round(progress * 100)); + const auto percent = int(base::SafeRound(progress * 100)); if (_loadingPercent != percent) { _loadingPercent = percent; _downloadProgress->setText(QString::number(percent) + '%'); diff --git a/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp b/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp index 7318d5a39..7f62e04ee 100644 --- a/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp +++ b/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp @@ -114,7 +114,7 @@ std::vector ParseDnsResponse( const auto object = elem.toObject(); if (typeRestriction) { const auto typeIt = object.find("type"); - const auto type = int(std::round((*typeIt).toDouble())); + const auto type = int(base::SafeRound((*typeIt).toDouble())); if (!(*typeIt).isDouble()) { LOG(("Config Error: Not a number in type field " "in Answer array in dns response JSON.")); @@ -136,7 +136,7 @@ std::vector ParseDnsResponse( const auto ttlIt = object.find("TTL"); const auto ttl = (ttlIt != object.constEnd()) - ? crl::time(std::round((*ttlIt).toDouble())) + ? crl::time(base::SafeRound((*ttlIt).toDouble())) : crl::time(0); result.push_back({ (*dataIt).toString(), ttl }); } diff --git a/Telegram/SourceFiles/mtproto/session_private.cpp b/Telegram/SourceFiles/mtproto/session_private.cpp index 4abd57a15..7b64e62e9 100644 --- a/Telegram/SourceFiles/mtproto/session_private.cpp +++ b/Telegram/SourceFiles/mtproto/session_private.cpp @@ -544,7 +544,9 @@ MTPVector SessionPrivate::prepareInitParams() { sliced -= 24 * 3600; } const auto sign = (sliced < 0) ? -1 : 1; - const auto rounded = std::round(std::abs(sliced) / 900.) * 900 * sign; + const auto rounded = base::SafeRound(std::abs(sliced) / 900.) + * 900 + * sign; return MTP_vector( 1, MTP_jsonObjectValue( diff --git a/Telegram/SourceFiles/payments/ui/payments_field.cpp b/Telegram/SourceFiles/payments/ui/payments_field.cpp index 2d95cbe3c..12309984a 100644 --- a/Telegram/SourceFiles/payments/ui/payments_field.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_field.cpp @@ -229,7 +229,7 @@ struct SimpleFieldState { QString() ).toDouble(); return QString::number( - int64(std::round(real * std::pow(10., rule.exponent)))); + int64(base::SafeRound(real * std::pow(10., rule.exponent)))); } else if (config.type == FieldType::CardNumber || config.type == FieldType::CardCVC) { return QString(parsed).replace( diff --git a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp index b98d2e068..d152e5cb2 100644 --- a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp @@ -452,8 +452,12 @@ void FormSummary::setupSuggestedTips(not_null layout) { for (auto i = 0; i != count; ++i) { const auto button = buttons[rowStart + i].widget; auto right = x + buttonWidths[i]; - button->setFullWidth(int(std::round(right) - std::round(x))); - button->moveToLeft(int(std::round(x)), height, outerWidth); + button->setFullWidth( + int(base::SafeRound(right) - base::SafeRound(x))); + button->moveToLeft( + int(base::SafeRound(x)), + height, + outerWidth); x = right + skip; } height += buttons[0].widget->height() + skip; diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm index ff4f65c7e..65ee77095 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm @@ -240,7 +240,8 @@ TimeId CalculateOnlineTill(not_null peer) { : indexOf(peer); const auto &entry = _pins[index]; entry->shift = entry->deltaShift - + std::round(entry->shiftAnimation.value(entry->finalShift)); + + base::SafeRound( + entry->shiftAnimation.value(entry->finalShift)); if (entry->deltaShift && !entry->shiftAnimation.animating()) { entry->finalShift += entry->deltaShift; entry->deltaShift = 0; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 16b8a1a8b..9f3389165 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -362,7 +362,7 @@ void ColorsPalette::updateInnerGeometry() { const auto y = st::settingsSectionSkip * 2; auto x = float64(padding.left()); for (const auto &button : _buttons) { - button->moveToLeft(int(std::round(x)), y); + button->moveToLeft(int(base::SafeRound(x)), y); x += size + skip; } inner->resize(inner->width(), y + size); @@ -1159,7 +1159,7 @@ void SetupDefaultThemes( auto left = padding.left() + 0.; for (const auto button : buttons) { button->resizeToWidth(single); - button->moveToLeft(int(std::round(left)), 0); + button->moveToLeft(int(base::SafeRound(left)), 0); left += button->width() + skip; } }, block->lifetime()); diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index b6fea9132..1538875a8 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -64,11 +64,11 @@ PreparedFileThumbnail PrepareFileThumbnail(QImage &&original) { const auto scaledWidth = [&] { return (width > height) ? kThumbnailSize - : int(std::round(kThumbnailSize * width / float64(height))); + : int(base::SafeRound(kThumbnailSize * width / float64(height))); }; const auto scaledHeight = [&] { return (width > height) - ? int(std::round(kThumbnailSize * height / float64(width))) + ? int(base::SafeRound(kThumbnailSize * height / float64(width))) : kThumbnailSize; }; result.image = scaled diff --git a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp index f7e9c6bf9..c6de00931 100644 --- a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp +++ b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp @@ -85,7 +85,7 @@ QString StateDescription(const BlobState &state, tr::phrase<> activeText) { return tr::lng_emoji_set_loading( tr::now, lt_percent, - QString::number(int(std::round(percent))) + '%', + QString::number(int(base::SafeRound(percent))) + '%', lt_progress, Ui::FormatDownloadText(data.already, data.size)); }, [](const Failed &data) { diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index 8fa41cfac..226dccd95 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -329,6 +329,10 @@ void UpdateImageDetails(PreparedFile &file, int previewWidth) { : image->data; Assert(!preview.isNull()); file.shownDimensions = PrepareShownDimensions(preview); + const auto scaledWidth = style::ConvertScale(preview.width()); + constexpr auto kIntMin = std::numeric_limits::min(); + static_assert(kIntMin == -2147483648); + scaledWidth; const auto toWidth = std::min( previewWidth, style::ConvertScale(preview.width()) diff --git a/Telegram/SourceFiles/ui/boxes/auto_delete_settings.cpp b/Telegram/SourceFiles/ui/boxes/auto_delete_settings.cpp index 9cd9975ef..0818a1dee 100644 --- a/Telegram/SourceFiles/ui/boxes/auto_delete_settings.cpp +++ b/Telegram/SourceFiles/ui/boxes/auto_delete_settings.cpp @@ -128,7 +128,7 @@ object_ptr CreateSliderForTTL( // Try to fill the line with exact number of dash segments. // UPD Doesn't work so well because it changes when clicking. //const auto length = till - from; - //const auto offSegmentsCount = int(std::round( + //const auto offSegmentsCount = int(base::SafeRound( // (length - st->dashOn) / (st->dashOn + st->dashOff))); //const auto onSegmentsCount = offSegmentsCount + 1; //const auto idealLength = offSegmentsCount * st->dashOff diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp index abd383c4c..a9bbcdf9c 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_preview.cpp @@ -263,7 +263,7 @@ void AlbumPreview::updateSize() { } else if (!_sendWay.groupFiles()) { return _photosHeight; } else { - return int(std::round(_thumbsHeightAnimation.value( + return int(base::SafeRound(_thumbsHeightAnimation.value( _thumbsHeight))); } }(); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp index b4e2d8a23..ab26971fb 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_album_thumbnail.cpp @@ -270,7 +270,7 @@ void AlbumThumbnail::drawSimpleFrame(Painter &p, QRect to, QSize size) const { const auto scaleWidth = to.width() / float64(width); const auto scaleHeight = to.height() / float64(height); const auto Round = [](float64 value) { - return int(std::round(value)); + return int(base::SafeRound(value)); }; const auto [from, fillBlack] = [&] { if (previewWidth < width && previewHeight < height) { @@ -474,7 +474,7 @@ void AlbumThumbnail::suggestMove(float64 delta, Fn callback) { } QRect AlbumThumbnail::countRealGeometry() const { - const auto addLeft = int(std::round( + const auto addLeft = int(base::SafeRound( _suggestedMoveAnimation.value(_suggestedMove) * _lastShrinkValue)); const auto current = _layout.geometry; const auto realTopLeft = current.topLeft() diff --git a/Telegram/SourceFiles/ui/chat/group_call_bar.cpp b/Telegram/SourceFiles/ui/chat/group_call_bar.cpp index 6507cee17..8ad33c772 100644 --- a/Telegram/SourceFiles/ui/chat/group_call_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/group_call_bar.cpp @@ -63,7 +63,7 @@ rpl::producer GroupCallScheduledLeft::late() const { void GroupCallScheduledLeft::update() { const auto now = crl::now(); const auto duration = (_datePrecise - now); - const auto left = crl::time(std::round(std::abs(duration) / 1000.)); + const auto left = crl::time(base::SafeRound(std::abs(duration) / 1000.)); const auto late = (duration < 0) && (left > 0); _late = late; constexpr auto kDay = 24 * 60 * 60; diff --git a/Telegram/SourceFiles/ui/controls/call_mute_button.cpp b/Telegram/SourceFiles/ui/controls/call_mute_button.cpp index da66edf26..9084f0faa 100644 --- a/Telegram/SourceFiles/ui/controls/call_mute_button.cpp +++ b/Telegram/SourceFiles/ui/controls/call_mute_button.cpp @@ -1002,7 +1002,7 @@ void CallMuteButton::shake() { ? -1. : 0.; const auto shift = from * (1. - part) + to * part; - _labelShakeShift = int(std::round(shift * st::shakeShift)); + _labelShakeShift = int(base::SafeRound(shift * st::shakeShift)); updateLabelsGeometry(); }; _shakeAnimation.start( diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index e0536010f..b13b31e5c 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -176,7 +176,7 @@ QPixmap CheckCaches::frame( auto &frames = framesForStyle(st, displayInactive); const auto frameCount = int(frames.list.size()); - const auto frameIndex = int(std::round(progress * (frameCount - 1))); + const auto frameIndex = int(base::SafeRound(progress * (frameCount - 1))); Assert(frameIndex >= 0 && frameIndex < frameCount); if (!frames.list[frameIndex]) { diff --git a/Telegram/SourceFiles/ui/empty_userpic.cpp b/Telegram/SourceFiles/ui/empty_userpic.cpp index b24995036..09526b34e 100644 --- a/Telegram/SourceFiles/ui/empty_userpic.cpp +++ b/Telegram/SourceFiles/ui/empty_userpic.cpp @@ -44,11 +44,11 @@ void PaintSavedMessagesInner( // X XX XX X | | // XX XX --- --- - const auto thinkness = std::round(size * 0.055); + const auto thinkness = base::SafeRound(size * 0.055); const auto increment = int(thinkness) % 2 + (size % 2); - const auto width = std::round(size * 0.15) * 2 + increment; - const auto height = std::round(size * 0.19) * 2 + increment; - const auto add = std::round(size * 0.064); + const auto width = base::SafeRound(size * 0.15) * 2 + increment; + const auto height = base::SafeRound(size * 0.19) * 2 + increment; + const auto add = base::SafeRound(size * 0.064); const auto left = x + (size - width) / 2; const auto top = y + (size - height) / 2; diff --git a/Telegram/SourceFiles/ui/grouped_layout.cpp b/Telegram/SourceFiles/ui/grouped_layout.cpp index 0290f7bbe..004d7728d 100644 --- a/Telegram/SourceFiles/ui/grouped_layout.cpp +++ b/Telegram/SourceFiles/ui/grouped_layout.cpp @@ -11,7 +11,7 @@ namespace Ui { namespace { int Round(float64 value) { - return int(std::round(value)); + return int(base::SafeRound(value)); } class Layouter { diff --git a/Telegram/SourceFiles/ui/image/image_location.cpp b/Telegram/SourceFiles/ui/image/image_location.cpp index f95f8c554..3049c00d0 100644 --- a/Telegram/SourceFiles/ui/image/image_location.cpp +++ b/Telegram/SourceFiles/ui/image/image_location.cpp @@ -694,8 +694,9 @@ InMemoryKey inMemoryKey(const WebFileLocation &location) { InMemoryKey inMemoryKey(const GeoPointLocation &location) { return InMemoryKey( - (uint64(std::round(std::abs(location.lat + 360.) * 1000000)) << 32) - | uint64(std::round(std::abs(location.lon + 360.) * 1000000)), + (uint64(base::SafeRound( + std::abs(location.lat + 360.) * 1000000)) << 32) + | uint64(base::SafeRound(std::abs(location.lon + 360.) * 1000000)), (uint64(location.width) << 32) | uint64(location.height)); } diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp index 13cd8efd2..a9ae6e93b 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp @@ -329,7 +329,7 @@ void MediaSlider::paintEvent(QPaintEvent *e) { const auto dividerValue = horizontal ? divider.atValue : (1. - divider.atValue); - const auto dividerMid = std::round(from + const auto dividerMid = base::SafeRound(from + dividerValue * length); const auto &size = divider.size; const auto rect = horizontal diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h index 44d775dbd..8b03e4a8e 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h @@ -167,14 +167,14 @@ public: } } setAdjustCallback([=](float64 value) { - return std::round(value * sectionsCount) / sectionsCount; + return base::SafeRound(value * sectionsCount) / sectionsCount; }); setChangeProgressCallback([ =, convert = std::forward(convert), callback = std::forward(callback) ](float64 value) { - const auto index = int(std::round(value * sectionsCount)); + const auto index = int(base::SafeRound(value * sectionsCount)); callback(convert(index)); }); } diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 9736fd05f..8379c8f48 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -723,7 +723,7 @@ int CloudList::resizeGetHeight(int newWidth) { for (const auto &element : _elements) { const auto button = element.button.get(); button->resizeToWidth(single); - button->moveToLeft(int(std::round(x)), y); + button->moveToLeft(int(base::SafeRound(x)), y); accumulate_max(rowHeight, button->height()); x += single + skip; if (++index == kShowPerRow) { diff --git a/Telegram/lib_base b/Telegram/lib_base index c42df26ff..4e5c7cd97 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit c42df26ff4a2359d996ceadbc84fd798b1b116fb +Subproject commit 4e5c7cd97a7bab5007e5ff050829aaa8b0688313 diff --git a/Telegram/lib_lottie b/Telegram/lib_lottie index d134c0361..33427eb49 160000 --- a/Telegram/lib_lottie +++ b/Telegram/lib_lottie @@ -1 +1 @@ -Subproject commit d134c0361ef96b5061c2719a0e984eaaed2c1a81 +Subproject commit 33427eb49c0b9a22651956df3290ec06d436742d diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 29cfdad44..e62d92f65 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 29cfdad44c22cb653fe756e4e1fba0f172fb3ca7 +Subproject commit e62d92f655a60b507bada9e387fb48aae89a5e72 diff --git a/Telegram/lib_webrtc b/Telegram/lib_webrtc index 29d513179..861948683 160000 --- a/Telegram/lib_webrtc +++ b/Telegram/lib_webrtc @@ -1 +1 @@ -Subproject commit 29d51317915ca43db45d436cba8eac3f40dea36b +Subproject commit 86194868334e3b51bc6300176d935c2beb84e37d