Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
In article <4k3mro$72p@newsreader.wustl.edu>, Paritosh Dhawale <paritosh> writes: > Hello, > > I get this dangerous bug rather randomly running > IDL 4.0a on a PowerMac 7500. Any one with similar > problems? IDL fails to return the correct answer > in statement 4. > > IDL> help,yy > YY FLOAT = 35.0000 > IDL> help,last_row > LAST_ROW FLOAT = 89.0000 > IDL> print,last_row-yy > 54.0000 > IDL> print,fix(last_row-yy) > 53 > IDL> print,fix(last_row)-fix(yy) > 54 You have really not provided sufficient information. If you created YY and LAST_ROW by direct assignment, i.e. YY = 35.0 LAST_ROW = 89.0 then I agree that there is a bug. All machines which I know of represent small floating point integers exactly, and there should be no roundoff error on subtraction. However, if YY or LAST_ROW are computed, then they might be slightly different than the values they appear to have, and you are just seeing normal roundoff problems. Whenever you are trying to convert a float which might have some slight roundoff error to an integer like this you should use a function which returns the nearest integer, not the integer value after discarding fractional parts. ____________________________________________________________ Mark Rivers (312) 702-2279 (office) CARS (312) 702-9951 (secretary) Univ. of Chicago (312) 702-5454 (FAX) 5640 S. Ellis Ave. (708) 922-0499 (home) Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
Paritosh Dhawale wrote: > > Hello, > > I get this dangerous bug rather randomly running > IDL 4.0a on a PowerMac 7500. Any one with similar > problems? IDL fails to return the correct answer > in statement 4. > > IDL> help,yy > YY FLOAT = 35.0000 > IDL> help,last_row > LAST_ROW FLOAT = 89.0000 > IDL> print,last_row-yy > 54.0000 > IDL> print,fix(last_row-yy) > 53 > IDL> print,fix(last_row)-fix(yy) > 54 > > Would appreciate any insight. > > Paritosh It may be because FIX truncates rather than rounds to get an integer, so FIX(4.9) returns 4 and not 5. So, as an example, if yy is actually 35.0000000001 and last_row is 89.0000000000, when you subtract them and then FIX you get FIX( 53.9999999999) which is 53. If you FIX them first, you get 89 - 53 which gives 54. So the answer may differ depending on how accurately your machine stores float variables. I think this is a problem in other languages besides IDL. Try using ROUND instead of FIX, as this rounds to the nearest integer, and it should solve the problem. Tim
Paritosh Dhawale wrote: > > Hello, > > I get this dangerous bug rather randomly running > IDL 4.0a on a PowerMac 7500. Any one with similar > problems? IDL fails to return the correct answer > in statement 4. > > IDL> help,yy > YY FLOAT = 35.0000 > IDL> help,last_row > LAST_ROW FLOAT = 89.0000 > IDL> print,last_row-yy > 54.0000 > IDL> print,fix(last_row-yy) > 53 > IDL> print,fix(last_row)-fix(yy) > 54 Ouch! FYI: I *don't* get this error running IDL 4.01b under Solaris. -- Andrew F. Loughe [afl@cdc.noaa.gov, http://cdc.noaa.gov/~afl] University of Colorado, CIRES * Campus Box 449 * Boulder, CO 80309 phone: (303) 492-0707 fax: (303) 497-7013