[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unsigned int woes (was: JULDAY 5.4 not same as 5.3?)

Craig Markwardt wrote:
> pit@phys.uu.nl (Peter Suetterlin) writes:
> ...
> > I'm still not sure who's to blame, me (i.e. the programmer) or
> > IDL/RSI, but in general it does not make sense to take a negative of a
> > unsigned number, and IMHO there should also occur an automatic type
> > conversion as soon as a minus sign is involved.  Currently, you get e.g.
> >
> > IDL> x=5b
> > IDL> print,-x
> >  251
> We can argue all day about what is correct mathematically. [...]

Well, not always. There are definitively cases where IDL produces a
mathematically incorrect result. Try this:

print, (-1L)*2UL, 2UL*(-1L)  

    Maybe, kids don't learn this in school any more, but there are
several textbooks on mathematics that indicate that you should get the
same answer in both cases. Well.... the answers are  -2  4294967294

    Perhaps it is best not to consider unsigned types as "numbers" in
the streetwise sense, i.e. entities that you can use for computations.
They are good as counters or addresses, that's it. So, in the original
post: what drove you to use unsigned longs as argument for julday in
the first place? Question to RSI: how hard would it be to generate an
overflow error whenever an unsigned type variable goes below zero?
Mathematically, that would probably be the most correct solution.



PS: Converting the type automatically would in my opinion make things
easier and more in line with how IDL handles other data types. It
would make things slower but it would take away one severe possible
pitfall from the users (not programmers!). Once more, it would be
interesting to learn for whom IDL is really made: is it scientists who
want a powerful, easy-to-use visualisation software that they can
"customize" by grouping statements together as a "code", or is it
programmers who are supposedly hired by scientists to develop
easy-to-use visualisation software and who could not live without
unsigned types, "break" statements, etc. As the answer is probably:
both - I think that's exactly where the problem is. There are some IDL
routines that obviously cater more to the programmer and others that
are simple enough (too simple) so they can be used by scientists. And
the two worlds don't always harmonize. ...and then there is history

[[ Dr. Martin Schultz   Max-Planck-Institut fuer Meteorologie    [[
[[                      Bundesstr. 55, 20146 Hamburg             [[
[[                      phone: +49 40 41173-308                  [[
[[                      fax:   +49 40 41173-298                  [[
[[ martin.schultz@dkrz.de                                        [[