by tptacek · 7y ago · 0 comments
O_o
1e7
Is a float literal.
var u uint32 = 10000000000.0 / 100000
even though 10000000000 overflows uint32 and it's also written like a floating-point literal. 12_345_678
1.2345678e710 * 1000 * 1000 worked pretty well too.
I know we have scientific-notation integer literals, but it's not the same thing, especially when trying to calculate e.g. Mebibytes.
var x int = 1e910_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.
#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. gofmt -r 'y << uint(x) -> y << x'
(You'll have to run this multiple times for uint32, uint64 etc. if you shift with those types.)