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: |

One thing that Telegram now offers to all users is the ability to “disappear” messages or set remote deletion deadlines. That enables users to have much more control over how long people can access what you’re sending them. Given that Russian law enforcement officials are reportedly (via Insider) stopping people in the street and demanding to read their text messages, this could be vital to protect individuals from reprisals. Despite Telegram's origins, its approach to users' security has privacy advocates worried. The Securities and Exchange Board of India (Sebi) had carried out a similar exercise in 2017 in a matter related to circulation of messages through WhatsApp. 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. 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.
from in


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