arduino / arduino/ArduinoCore-API

map() for float data type

Open
#71 18 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

If a `float` argument is passed to the `map()` function, it truncates them to integer values. This provides erroneous output that may not be immediately noticed. This does not produce a compiler warning.

Please add a `float` variant of `map()`:

```cpp
float mapf(float value, float istart, float istop, float ostart, float ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
```

### Additional context

#### Additional reports

- https://dicks-photon-arduino.blogspot.com/2016/05/40-arduino-c-map-function-vs.html

#### Related

- https://github.com/arduino/Arduino/issues/288

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing map() entry point in ArduinoCore-API and reviewing how it handles numeric inputs and outputs. Done means a float-specific mapping API preserves fractional values for float arguments while leaving the existing map() behavior unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.