8000 Fix Map function - IntegerDivideByZero #8938 by TD-er · Pull Request #8957 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Fix Map function - IntegerDivideByZero #8938 #8957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Simplify map to inverse range of same length
  • Loading branch information
TD-er committed Jul 18, 2023
commit 0962edc5453884e901b46dc1df788f977677c024
8 changes: 4 additions & 4 deletions cores/esp8266/WMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ long map(long x, long in_min, long in_max, long out_min, long out_max) {

long delta = x - in_min;

if (out_length == in_length) {
return out_min + delta;
}

if ((out_length < 0) && (in_length < 0)) {
std::swap(in_min, in_max);
std::swap(out_min, out_max);
Expand All @@ -101,6 +97,10 @@ long map(long x, long in_min, long in_max, long out_min, long out_max) {
in_length = in_max - in_min;
out_length = out_max - out_min;

if (out_length == in_length) {
return out_min + delta;
}

// We now know in_min < in_max and out_min < out_max
// Make sure x is within range of in_min ... in_max
// Shift the in/out range to contain 'x'
Expand Down
0