Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个介于 0 和 1 之间的浮点值,它代表特定颜色的色调。如何将该浮点值映射到某个大小的数组索引。
所以,假设我想创建 128 个“桶”来对我的对象进行排序,如何根据它的值将浮点值转换为 0-127 之间的数组索引?
乘法,然后向下舍入。
arrayIndex = floor(floatingValue * numberOfBuckets)