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

Home » Public Forums » archive » Re: Unsigned Integer Math Problem
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Unsigned Integer Math Problem [message #70527] Wed, 21 April 2010 10:19
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
> Clearly, I don't want the minimum x range value to be less
> than zero in this case, but I also don't want to force the
> value to be zero if the minimum I want is somewhat higher
> than this, say 1200. How do I test for this? Clearly, this
> does not work:
>
> min_xrange = (omin - binsize)> 0
>
> Since this number 64810 *is* larger than zero, and WRONG!

what about doing if (omin-binsize) gt omin then min_xrange=0

Jean
Re: Unsigned Integer Math Problem [message #70528 is a reply to message #70527] Wed, 21 April 2010 07:46 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt writes:

> Hi David, I think there is no way to do exactly what you want. But
> this is a "doctor it hurts when I do this" problem. For plotting
> purposes, there is absolutely no harm in upcasting to a signed
> integer, and *then* doing your devious arithmetic.
>
> For that matter, why even bother with integers? For plotting
> purposes, make your calculations in double precision!

Well, as I just discovered in another program where this
same thing occurs, this is exactly what I do. :-(

I brought this up mostly as a cautionary tale about
doing math with unsigned integers. This is the second
time in a week unsigned integers have given me
heartburn.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Unsigned Integer Math Problem [message #70529 is a reply to message #70528] Wed, 21 April 2010 07:37 Go to previous message
liamgumley is currently offline  liamgumley
Messages: 74
Registered: June 2005
Member
David,

If min_xrange is only used for creating the plot, then why not use

min_xrange = long(omin) - long(binsize)

Liam.
---
Practical IDL Programming
http://www.gumley.com/
Re: Unsigned Integer Math Problem [message #70530 is a reply to message #70529] Wed, 21 April 2010 07:34 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Apr 21, 10:12 am, David Fanning <n...@dfanning.com> wrote:
> Folks,
>
> I've run into a problem with my Histoplot code this morning.
>
> It is extremely important to the Histogram command that the
> data type of the BINSIZE argument be the same as the data
> type of the data for which the histogram is being calculated.
> I don't know why this is the case, but it is.
>
> In any case, I'm extremely careful about this. But this
> is giving me a problem when I try to make a histogram plot
> of an image that is stored as unsigned integers (UINT).
>
> Basically, to make my plot I take the output minimum
> and maximum from the histogram command and subtract (or
> add) a full binsize to those numbers to give the X axis
> range of the plot.
>
> My problem is this. The OMIN of the histogram is 0, the
> binsize is 726.
>
>    IDL> help, omin, binsize
>    OMIN            UINT      =        0
>    BINSIZE         UINT      =      726
>
> When I make the calculation for the minimum data range
> of my axis, I do this:
>
>    IDL> min_xrange = omin - binsize
>    IDL> Help, min_xrange
>    MIN_XRANGE      UINT      =    64810
>
> Now, this causes the minimum x range to be larger than the
> maximum x range and results in complete chaos downstream.
>
> Clearly, I don't want the minimum x range value to be less
> than zero in this case, but I also don't want to force the
> value to be zero if the minimum I want is somewhat higher
> than this, say 1200. How do I test for this? Clearly, this
> does not work:
>
>    min_xrange = (omin - binsize) > 0
>
> Since this number 64810 *is* larger than zero, and WRONG!
>
> I guess my real question is this: How do I do arithmetic
> operations with unsigned integers in a way that preserves
> the nature of unsigned integers?
>
> Any ideas on this?

Hi David, I think there is no way to do exactly what you want. But
this is a "doctor it hurts when I do this" problem. For plotting
purposes, there is absolutely no harm in upcasting to a signed
integer, and *then* doing your devious arithmetic.

For that matter, why even bother with integers? For plotting
purposes, make your calculations in double precision!

Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: contour of 2D data
Next Topic: Re: Arc of a circle

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

Current Time: Wed Oct 08 13:31:51 PDT 2025

Total time taken to generate the page: 0.00619 seconds