August 11, 2022, 06:32:35 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

possible problem with operators or long chain calculations

Started by John S, May 29, 2007, 09:07:53 AM

0 Members and 1 Guest are viewing this topic.

John S

May 29, 2007, 09:07:53 AM
Paul,
I had some trouble with this and I finally got it to work though it wasn't pretty.

This works:
`... TPhiT = TanD(45+NewPhi/2); Q3t = 4 *  Q11 * (TPhiT^1.5-1)/(TPhiT^2-1) / 3;   // Stress 3, Zone t...`

This didn't work:
`... Q3t = 4/3*Q11*((TanD(45+PhiNew/2))^1.5-1) / ((TanD(45+PhiNew/2))^2-1);   // Stress 3, Zone t...`

Near as I can figure it, there was at least one may be two problems.  The  4/3*Q1  part didn't seem to calc out correctly and I think there was a problem with the  (TanD(45+PhiNew/2))^1.5 part.  I don't know if the calculation became too large for a single line or if the compiler messed up on the order of operations.  I monkeyed around with parenthesis to no avail.
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

May 29, 2007, 09:17:17 AM #1
4/3 = 1 if you don't force elevation to float or double.   It is explained fairly well in the Emergence manual, just not in the Aurora guide yet.  The compiler always picks the highest precision of the operands in a mathematical operation for the result type.

4/3 = Integer result
4/3.0 = double result
4.0/3 = double result
4/3f = float result

Precedence is listed in the tutorial, TPhiT is a double type so the left hand of your working equation becomes a double type.  The the /3 comes last and the result is a double.

Equations are evaluated in order of parenthsis, precedence, and then left to right.

Paul.
Ionic Wind Support Team

John S

May 29, 2007, 10:10:13 AM #2
o.k., thanks for the explanation.  I was really going nuts trying to find the error in my results.  I kept looking at the equations and everything looked o.k. but it didn't come out right.  I'll have to chase though some 4000 lines of code now and make sure that same kind of error isn't elsewhere.

Can you add something like the f for doubles?  like 4d?
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

May 29, 2007, 10:14:08 AM #3
I could but just the 4.0 makes it a double without a modifier
Ionic Wind Support Team

John S

May 29, 2007, 11:26:04 AM #4
I have a lot of equation like:
double someDouble;
someOtherDoble = someDouble^2;

Should the 2 be a 2.0?
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

May 29, 2007, 11:27:36 AM #5
no.   ^ is a double precision operator.  The result is always a double.

It is usually only division where you would need to be concerned about it.
Ionic Wind Support Team

John S

May 29, 2007, 11:32:24 AM #6
thanks Paul
John Siino, Advanced Engineering Services and Software