Answers for "c++ clamp function"

C++
0

clamp in c++

#include <cstdint>
#include <algorithm>
#include <iostream>
#include <iomanip>
 
int main()
{
    std::cout << " raw   clamped to int8_t   clamped to uint8_tn";
    for(int const v: {-129, -128, -1, 0, 42, 127, 128, 255, 256}) {
        std::cout << std::setw(04) << v
                  << std::setw(20) << std::clamp(v, INT8_MIN, INT8_MAX)
                  << std::setw(21) << std::clamp(v, 0, UINT8_MAX) << 'n';
    }
}
Posted by: Guest on March-15-2021

Browse Popular Code Answers by Language