Variable larger than float or double

afternoon, here is the code to my sketch (arduino uno)

float ans;
float temp;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}
void loop(){
for (int j=1 ; j <= 30; j++){
 for (int i=1; i <= 30; i++) {
  temp = (sq(j)*j) + (sq(i)*i);
  ans = pow(temp, 0.3333333);
  delay(50);
  Serial.print(ans,DEC);
  Serial.print("      ");
  Serial.print(j);
  Serial.print("^3 + ");
  Serial.print(i);
  Serial.println("^3")
  } 
 } 
}

the goal of this sketch here is to cube root two cubes and print the resulting answer, also showing, next to the printed answer, what the two cubes are.

this goes on from 1 and 1, to 1 and 30, to 2 and 1 then to 2 and 30 and so on.

the problem with my code is there gets to a point where my answer doesnt get printed but the word "nan" is getting printed out (i have assumed an overflow has occurred around this situation) when it gets heavy operations like [21^3 + 30^3].

to go around this problem i wanted to figure out a way to manipulate the program such that values larger than float or double is possible so that i can finally handle larger operations like [256^3 + 568^3]. Is there any way i can do this or do you guys believe that this is technically impossible?

A 64 bit integer I think could hold up to the cube of 120000.

Bit of a problem printing it in decimal though.

I believe you are seeing the result of integer overflow. Don't use sq() and keep in mind that integers on an Uno have maximum value 32767.

If you want to treat i as a float, do it explicitly.

float x = i;
temp = x*x*x + y*y*y;

is it possible for me to have a 64 bit variable in arduino uno

Yes.
Edit: I think my earlier assertion was an understatement

Edit edit: big time

what function do i use to create 64 bit variable

You don't use a function, you just declare it like any other variable.
"long long" or "unsigned long long"

You don't need 64 bit variables, and they are not handled well by Arduino.
You need to fix the code, avoiding sq().

It depends how big they want to go...

They're handled well enough for the calculations.

does i have to be a float when the only value it will hold will only be between 0-30 provided that the function int will suffice for holding such the number range

The problem with your code is that sq() is a macro and treats i as an integer.

30x30x30 = 27000

adding two of those leads to integer overflow.

DON'T USE sq().

i used long double instead because i wanted the numbers behind the decimal point too

so i tried using long double but then now it says
"call of overloaded 'print(long double&)' is ambiguous"
should this be the end of the road provided that i cant get a value like "long double" to be printed?

i tried but im still getting nans

Post the code you tried, using code tags. You are still doing something wrong.

here you go

 double ans;
double  temp;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}
void loop(){
for (int j=1 ; j <= 30; j++){
 for (int i=1; i <= 30; i++) {
  temp = (j*j*j) + (i*i*i);
  ans = pow(temp, 0.3333333);
  delay(50);
  Serial.print(ans);
  Serial.print("      ");
  Serial.print(j);
  Serial.print(" x ");
  Serial.println(i);
  } 
 } 
}

also i have runned into another problem with this alternative. It seems as though this sketch rounds off the float value to two decimal points (i dont know why) is there a way i can go around this problem and instead print the full decimal value and not the rounded value?

This is guaranteed to produce integer overflow on an AVR based Arduino.

Replace that with

float x=i;
float y=j;
float temp = x*x*x + y*y*y;

im getting 0.00s as my printed answer, whats the problem now?

 double ans;
double  temp;
int j;
int i;
float y = j;
float x = i;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}
void loop(){
for ( j=1 ; j <= 30; j++){
 for ( i=1; i <= 30; i++) {
  temp = (y*y*y) + (x*x*x);
  ans = pow(temp, 0.3333333);
  delay(50);
  Serial.print(ans);
  Serial.print("      ");
  Serial.print(j);
  Serial.print(" x ");
  Serial.println(i);
  } 
 } 
}

The problem is that you do not follow instructions.

This code should be inside the loops, just before "temp" is calculated, not outside of any function.

        20    21    22    23    24    25    26    27    28    29    30
 20:  25.2  25.8  26.5  27.2  27.9  28.7  29.5  30.3  31.1  31.9  32.7
 21:  25.8  26.5  27.1  27.8  28.5  29.2  29.9  30.7  31.5  32.3  33.1
 22:  26.5  27.1  27.7  28.4  29.0  29.7  30.4  31.2  31.9  32.7  33.5
 23:  27.2  27.8  28.4  29.0  29.6  30.3  31.0  31.7  32.4  33.2  34.0
 24:  27.9  28.5  29.0  29.6  30.2  30.9  31.5  32.2  33.0  33.7  34.4
 25:  28.7  29.2  29.7  30.3  30.9  31.5  32.1  32.8  33.5  34.2  34.9
 26:  29.5  29.9  30.4  31.0  31.5  32.1  32.8  33.4  34.1  34.8  35.5
 27:  30.3  30.7  31.2  31.7  32.2  32.8  33.4  34.0  34.7  35.3  36.0
 28:  31.1  31.5  31.9  32.4  33.0  33.5  34.1  34.7  35.3  35.9  36.6
 29:  31.9  32.3  32.7  33.2  33.7  34.2  34.8  35.3  35.9  36.5  37.2
 30:  32.7  33.1  33.5  34.0  34.4  34.9  35.5  36.0  36.6  37.2  37.8

char s [20];
char t [20];

void
cube (
    int  N)
{
    Serial.print  ("    ");
    for (int j = 20; j <= N; j++)  {
        sprintf (s, " %5d", j);
        Serial.print (s);
    }
    Serial.println ();

    for (int i = 20; i <= N; i++)  {
        sprintf (s, " %2d:", i);
        Serial.print (s);

        for (int j = 20; j <= N; j++)  {
            float i2 = i*i*i;
            float j2 = j*j*j;

            float f = pow(i2 + j2, 1.0/3);
            dtostrf (f, 5, 1, t);
            sprintf (s, " %s", t);
            Serial.print (s);
        }

        Serial.println ();
    }
}

void setup ()
{
    Serial.begin (9600);
    cube (30);
}

void loop () {
}

ok i put the code in properly, one problem was fixed ( i follow instructions now) but there now comes a different problem, the board happens to continue calculating until it gets to a point where you have a heavy operation like [18^3 + 30^3]. instead of printing "nan" it skips the next consecutive heavy operations and goes back to a easy operation like [1^3 + 30^3].
(i think another problem introduced is that my board is acting a bit lazy)

 double ans;
double  temp;
int j;
int i;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}
void loop(){
  
for ( j=1 ; j <= 30; j++){
 for ( i=1; i <= 30; i++) {
  float x = i;
  float y = j;
  temp = (y*y*y) + (x*x*x);
  ans = pow(temp, 0.3333333);
  delay(50);
  Serial.print(ans);
  Serial.print("      ");
  Serial.print(j);
  Serial.print(" x ");
  Serial.println(i);
  } 
 } 
}