3 ms·
Compile-time integer exponentiation in Go would be neat, e.g. 5 * (1000**4). I know we have scientific-notation integer literals, but it's not the same thing,
by derefr 7y ago
Compile-time integer exponentiation in Go would be neat, e.g. 5 * (1000**4).
I know we have scientific-notation integer literals, but it's not the same thing, especially when trying to calculate e.g. Mebibytes.
- pkaye 7y agoIn go you can use scientific notation for integers var x int = 1e9
- big_chungus 7y agoNot sure about go, but you can do this in C as a compile-time constant: #define foo 1.34E8 Maybe go would benefit from a pre-processor? Though it can be somewhat byzantine in C (and result in very unpredictable final source, if abused), it's very helpful to have a complete functional language available for code transformation. It might help go in some cases, too.
- Cthulhu_ 7y agoYou say that, but I find that a lot harder to read (and using `e` notation) than just the number - and readability / clarity is more important than cleverness, especially in Go. 10_000_000 can be read, 5 * (1000**4) and 1e7 has to be decoded. By me anyway, I'm just an average developer that never did well in maths - and you have to write code for the average developer, not for yourself and not for the top 10% smartest people.