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

Home » Public Forums » archive » inexplicable LONG() - behaviour
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
inexplicable LONG() - behaviour [message #2874] Tue, 06 September 1994 06:48
frank is currently offline  frank
Messages: 15
Registered: August 1993
Junior Member
Hello,

I'm using IDL 3.1.1 (no update in sight :-( ) under HP-UX.
And there are some strange things happening....
Of course, these are just things that I understand wrong :), so could someone
please explain this behaviour:


IDL. Version 3.1.1 (hp-ux hp_pa).
Copyright 1989-1993, Research Systems, Inc.
All rights reserved. Unauthorized reproduction prohibited.
Installation number: 3063.
Licensed for use by: Johann Wolfgang Goethe-Universitaet, HRZ

X-IDL> print, long(1231231434.1)
1231231488

The last two digits differ quite a bite. O.k. the number is too long,
but why isn't there an error-message like in this example (same number but
first digit):

X-IDL> print, long(2231231434.1)
% Program caused arithmetic error: Floating overflow
% Detected at $MAIN$ (LONG).
2139095040

there still is an result, and the result is still wrong, but at least there's
a message indicating that something went wrong.

Furthermore, I programmed a little routine, that is supposed to return
a rounded value of it's argument (included at the end of this article).
The argument can be integer, long, double, and the result is always long. e.g.

X-IDL> PRINT, ROUNDUP(12345.9867)
13000
X-IDL> PRINT, ROUNDUP(999.67)
1000
X-IDL> PRINT, ROUNDUP(53645)
54000

- just to give you an impression.
Using this function I have the following problem:

X-IDL> PRINT, ROUNDUP(101.1)
109

and it should result to 110. Wow, that's bad. If i leave out the LONG() conversion
of the result at the end of the function, the returned value looks like this:

X-IDL> PRINT, ROUNDUP(101.1)
110.0000

- as it should be, just that the result is DOUBLE instead of LONG as I want it to be.
Just a remark, in this particular version

X-IDL> t = ROUNDUP(101.1)
X-IDL> PRINT, LONG(t)
109

this detour doesn't fix it either. So what's wrong?
Do I miss something with the LONG()-function??
Or is it just 'buggy'?
Should I test every LONG()-result by hand :)?
Any help appreciated. Thanks in advance.



;
; I'm almost embarrassed to post this - what a code!
;
;--------- snip, snip, snip --------------------------

FUNCTION roundup, number

number = DOUBLE(number)

i = 0
REPEAT BEGIN
powercheck = number/10.0^i
i = i+1
ENDREP UNTIL powercheck LT 1

power = i-2
round2power = power - 1

tempvar = ((1-powercheck)*10^(power-round2power+1)) - FIX((1-powercheck)*10^(power-round2power+1))
result = number + (tempvar*10.0^round2power)

PRINT, "RESULT: ", result
PRINT, "DOUBLE: ", DOUBLE(result)
PRINT, "LONG : ", LONG(result)

RETURN, LONG(result)
END

;--------- snip, snip, snip --------------------------
;
; this program gives the following output:
;
; X-IDL> .rnew roundup
; % Compiled module: ROUNDUP.
; X-IDL> PRINT, ROUNDUP(101.1)
; RESULT: 110.00000
; DOUBLE: 110.00000
; LONG : 109
; 109
; X-IDL> PRINT, ROUNDUP(111.1)
; RESULT: 120.00000
; DOUBLE: 120.00000
; LONG : 119
; 119
; X-IDL> PRINT, ROUNDUP(121.1)
; RESULT: 130.00000
; DOUBLE: 130.00000
; LONG : 129
; 129


--
-=-=-=-=-=-=-=-=-=-=-=-=--=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=- =-=-=-=-=-=-=-=-=-=-

Frank Hoffsuemmer E-Mail:frank@chaos.uni-frankfurt.de
Institut fuer Theor. Physik ,__o
Robert-Mayer-Str. 8 -\_<, Office: Phone (49) 69 / 798-3359
D-60054 Frankfurt am Main (*)/'(*) Fax (49) 69 / 798-8354
Germany Home : Phone (49) 69 / 289447

-=-=-=-=-=-=-=-=-=-=-=-=--=-=--=-=-=-=-=-=-=-=-=-=-=-=--=-=- =-=-=-=-=-=-=-=-=-=-
[Message index]
 
Read Message
Previous Topic: test
Next Topic: Keyword_set() (was: Re: Fitting curves)

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

Current Time: Fri Oct 10 01:37:39 PDT 2025

Total time taken to generate the page: 0.87967 seconds