Skip to content

Commit b1e1782

Browse files
Fix for map() function - supplied by @pito
1 parent 23fa7b7 commit b1e1782

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

STM32F1/cores/maple/wirish_math.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ long random(long min, long max);
7979
* @param toEnd the end of the value's mapped range.
8080
* @return the mapped value.
8181
*/
82-
static inline long map(long value, long fromStart, long fromEnd,
83-
long toStart, long toEnd) {
84-
return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) +
85-
toStart;
86-
}
82+
// Fix by Pito 9/2017
83+
static inline int32_t map(int32_t value, int32_t fromStart, int32_t fromEnd,
84+
int32_t toStart, int32_t toEnd) {
85+
return ((int64_t)(value - fromStart) * (toEnd - toStart)) / (fromEnd - fromStart) +
86+
toStart;
87+
}
8788

8889
#define PI 3.1415926535897932384626433832795
8990
#define HALF_PI 1.5707963267948966192313216916398

STM32F4/cores/maple/wirish_math.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ long random(long min, long max);
7878
* @param toEnd the end of the value's mapped range.
7979
* @return the mapped value.
8080
*/
81-
static inline long map(long value, long fromStart, long fromEnd,
82-
long toStart, long toEnd) {
83-
return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) +
84-
toStart;
85-
}
81+
// Fix by Pito 9/2017
82+
static inline int32_t map(int32_t value, int32_t fromStart, int32_t fromEnd,
83+
int32_t toStart, int32_t toEnd) {
84+
return ((int64_t)(value - fromStart) * (toEnd - toStart)) / (fromEnd - fromStart) +
85+
toStart;
86+
}
8687

8788
#define PI 3.1415926535897932384626433832795
8889
#define HALF_PI 1.5707963267948966192313216916398

0 commit comments

Comments
 (0)