Skip to content

Instantly share code, notes, and snippets.

@jacknlliu
Last active April 25, 2018 08:55
Show Gist options
  • Save jacknlliu/b1872bfd6c4b6688ea906473caa82512 to your computer and use it in GitHub Desktop.
Save jacknlliu/b1872bfd6c4b6688ea906473caa82512 to your computer and use it in GitHub Desktop.
c++ implement of numpy clip. reference https://stackoverflow.com/a/9324086
#include <math.h>
#include <iostream>
using namespace std;
float clip(float n, float lower, float upper) {
return std::max(lower, std::min(n, upper));
}
int main()
{
float a = 0.0;
cout<<"input a number:"<<endl;
cin>>a;
float c = clip(a, 10.0, 200.0);
cout<<c<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment