The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 arithmetic operation error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 04/18/2004 :  10:14:25 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

The attached code does not evaluate properly for XValue :
 
BOOL OCCreateCurves(double BottomDose, double TopXValue, int NumCurvePoints, string DSName){

Dataset CurveXValues(DSName);
CurveXValues.SetSize(10+NumCurvePoints);
double XValue;
double var1=TopXValue/BottomDose;
double var2;

// comment
for (int NumXValue=1; NumXValue<= 10+NumCurvePoints; NumXValue++)
{
if (NumXValue<=10)
{
XValue = 0+0.1*(NumXValue-1)*BottomDose;
}
else
{
var2=(NumXValue-10)/NumCurvePoints; // always evaluates to 0!
//var2=(NumXValue-10);
//var2/=NumCurvePoints;
XValue = pow(var1,var2);
}
CurveXValues[NumXValue-1]=XValue;

}
return TRUE;
}

unless var is calculated as follows :
 
var2=(NumXValue-10);
var2/=NumCurvePoints;

Any clues would be appreciated!

Cheers,

Pete

cpyang

USA
1406 Posts

Posted - 04/18/2004 :  11:51:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is how it works in C, so please replace

=(NumXValue-10)/NumCurvePoints;

with

=(NumXValue-10.0)/NumCurvePoints;

or

=(NumXValue-10)/(double)NumCurvePoints;


Something on the right-hand-side must be floating point in order to indicate to compiler to do arithmetics in floating point, otherwise the division will be performed by integers and can result only as integers.

CP


Go to Top of Page

peter.cook

UK
356 Posts

Posted - 04/19/2004 :  08:00:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CP,

Thanks for reply.

Without enough expertise in C/C++ I couldn't understand why one method worked and the other didn't. Still surprised but will modify/check code accordingly.

Cheers,

Pete

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000