comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » IDL mathematics
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: IDL mathematics [message #2898 is a reply to message #2705] Thu, 01 September 1994 05:13 Go to previous message
sjt is currently offline  sjt
Messages: 72
Registered: November 1993
Member
dean@phobos.cira.colostate.edu wrote:

: How come the following expression gives the wrong answer.

: J = 201+((1461*(1994+4799))/4)-(3*((1994+4899)/100)/4)-2465022

: J = -2457713

: It should be:

: J = 201+((1461.*(1994+4799.))/4.)-(3.*((1994+4899.)/100.)/4.)-24 65022.

: J = 16270.5


: Kelly Dean

The problem is IDL's conversion rules. You have two problems here:
a) 1461*(1994+4799) is a combination of 3 ints and is thus evaluated as
an int whereas it needs to be a long or float to get the right answer
b) Division of integers is an integer devide e.g. 3/2 = 1 and 4/5 = 0.

I think the minimal modification to get the right answer is:

J = 201+((1461.*(1994+4799))/4)-(3*((1994+4899)/100.)/4)-2465022
^ ^
--
James Tappin, School of Physics & Space Research
University of Birmingham
sjt@xun8.sr.bham.ac.uk
"If all else fails--read the instructions!"

O__
-- \/`
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: WIDGETS - AGAIN
Next Topic: Re: WIDGETS - AGAIN

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 00:41:52 PDT 2025

Total time taken to generate the page: 0.07198 seconds