floaty fiddling
2008-05-06 20:24![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
So I needed some Lua functions to extract bit fields from an integral value, specifically struct stat.st_mode. Lua only has floating point numbers, and its standard library doesn't extend beyond ANSI C. So I wrote the following. (Note that a % b == a - floor(a/b)*b.)
function mask(lobit, hibit, num) local toolo = num % 2^lobit return (num - toolo) % 2^hibit end function bit(bit, num) return num / 2^bit % 2 >= 1 end
no subject
Date: 2008-05-07 10:31 (UTC)I remember his approach to fast multiplication (FFT, convolve, FFT); I'd guess that he had some fast method for computing 1/x, which would make a/b as fast as a*(1/b).
no subject
Date: 2008-05-07 16:33 (UTC)Whenever I need to do a convolution or, more likely, a correlation/autocorrelation, I tend to go FFT, multiply, FFT. In what case/by what algorithm is a direct convolution faster than multiplication?