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

Groups are also not fully encrypted, end-to-end. This includes private groups. Private groups cannot be seen by other Telegram users, but Telegram itself can see the groups and all of the communications that you have in them. All of the same risks and warnings about channels can be applied to groups. The news also helped traders look past another report showing decades-high inflation and shake off some of the volatility from recent sessions. The Bureau of Labor Statistics' February Consumer Price Index (CPI) this week showed another surge in prices even before Russia escalated its attacks in Ukraine. The headline CPI — soaring 7.9% over last year — underscored the sticky inflationary pressures reverberating across the U.S. economy, with everything from groceries to rents and airline fares getting more expensive for everyday consumers. So, uh, whenever I hear about Telegram, it’s always in relation to something bad. What gives? He floated the idea of restricting the use of Telegram in Ukraine and Russia, a suggestion that was met with fierce opposition from users. Shortly after, Durov backed off the idea. At the start of 2018, the company attempted to launch an Initial Coin Offering (ICO) which would enable it to enable payments (and earn the cash that comes from doing so). The initial signals were promising, especially given Telegram’s user base is already fairly crypto-savvy. It raised an initial tranche of cash – worth more than a billion dollars – to help develop the coin before opening sales to the public. Unfortunately, third-party sales of coins bought in those initial fundraising rounds raised the ire of the SEC, which brought the hammer down on the whole operation. In 2020, officials ordered Telegram to pay a fine of $18.5 million and hand back much of the cash that it had raised.
from ar


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