Telegram Group & Telegram Channel
Наткнулся на видос, где рассказывают, какие неочевидные проблемы могут возникнуть при поиске среднего двух чисел:

https://www.youtube.com/watch?v=sBtAGxBh-XI

Удивительно, что доклад на такую, казалось бы, простую тему может длиться час. Но там действительно огромное поле для ошибок.

При написании алгоритма поиска среднего велик соблазн сделать просто return (a + b) / 2, однако такая реализация может переполниться и привести к неопределенному поведению.

Ровно из-за такой ошибки в Java 9 лет некорректно работал бинпоиск. Аналогичная проблема была и в имплементации JS от Mozilla.

Помимо переполнения есть еще другие сложности: integer promotion при работе с short, зависящий от имплементации знак у char. Ловушки в специализации шаблонов. А кроме целых типов ведь есть еще флоты и указатели, с которыми тоже приколов хватает.

Если лень смотреть, то есть документ с описанием имплементации std::midpoint, на основе которого и был сделан доклад (тут не все, но все равно есть, что почитать):
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html

Также можно глянуть итоговую имплементацию std::midpoint:
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__numeric/midpoint.h



group-telegram.com/misha_writes_code/195
Create:
Last Update:

Наткнулся на видос, где рассказывают, какие неочевидные проблемы могут возникнуть при поиске среднего двух чисел:

https://www.youtube.com/watch?v=sBtAGxBh-XI

Удивительно, что доклад на такую, казалось бы, простую тему может длиться час. Но там действительно огромное поле для ошибок.

При написании алгоритма поиска среднего велик соблазн сделать просто return (a + b) / 2, однако такая реализация может переполниться и привести к неопределенному поведению.

Ровно из-за такой ошибки в Java 9 лет некорректно работал бинпоиск. Аналогичная проблема была и в имплементации JS от Mozilla.

Помимо переполнения есть еще другие сложности: integer promotion при работе с short, зависящий от имплементации знак у char. Ловушки в специализации шаблонов. А кроме целых типов ведь есть еще флоты и указатели, с которыми тоже приколов хватает.

Если лень смотреть, то есть документ с описанием имплементации std::midpoint, на основе которого и был сделан доклад (тут не все, но все равно есть, что почитать):
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0811r3.html

Также можно глянуть итоговую имплементацию std::midpoint:
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__numeric/midpoint.h

BY Миша пишет код




Share with your friend now:
group-telegram.com/misha_writes_code/195

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Stocks dropped on Friday afternoon, as gains made earlier in the day on hopes for diplomatic progress between Russia and Ukraine turned to losses. Technology stocks were hit particularly hard by higher bond yields. The regulator said it had received information that messages containing stock tips and other investment advice with respect to selected listed companies are being widely circulated through websites and social media platforms such as Telegram, Facebook, WhatsApp and Instagram. What distinguishes the app from competitors is its use of what's known as channels: Public or private feeds of photos and videos that can be set up by one person or an organization. The channels have become popular with on-the-ground journalists, aid workers and Ukrainian President Volodymyr Zelenskyy, who broadcasts on a Telegram channel. The channels can be followed by an unlimited number of people. Unlike Facebook, Twitter and other popular social networks, there is no advertising on Telegram and the flow of information is not driven by an algorithm. This ability to mix the public and the private, as well as the ability to use bots to engage with users has proved to be problematic. In early 2021, a database selling phone numbers pulled from Facebook was selling numbers for $20 per lookup. Similarly, security researchers found a network of deepfake bots on the platform that were generating images of people submitted by users to create non-consensual imagery, some of which involved children. At this point, however, Durov had already been working on Telegram with his brother, and further planned a mobile-first social network with an explicit focus on anti-censorship. Later in April, he told TechCrunch that he had left Russia and had “no plans to go back,” saying that the nation was currently “incompatible with internet business at the moment.” He added later that he was looking for a country that matched his libertarian ideals to base his next startup.
from ms


Telegram Миша пишет код
FROM American