So far, I've figured out an algorithm for tetration that works.
However, although the variable a can be floating or integer, unfortunately, the variable b must be an integer number.
How can I modify the algorithm so that both a and b can be floating point numbers and the correct answer will be produced?
// Hyperoperation type 4:
public double tetrate(double a, double b)
{
double total = a;
for (int i = 1; i < b; i++) total = pow(a, total);
return total;
}
In an attempt to solve this, I've create my own custom power() function (trying to avoid roots, and log functions), and then successfully generalized it to multiplication. Unfortunately, when I then try to generalize to tetration, numbers go pear shaped.
I would like an algorithm to be precise up to x amount of decimal places, and not an approximation as Wikipedia talks about.
I feel like this is more of a programming techniques question than anything else, since the issues is about data type conversion. So you want to convert from
floattoint. So here is my suggested code (this should work. If not, tell me and I will edit this):// Hyperoperation type 4: public double tetrate(double a, double b) { double total = a; int coefficient = 0; for (int i = 1; i <= b; i++) { total = pow(a, total); coefficient = i; } total = pow(b-double(coefficient), total); return total; }As you can see, I added an
(int)statement before thebvariable. This is called a cast. It treats that double like an integer.