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?
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
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?
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?
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);
}
}
}