clamp in c 2b 2b

Solutions on MaxInterview for clamp in c 2b 2b by the best coders in the world

showing results for - "clamp in c 2b 2b"
Clyde
09 May 2020
1#include <cstdint>
2#include <algorithm>
3#include <iostream>
4#include <iomanip>
5 
6int main()
7{
8    std::cout << " raw   clamped to int8_t   clamped to uint8_t\n";
9    for(int const v: {-129, -128, -1, 0, 42, 127, 128, 255, 256}) {
10        std::cout << std::setw(04) << v
11                  << std::setw(20) << std::clamp(v, INT8_MIN, INT8_MAX)
12                  << std::setw(21) << std::clamp(v, 0, UINT8_MAX) << '\n';
13    }
14}