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
 All Forums
 Origin Forum
 Origin Forum
 arithmetic operation error

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 04/18/2004 : 10:14:25 AM
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

2   L A T E S T    R E P L I E S    (Newest First)
peter.cook Posted - 04/19/2004 : 08:00:47 AM
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

cpyang Posted - 04/18/2004 : 11:51:04 AM
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



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000