3 ms·
In C you can use scalbn(), which a good compiler would hopefully optimize to something equivalent to what you wrote. Java has scalb(), presumably based on the C
by wiml 11y ago
In C you can use scalbn(), which a good compiler would hopefully optimize to something equivalent to what you wrote. Java has scalb(), presumably based on the C function.
- cozzyd 11y agoIt doesn't look like gcc (4.8.3) inlines scalbn on -O3 (unless I need another flag...). I see callq(scalbn) in the disassembly.
- stephencanon 11y agoThat's not a legal optimization as it gets all sorts of edge cases wrong. For example scalbn(0, anything) is zero, whereas simply adding to the exponent will produce some arbitrary power of two or infinity.