Java function equivalent to the c++ map()

Asked

Viewed 81 times

2

There is a function for java, equivalent to map() of c++?

Basically it calculates the ratio between the values "minimum" and "maximum".

1 answer

3


Apparently, there is no such standard function in Java, and probably not even in C++, but only in the Arduino for the conversion of sensor values.

You can implement it in your project because it’s very simple, and the code is in the link you posted:

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
  • 1

    It’s true @George had not read the right post. Thank you very much friend.

  • 1

    @Emersonbarcellos, no problem. It’s an important question for the community, having a native function would be much simpler!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.