Generic integer scaling between different integer sizes.
Generic integer scaling between different integer sizes.
- Template Parameters
-
- Parameters
-
| x | The input value to scale |
- Returns
- The scaled value preserving relative position in range
Requires explicit specification of BOTH input and output types to prevent implicit type conversions that could mask bugs. Uses bit replication for scaling up (8→16, 8→32, 16→32) and right-shift with rounding for scaling down (16→8, 32→16, 32→8).
Supports all combinations of 8-bit, 16-bit, and 32-bit signed/unsigned types. Compile-time error for unsupported type conversions.
uint16_t y = fl::int_scale<uint8_t, uint16_t>(102);
int32_t z = fl::int_scale<int8_t, int32_t>(64);
uint8_t w = fl::int_scale<uint32_t, uint8_t>(0x80000000);
uint8_t noop = fl::int_scale<uint8_t, uint8_t>(255);
#pragma once
#include "platforms/intmap.h"
return fl::int_scale<u8, u16>(
x);
}
return fl::int_scale<u8, u32>(
x);
}
return fl::int_scale<u16, u32>(
x);
}
return fl::int_scale<u16, u8>(
x);
}
return fl::int_scale<u32, u16>(
x);
}
return fl::int_scale<u32, u8>(
x);
}
return fl::int_scale<i8, i16>(
x);
}
return fl::int_scale<i8, i32>(
x);
}
return fl::int_scale<i16, i32>(
x);
}
return fl::int_scale<i16, i8>(
x);
}
return fl::int_scale<i32, i16>(
x);
}
return fl::int_scale<i32, i8>(
x);
}
}
u8 map32_to_8(u32 x) FL_NO_EXCEPT
u32 map8_to_32(u8 x) FL_NO_EXCEPT
i16 smap32_to_16(i32 x) FL_NO_EXCEPT
Use int_scale<int32_t, int16_t>() instead.
i32 smap16_to_32(i16 x) FL_NO_EXCEPT
Use int_scale<int16_t, int32_t>() instead.
u16 map8_to_16(u8 x) FL_NO_EXCEPT
i16 smap8_to_16(i8 x) FL_NO_EXCEPT
Use int_scale<int8_t, int16_t>() instead.
u16 map32_to_16(u32 x) FL_NO_EXCEPT
i32 smap8_to_32(i8 x) FL_NO_EXCEPT
Use int_scale<int8_t, int32_t>() instead.
u32 map16_to_32(u16 x) FL_NO_EXCEPT
i8 smap16_to_8(i16 x) FL_NO_EXCEPT
Use int_scale<int16_t, int8_t>() instead.
i8 smap32_to_8(i32 x) FL_NO_EXCEPT
Use int_scale<int32_t, int8_t>() instead.
u8 map16_to_8(u16 x) FL_NO_EXCEPT
Base definition for an LED controller.