Overcomplicated Linear Function
f(x) = coefficient * x + intercept Too simple? D'accord, let's extend this with a division, rounding, and saturation : void sFC(unsigned short * pDst, short * pSrc, short coeff, sh { int res; do { res = *pSrc++ * coeff + intercept; if (res & 0x80) res += 256; res >>= 8; if (res < 0) res = 0; if (res>0xffff) res = 0xffff; *pDst++ = (unsigned short) res; } while (--count); } The C function above is quite self explanatory. It does multiplication, addition, division (right shift) with roundings, and saturates to 0 to 65535 (16bit).
A screenshot presents a supposedly simple linear function, then expands it into dense C code with fixed-point arithmetic, rounding, shifting, and saturation. The joke is that a basic formula becomes absurdly complicated in real low-level implementation, making it a relatable reaction to overengineering or unexpectedly difficult programming tasks. EN: A screenshot presents a supposedly simple linear function, then expands it into dense C code with fixed-point arithmetic, rounding, shifting, and saturation. The joke is that a basic formula becomes absurdly complicated in real low-level implementation, making it a relatable reaction to overengineering or unexpectedly difficult programming tasks.
mathematical formula / математическая формулаC code / код на Ccode editor screenshot / скриншот редактора кодаsource code / исходный кодfunction declaration / объявление функцииmultiplication / умножениеaddition / сложениеdivision / делениеrounding / округлениеbit shift / битовый сдвигsaturation / насыщениеnumeric values / числовые значенияgreen highlight / зелёная подсветкаtext caption / текстовая подпись
- @profunctor_io / 3214 2019-10-15
- Type
- image
- Size
- 800×470 · 58.3 KiB
- Mood
- sarcastic, relatable
- Language
- en
- Added