Last active
April 25, 2018 08:55
-
-
Save jacknlliu/b1872bfd6c4b6688ea906473caa82512 to your computer and use it in GitHub Desktop.
c++ implement of numpy clip. reference https://stackoverflow.com/a/9324086
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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