shoorick: (Рыжий)
[personal profile] shoorick
Интересный способ округления увидел сейчас в http://3site.eu/examples/snow/snow.js — для этого там используется сдвиг:
style.left = ((random() * offsetWidth) >> 0) + "px";

Проверил — так и есть:
5 / 2      == 2.5
5 / 2 >> 0 == 2

Но в чём смысл? Сэкономить буквы, отказавшись от Math.floor?

Date: 2013-12-20 06:01 am (UTC)
From: [identity profile] aamonster.livejournal.com
Совершенно непонятно. Погуглив - нашёл вариант "x|0", который явно короче и, как пишут, чуть быстрее, чем Math.floor.

Date: 2013-12-22 02:13 pm (UTC)
From: [identity profile] intripalroh.livejournal.com
ух ты=) круто

Profile

shoorick: (Default)
shoorick

December 2016

S M T W T F S
    1 23
45678910
11121314151617
18 19 2021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 22nd, 2026 05:00 pm
Powered by Dreamwidth Studios