Skip to content
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

map function high to low #90

Open
jbobrow opened this issue May 30, 2019 · 3 comments
Open

map function high to low #90

jbobrow opened this issue May 30, 2019 · 3 comments

Comments

@jbobrow
Copy link
Contributor

jbobrow commented May 30, 2019

Currently the map() function works with the following:
map(var, low_input, high_input, low_output, high_output)

i.e. lo,hi,lo,hi

I would like to have the function also work for the following:
lo,hi,hi,lo
hi,lo,hi,lo
hi,lo,lo,hi

Some common use case examples are mapping the remaining time from a timer which is going from high to low or wanting to dim brightness with the increase of a variable... All in all these are conveniences, but I have found that only working properly for the lo,hi,lo,hi makes it easy to make mistakes the the 3 other possible configurations. Working with words still makes sense, no need to account for negative numbers, I think that is a fine place to draw the line.

@bigjosh
Copy link
Owner

bigjosh commented Jun 1, 2019

Of course it is easy to make a map() function that covers these additional cases, but these will expand the flash used by this already-too-big function by several times.

Maybe make a new expensive_map() function that does not require the arguments to be in min < max order and instead covers all the combinations?

Or maybe we could change the type of the inputs to be ints so that the function could use signed math rather than special casing out the combinations?

@jbobrow
Copy link
Contributor Author

jbobrow commented Jun 2, 2019

Using int makes a lot of sense, I’m trying to think of the main consequences of that change. Ints are twice the size, but I imagine the math is the expensive portion. This isn’t prohibitive for our launch games, but trying to make the platform friendlier for beginners.

@bigjosh
Copy link
Owner

bigjosh commented Jun 2, 2019

Both int and word are 16 bits on this platform, only difference is that int uses one of those bits for sign so goes from -32768 to 32767 whereas word goes from 0-65535.

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

No branches or pull requests

2 participants