Playing around with genetic programming. Program will make a formula which approximates the input sequence.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

39 lines
736 B

#include "utilities.hpp"
#include <limits>
using namespace std;
int divi(int x, int y){
// clearly we don't want a division by zero
if(!y) {
if(x < 0) return numeric_limits<int>::min();
if(x == 0) return 1;
return numeric_limits<int>::max();
}
// in this situation there is a overflow which causes a SIGFPE
if(x == numeric_limits<int>::min() && y == -1) {
return numeric_limits<int>::max();
}
return x / y;
}
int modi(int x, int y){
if(!y) return 0;
if(x == numeric_limits<int>::min() && y == -1) return 0;
return x % y;
}
// exponentiation by squaring
int powi(int base, int exp){
if(exp < 0) return 0;
int res = 1;
while (exp) {
if (exp & 1)
res *= base;
exp >>= 1;
base *= base;
}
return res;
}