Re: Explanation received. (re prev. post) [message #3214] |
Mon, 05 December 1994 00:18 |
sigut
Messages: 12 Registered: February 1994
|
Junior Member |
|
|
In article <Pine.SOL.3.91.941202162651.15342D-100000@chroma> Russ
Welti <rwelti@chroma.mbt.washington.edu> writes:
>> The IDL ABS function is a wrapper to the C ABS function. This is the
>> value that is returned by that function. I beleive the reason is
>> that the absolute value is not really defined for byte data. However,
>> I can't really explain what is going on and why it is returning this
>> value. You would see the same behavior in a C program. The solution
>> is to convert your arguements to integers before taking the absolute
>> value.
>
> I guess this makes sense, although I wish the manuals
> made note of it, instead of saying that any type may be used with
> ABS. For example, it mentions passing strings and complexes to ABS.
> Would they also return garbage? Then what's the point?
>
> Maybe it's all so IDL can avoid having a runtime error. But it is
> sometimes hard to track down problems like this when a function
> like ABS returns something *reasonable*, but wrong.
As a matter of fact byte is a byte as long as you don't start doing
arithmetics with it. Once you start with arithmetics, it has to decide
if it is a "signed" or "unsigned" byte. If you want to run it through
the "abs" function, you are implying that it is signed. In that moment
your 244 turns into -12 (signed byte interval is -128 to 127). So I
would argue that the program (IDL or PV-Wave) behaves correctly.
Pehaps there should be a warning given somwhere, that byte arithmetic
might bite you.
George
------------------------------------------------------------ ------------------
George M.Sigut ETH Informatikdienste, Beratung & Schulung, CH-8092 Zurich
Swiss Federal Inst. of Technology, Computing Services, User Support & Training
email: sigut@bs.id.ethz.ch Phone: +41 1 632 5763 Fax: +41 1 632 1225
>>>> >>>>> in case of email problems send the mail to "sigut@acm.org" <<<<<<<<<
------------------------------------------------------------ ------------------
--
------------------------------------------------------------ ------------------
George M.Sigut ETH Informatikdienste, Beratung & Schulung, CH-8092 Zurich
Swiss Federal Inst. of Technology, Computing Services, User Support & Training
email: sigut@bs.id.ethz.ch Phone: +41 1 632 5763 Fax: +41 1 632 1225
>>>> >>>>> in case of email problems send the mail to "sigut@acm.org" <<<<<<<<<
------------------------------------------------------------ ------------------
|
|
|