#casting float64 -> int embedded in []r3.Vector

5 messages · Page 1 of 1 (latest)

whole stone
#

i have a library that is returning []r3.Vector (its a list of positions in a 3d game world). my problem is that each individual value is float64, but i dont need this level of detail for my purposes and would prefer if i could cast all of them to ints (and truncate everything after the decimal point). whats the best way i can do this?

#

sorry if this is badly worded, just getting into Go as of last week. only used Python and some Java otherwise

#

nevermind, i realised i didnt actually need to do this

#

jumped the gun a little lol

austere rose
#

it's probably gonna be more expensive to do the conversion because you will need to reallocate a new slice.
The most optimized way is wherever you are consuming this slice cast it there (so you don't create new memory workload, basically where you would have red it anyway you read it there)

If you know the slice is not used by someone else and you don't mind a bit of unsafe you can convert it to a slice of ints however this will require reading and writing everything back, which is less efficient than at use conversion due to the extra memory workload of reading and copying