Page 1 of 1

Problems with EWISE statement

Posted: Tue Nov 14, 2006 9:07 am
by TedKury
I'm using an EWISE statement in a procedure and it's not working properly. I'm wondering if anyone has any suggestions.

EWISE AUX1(I) = (2/LAGS * (LAGS-I)) ** 2

AUX1 is a local real vector, dim LAGS-1. When LAGS=2, then AUX1 has just one element, 1. That works fine. If I set LAGS to anything else, like 3 or 4, the vector contains all zeros.

Any ideas why?

Posted: Tue Nov 14, 2006 10:11 am
by TomM
The problem is that you are doing integer division here:

2/LAGS

Integer division returns an integer result, with any remainder truncated. So, if LAGS = 3, you are getting:

2/3 = 0.66667

which truncates down to zero.

Assuming you want a fractional result, you need to make one or both terms real rather than integer. Easiest way is to add a decimal to the "2". For example:

EWISE AUX1(I) = (2.0/LAGS * (LAGS-I)) ** 2

Tom Maycock
Estima

Posted: Tue Nov 14, 2006 11:19 am
by TedKury
Ugh. I can't believe I overlooked that.

I also wanted to say that I can't get access to e-mail lists at work, so I think that this forum is a great service.

Thanks, Tom.