/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int32_t map_exp (int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max);
float helper_throttle = 0.3;
int main()
{
//mapped_throttle= map_exp(adc_value[1], MP.throttle_offset, MP.throttle_max, 0, phase_current_max_scaled);
printf("result: %d",map_exp(2000,1000,3000,0,500));
return 0;
}
int32_t map_exp (int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max)
{
// if input is smaller/bigger than expected return the min/max out ranges value
if (x < in_min)
return out_min;
else if (x > in_max)
return out_max;
else{
float mapped_exp = (float)(x-in_min)/(float)(in_max-in_min);
printf("fraction: %f\r\n",mapped_exp);
mapped_exp= powf(mapped_exp,helper_throttle)*out_max;
return (int32_t)mapped_exp;
}
}