C++ to PB
Posted: Sun Nov 19, 2006 10:26 pm
Some software I have auto-generates a C++ code snippet which I want to convert to PB . . . but with no experience of C I'm struggling to know what's going on. Can anyone offer me a solution?
It's basically for a formula I need to apply to a set of variables which I supply, and are identified as X1 thru X9. The C++ code is as follows;
#include <math.h>
double gModel(double d[]);
double gModel(double d[])
{
const double G1C0 = -4.308685;
const double G1C1 = -6.65509;
const double G2C0 = -5.364014;
const double G2C1 = -1.628174;
const double G3C0 = 7.809296;
const double G3C1 = 4.200164;
const double G4C0 = 4.932343;
const double G4C1 = 7.813782;
double dblTemp = 0.0;
dblTemp = sin(atan((d[1]*d[0])));
dblTemp += d[3];
dblTemp += (d[2]+((G3C1+G3C0)+d[2]));
dblTemp += d[3];
return dblTemp;
}
I've tried substituting the d[x] array(?) elements with my X variables and the G3Cx constants as declared, but the answer is not quite as expected.
The software also allows the code to be produced with or without "labels". Above is without labels. The 'with labels' version is as below;
#include <math.h>
double gModelHY(double d[]);
double gModelHY(double d[])
{
const double G1C0 = -4.308685;
const double G1C1 = -6.65509;
const double G2C0 = -5.364014;
const double G2C1 = -1.628174;
const double G3C0 = 7.809296;
const double G3C1 = 4.200164;
const double G4C0 = 4.932343;
const double G4C1 = 7.813782;
const int X1 = 0;
const int X2 = 1;
const int X3 = 2;
const int X4 = 3;
const int X5 = 4;
const int X6 = 5;
const int X7 = 6;
const int X8 = 7;
const int X9 = 8;
double dblTemp = 0.0;
dblTemp = sin(atan((d[X2]*d[X1])));
dblTemp += d[X4];
dblTemp += (d[X3]+((G3C1+G3C0)+d[X3]));
dblTemp += d[X4];
return dblTemp;
}
Anyone point me in the right direction?
Stef
PS
Software also outputs in other languages, but I'm not familiar with any of them.
It's basically for a formula I need to apply to a set of variables which I supply, and are identified as X1 thru X9. The C++ code is as follows;
#include <math.h>
double gModel(double d[]);
double gModel(double d[])
{
const double G1C0 = -4.308685;
const double G1C1 = -6.65509;
const double G2C0 = -5.364014;
const double G2C1 = -1.628174;
const double G3C0 = 7.809296;
const double G3C1 = 4.200164;
const double G4C0 = 4.932343;
const double G4C1 = 7.813782;
double dblTemp = 0.0;
dblTemp = sin(atan((d[1]*d[0])));
dblTemp += d[3];
dblTemp += (d[2]+((G3C1+G3C0)+d[2]));
dblTemp += d[3];
return dblTemp;
}
I've tried substituting the d[x] array(?) elements with my X variables and the G3Cx constants as declared, but the answer is not quite as expected.
The software also allows the code to be produced with or without "labels". Above is without labels. The 'with labels' version is as below;
#include <math.h>
double gModelHY(double d[]);
double gModelHY(double d[])
{
const double G1C0 = -4.308685;
const double G1C1 = -6.65509;
const double G2C0 = -5.364014;
const double G2C1 = -1.628174;
const double G3C0 = 7.809296;
const double G3C1 = 4.200164;
const double G4C0 = 4.932343;
const double G4C1 = 7.813782;
const int X1 = 0;
const int X2 = 1;
const int X3 = 2;
const int X4 = 3;
const int X5 = 4;
const int X6 = 5;
const int X7 = 6;
const int X8 = 7;
const int X9 = 8;
double dblTemp = 0.0;
dblTemp = sin(atan((d[X2]*d[X1])));
dblTemp += d[X4];
dblTemp += (d[X3]+((G3C1+G3C0)+d[X3]));
dblTemp += d[X4];
return dblTemp;
}
Anyone point me in the right direction?
Stef
PS
Software also outputs in other languages, but I'm not familiar with any of them.