My code won\'t compile in c++ visual studio\'s i\'m not sure whats wrong exactly
ID: 2854487 • Letter: M
Question
My code won't compile in c++ visual studio's i'm not sure whats wrong exactly.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// here the function is used fro cheking
double equationRootB(double x, double y, double z)
{
return (-y + sqrt(y * y - 4 * x * z)) / (2 * x);
}
double equationRoot(double x, double y, double z)
{
double root;
asm(
"fldl %1 "
"fadd %%ST "
"fldl %1 "
"fldl %3 "
"fmulp %%ST(1) "
"fadd %%ST "
"fadd %%ST "
"fldl %2 "
"fldl %2 "
"fmulp %%ST(1) "
"fsubp %%ST(1) "
"fsqrt "
"fldl %2 "
"fchs "
"faddp %%ST(1) "
"fdivp %%ST(1) "
:"=t"(root)
:"m"(x), "m"(y), "m"(z)
);
return(root);
}
int main( char **argv,int argc)
{
double x, y, z;
double root, rootB;
if (argc != 4) {
printf("three arguments reuired: x, y, z ");
return -1;
}
x = atof(argv[1]);
y = atof(argv[2]);
z = atof(argv[3]);
root = equationRoot(x, y, z);
rootB = equationRootB(x, y, z);
printf("equationRoot(%.3f, %.3f, %.3f) = %.3f, %.3f ", x, y, z, root, rootB);
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// here the function is used fro cheking
double equationRootB(double x, double y, double z)
{
return (-y + sqrt(y * y - 4 * x * z)) / (2 * x);
}
double equationRoot(double x, double y, double z)
{
double root;
asm(
"fldl %1 "
"fadd %%ST "
"fldl %1 "
"fldl %3 "
"fmulp %%ST(1) "
"fadd %%ST "
"fadd %%ST "
"fldl %2 "
"fldl %2 "
"fmulp %%ST(1) "
"fsubp %%ST(1) "
"fsqrt "
"fldl %2 "
"fchs "
"faddp %%ST(1) "
"fdivp %%ST(1) "
:"=t"(root)
:"m"(x), "m"(y), "m"(z)
);
return(root);
}
int main( 'char **'argv,int argc)
{
double x, y, z;
double root, rootB;
if (argc != 4) {
printf("three arguments reuired: x, y, z ");
return -1;
}
x = atof(argv[1]);
y = atof(argv[2]);
z = atof(argv[3]);
root = equationRoot(x, y, z);
rootB = equationRootB(x, y, z);
printf("equationRoot(%.3f, %.3f, %.3f) = %.3f, %.3f ", x, y, z, root, rootB);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.