const maxFrameRate = 60
minInterval := int64((1.0 / maxFrameRate) * 1e9)
... then Go reports this error: constant 1.66667e+07 truncated to integer
But this code compiles just fine:
const maxFrameRate = 60
foo := (1.0 / maxFrameRate) * 1e9
minInterval := int64(foo)
I'm not doing something wrong, am I?
Chris
When converting a floating-point number to an integer, the fraction is discarded (truncation towards zero).
The values of typed constants must always be accurately representable as values of the constant type.
Michael T. Jones
Chief Technology Advocate, Google Inc.
1600 Amphitheatre Parkway, Mountain View, California 94043
Email: m...@google.com Mobile: 650-335-5765 Fax: 650-649-1938
Organizing the world's information to make it universally accessible and useful
interestingly...var maxFrameRate int = 60
minInterval := 1e9/maxFrameRate
fmt.Printf("%T, %v\n", minInterval, minInterval)prints: int, 16666666
whileconst maxFrameRate = 60
minInterval := 1e9/maxFrameRate
>
> He did not really want 1e9, he wanted 10**9. The first conflates
> floating point styling and scientific notation with exponentiation. If
> we had some syntax for the second it would have worked as expected.
It worked as I expected and explained. As for the missing syntax: int(1e9).
-rob