4 ms·
Had a quick look, found this little gem, a math evaluator with precedence. https://github.com/mirror/busybox/blob/master/shell/math.c https://github.com/mirror
by dana321 7y ago
Had a quick look, found this little gem, a math evaluator with precedence.
https://github.com/mirror/busybox/blob/master/shell/math.c https://github.com/mirror/busybox/blob/master/shell/math.c
Some funny comments like "Think about it.
* It makes sense."
- voldacar 7y ago> The lower 5 bits are the precedence, and 3 high bits are an ID unique across operators of that precedence. This is so cool. Nobody would write code like this today
- tachyonbeam 7y agoPeople wouldn't optimize a shell like that anymore, but people still do encode small pieces of information into integers using bitwise operations when compactness is an advantage. If you're dealing with a large data structure with tens of millions (or billions) of entries, compact encoding still trumps convenience, because memory bandwidth will often be the bottleneck. A data structure that would benefit from a compact encoding could be a compiler's intermediate representation, for example.
- userbinator 7y agoI was surprised that it's not recursive-descent/precedence-climbing, and that ~20% of the linecount is copyright/comments.
- swiley 7y agoYeah most things have a lot of comments. It’s very nice to read.