math: integer division, modulo? #1064
-
Hey guys, I'm struggling with doing just normal integer stuff in a for comprehension. I want to loop through a list and set x to idx%2 and y to idx/2 using integer division (rounding down). However, I'm fighting the type system and I can't find a good way to do it. This is the ideal way I would hope to achieve what I want:
Since idx is int, not float64, I can't use it in any of the math library functions, like Mod. However, if I divide it at all, it goes from an int to a float (still not float64). I can't do integer division and I can't do modulo and I keep feeling like I must be missing something obvious. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Ok, yes, I was missing something obvious. Right after posting, I found a good way to do what I want:
This solves my specific use case and hopefully it helps others, but working with numbers still feels a bit annoying. |
Beta Was this translation helpful? Give feedback.
-
This discussion has been migrated to cue-lang/cue#1064. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
Ok, yes, I was missing something obvious. Right after posting, I found a good way to do what I want:
This solves my specific use case and hopefully it helps others, but working with numbers still feels a bit annoying.