Skip to content

detect division by zero in map() to prevent exceptions #2397

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

Merged
merged 2 commits into from
Aug 18, 2016

Conversation

me-no-dev
Copy link
Collaborator

Will return -1 like AVR would
connected to #2219

@codecov-io
Copy link

codecov-io commented Aug 15, 2016

Current coverage is 27.80% (diff: 100%)

Merging #2397 into master will not change coverage

@@             master      #2397   diff @@
==========================================
  Files            20         20          
  Lines          3625       3625          
  Methods         335        335          
  Messages          0          0          
  Branches        656        656          
==========================================
  Hits           1008       1008          
  Misses         2441       2441          
  Partials        176        176          

Powered by Codecov. Last update 7746288...c7bf824

@me-no-dev me-no-dev merged commit fb00e64 into esp8266:master Aug 18, 2016
@me-no-dev me-no-dev deleted the map-div-by-zero branch August 18, 2016 07:51
slaff pushed a commit to slaff/Sming that referenced this pull request Jun 1, 2017
slaff added a commit to SmingHub/Sming that referenced this pull request Jun 1, 2017
if(divisor == 0){
return -1; //AVR returns -1, SAM returns 0
}
return (x - in_min) * (out_max - out_min) / divisor;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be

divisor = in_max - in_min;
return .../divisor + out_min;

@FernandoGarcia
Copy link

FernandoGarcia commented Jun 3, 2023

Hi @me-no-dev!

The map function has been changed and I'm getting this error in version 3.1.1.

Captura de tela de 2023-06-03 19 03 44

EDIT: I'll place all information here because I'm not sure about the right version number.

PLATFORM: Espressif 8266 (4.1.0) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 @ 3.30101.0 (3.1.1)

I'm using PIO.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants