I have a function that calls itself a near infinite amount of times, but it does have an end. It calculates the mathematical formula (in TeX):
When x<a
:
g_{a}(x)=1
When x>=a
:
g_{a}(x)=g_{a}(x-1)+g_a(x-a)
Here is my code(c++):
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <cmath>
using namespace std;
double g( double a, double x){
if (x>=a) return (g(a,x-1)+g(a,x-a));
else if (x<a) return 1;
return 0;
}
int main(){cout << g(sqrt(10000019),10000019);}
I call the function with g(sqrt(10000019),10000019);
How do I stop the SEGFAULT?