Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Math.h"
- Math::Math()
- {
- }
- Math::~Math()
- {
- }
- double Math::pi = std::acos(-1);
- int Math::sign(long n){
- return (n < 0) ? -1 : 1;
- }
- double Math::round(double n, int r){
- double p = pow(10, r);
- return std::round(n*p) / p;
- }
- double Math::max(vector<double> t){
- double largest = t[0];
- for (int i = 1; i<t.size(); i++)
- {
- double val = t[i];
- largest = (largest>val) ? largest : val;
- }
- return largest;
- }
- double Math::min(vector<double> t){
- double lowest = t[0];
- for (int i = 1; i<t.size(); i++)
- {
- double val = t[i];
- lowest = (lowest<val) ? lowest : val;
- }
- return lowest;
- }
- double Math::gcd(int a, int b){
- while (b != 0){
- int r = a%b;
- a = b;
- b = r;
- }
- return a;
- }
- double Math::lcm(int a, int b){
- return a*b / gcd(a, b);
- }
- int Math::modpow(int a, int b, int c){
- if (b == 0)
- return 1 % c;
- if (b == a)
- return a % c;
- int r = modpow(a, b / 2, c);
- return r*r*((b % 2 == 1) ? a : 1) % c;
- }
- int Math::rand(int min, int max){
- mt19937 rng;
- rng.seed(random_device()());
- uniform_int_distribution<mt19937::result_type> dist1(min, max);
- double ra = std::rand();
- return dist1(rng);
- }
- long Math::factorial(int n){
- long p = 1;
- for (int i = 2; i <= n; i++){
- p *= i;
- }
- return p;
- }
Add Comment
Please, Sign In to add comment