This in fact is correct behavior.

As 100 is an untyped integer constant, 1e2 can not be implicitly converted 
to the same type and so the % operation fails.

You can fix it with:

func main() { println(int(100) % 1e2) }

Now 1e2 is converted to 'int' and all is well :)

Alan

On Thursday, October 31, 2019 at 5:13:48 PM UTC, Marc Vertes wrote:
>
> Hello,
>
> I see that the following code
>
> func main() { println(100 % 1e2) }
>
> is rejected by the compiler with "invalid operation: operator % not 
> defined on untyped float"
>
> but the following
>
> func main() { i := 100; println(i % 1e2) }
>
> is happily accepted. Should I open an issue on this ? What should the 
> normal behaviour be ?
>
> Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/14fb91c8-019e-4800-817a-db71b908c47b%40googlegroups.com.

Reply via email to