Handling Denormal Numbers

Правка en1, от maroonrk, 2022-07-06 19:13:54

What if your solution got TLE due to denormal numbers? Would you add if(val<eps)val=0 everywhere? Today I found a simpler fix: let's include #include <xmmintrin.h> and insert _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); at the beginning of the main function.

Example Problem

TLE Submission

AC Submission

I confirmed this magic works on AtCoder, Codechef, Yandex, and, of course, on Codeforces.

Since it's written on the Wikipedia page, I won't be surprised if this is a well-known trick in some countries. However, I and my friends haven't heard of this, so it must be worth sharing.

Note that I know nothing about what exactly this snippet does, and I'm happy to hear from computer experts what the possible defects it has if such exist.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский maroonrk 2022-07-06 19:13:54 1002 Initial revision (published)