Fix for map() function - supplied by @Pito
This commit is contained in:
parent
23fa7b7c34
commit
b1e1782019
|
@ -79,9 +79,10 @@ long random(long min, long max);
|
||||||
* @param toEnd the end of the value's mapped range.
|
* @param toEnd the end of the value's mapped range.
|
||||||
* @return the mapped value.
|
* @return the mapped value.
|
||||||
*/
|
*/
|
||||||
static inline long map(long value, long fromStart, long fromEnd,
|
// Fix by Pito 9/2017
|
||||||
long toStart, long toEnd) {
|
static inline int32_t map(int32_t value, int32_t fromStart, int32_t fromEnd,
|
||||||
return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) +
|
int32_t toStart, int32_t toEnd) {
|
||||||
|
return ((int64_t)(value - fromStart) * (toEnd - toStart)) / (fromEnd - fromStart) +
|
||||||
toStart;
|
toStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,10 @@ long random(long min, long max);
|
||||||
* @param toEnd the end of the value's mapped range.
|
* @param toEnd the end of the value's mapped range.
|
||||||
* @return the mapped value.
|
* @return the mapped value.
|
||||||
*/
|
*/
|
||||||
static inline long map(long value, long fromStart, long fromEnd,
|
// Fix by Pito 9/2017
|
||||||
long toStart, long toEnd) {
|
static inline int32_t map(int32_t value, int32_t fromStart, int32_t fromEnd,
|
||||||
return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) +
|
int32_t toStart, int32_t toEnd) {
|
||||||
|
return ((int64_t)(value - fromStart) * (toEnd - toStart)) / (fromEnd - fromStart) +
|
||||||
toStart;
|
toStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue