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

Home » Public Forums » archive » Floats
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
Floats [message #47862] Wed, 08 March 2006 12:52 Go to next message
Liberum is currently offline  Liberum
Messages: 48
Registered: September 2005
Member
Hello,

Here is a silly question: Can I define a float array and control how
many decimal places are kept? For example, I want all values to only
have an accuracy to the nearest 100th (20.15 and not 20.154983445).
Kind of like in printing, you know, the f5.2 print definition, but only
for variables and arrrays.

Thanks,
Sheldon
Re: Floats [message #47936 is a reply to message #47862] Sun, 12 March 2006 00:32 Go to previous message
Liberum is currently offline  Liberum
Messages: 48
Registered: September 2005
Member
Thanks Paul,

I found this out last Friday that the end results change even though
the intermediate looks fine - naturally, as I summed millions more
pixel values. The solution was double().
Now I am back to where I started, looking at double precision values
but I got some answers here to help me quickly assess the results.

Much obliged,
Sheldon
Re: Floats [message #47937 is a reply to message #47862] Sun, 12 March 2006 00:22 Go to previous message
Liberum is currently offline  Liberum
Messages: 48
Registered: September 2005
Member
Thanks Reimar.
Very smart idea.

Sheldon
Re: Floats [message #47944 is a reply to message #47862] Sat, 11 March 2006 04:08 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Sheldon wrote:
> Hello,
>
> Here is a silly question: Can I define a float array and control how
> many decimal places are kept? For example, I want all values to only
> have an accuracy to the nearest 100th (20.15 and not 20.154983445).
> Kind of like in printing, you know, the f5.2 print definition, but only
> for variables and arrrays.
>
> Thanks,
> Sheldon
>

Hi Sheldon

we do this this way

IDL> array = RandomU(-3L, 4, 5)
IDL> print,array
0.897916 0.558249 0.766930 0.589101
0.0603181 0.973112 0.0378892 0.218058
0.142394 0.984703 0.894904 0.947651
0.804079 0.160385 0.208246 0.818130
0.103716 0.741117 0.0134482 0.0960160

IDL> array=float(string(array,format='(F7.2)'))
IDL> print,array
0.900000 0.560000 0.770000 0.590000 0.0600000
0.970000 0.0400000 0.220000
0.140000 0.980000 0.890000 0.950000 0.800000
0.160000 0.210000 0.820000
0.100000 0.740000 0.01000000 0.100000


cheers
Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
Re: Floats [message #47955 is a reply to message #47862] Fri, 10 March 2006 08:45 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Sheldon wrote:
> Boy, you guys really went off on this issue. But it is good.
> Much is revealed about IDL, the art of programming, and, an added
> extra, the personalities of the writers :)
> To answer an earlier question of why I asked. Well, maybe I am just too
> curious about things :)
> I used Matlab before and it had the possibility to limit the precision.
> But I could not control it too much.
> I am working with a large number of arrays and averaging millions of
> pixel values. As a result I am getting rounding errors.
> I stop the program here and there and check the data at different
> points. As such I only want a precision to the nearest hundreth.
> It makes for quick assessment. Silly but,I am still learning :)
> I need to understand more fundemental things about ROUND, FIX, FLOAT,
> and LONG so as to eliminate some of these annoying errors. (Thanks
> David for the info)
> Using double precision seem to be the next step for me.

Ah. You mentioning rounding errors as "annoying" sends up a red flag for me. :o) You
should /expect/ this to occur if you're adding a whole bunch of numbers, and your
algorithm should handle it - especially if the end result is affected (sometimes rounding
errors only show up in intermediate results and the end result is fine.) I don't think use
of ROUND, FIX, FLOAT, and LONG should be considered until the problem is better understood.

You might want to consider using a compensated summation routine to sum your millions of
pixel values to minimise rounding errors. A popular (or, at least, better known) method is
also called Kahan summation. There is also doubly compenated summation which requires the
data being summed to be sorted in ascending order.

Depending on your problem (e.g. sorting the data first may be too onerous), one or the
other should do. (Although maybe the TOTAL function in IDL already does this?)

Anyway, check out chapter 4 of "Accuracy and Stability of Numerical Algorithms" by
Nicholas Higham. Accuarate summation of floating point numbers is exhaustively dealt with.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: Floats [message #47959 is a reply to message #47862] Fri, 10 March 2006 06:27 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <duq5l0$8j6$1@newsreader.mailgate.org>,
Mark Hadfield <m.hadfield@niwa.co.nz> wrote:

> It is sometimes said that Americans don't do irony. This is demonstrably
> false (just listen to any sitcom for 5 minutes--irony flying around the
> room). What they don't do is subtlety.

WHO SAYS WE DON'T DO SUBTLETY?!!! THAT'S THE DUMBEST THING I EVER
HEARD!!! WE ALSO DO HYPERBOLE.

Ken
Re: Floats [message #47964 is a reply to message #47862] Fri, 10 March 2006 01:29 Go to previous message
Liberum is currently offline  Liberum
Messages: 48
Registered: September 2005
Member
Boy, you guys really went off on this issue. But it is good.
Much is revealed about IDL, the art of programming, and, an added
extra, the personalities of the writers :)
To answer an earlier question of why I asked. Well, maybe I am just too
curious about things :)
I used Matlab before and it had the possibility to limit the precision.
But I could not control it too much.
I am working with a large number of arrays and averaging millions of
pixel values. As a result I am getting rounding errors.
I stop the program here and there and check the data at different
points. As such I only want a precision to the nearest hundreth.
It makes for quick assessment. Silly but,I am still learning :)
I need to understand more fundemental things about ROUND, FIX, FLOAT,
and LONG so as to eliminate some of these annoying errors. (Thanks
David for the info)
Using double precision seem to be the next step for me.

/Sheldon
Re: Floats [message #47968 is a reply to message #47862] Thu, 09 March 2006 13:10 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
David Fanning wrote:
> I find if you are going for irony you have to put a "yeah" or
> an "uh" in the sentence. At the very least, you have to
> punctuate with a "!?". It's an art, more than a science. :-)

It is sometimes said that Americans don't do irony. This is demonstrably
false (just listen to any sitcom for 5 minutes--irony flying around the
room). What they don't do is subtlety.

Oops, I forgot ... :-)

--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Floats [message #47980 is a reply to message #47862] Thu, 09 March 2006 06:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth P. Bowman writes:

> Obviously there was insufficient irony in my previous post (... how to
> convey tone of voice?).

I find if you are going for irony you have to put a "yeah" or
an "uh" in the sentence. At the very least, you have to
punctuate with a "!?". It's an art, more than a science. :-)

Cheers,

David

P.S. Let's just say it helps to have a reputation for
nonsense, too. You are falling WAY short in that
category, Ken. :-)

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: accuracy problems
Next Topic: Solaris 10 compatibility

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

Current Time: Sun Oct 12 19:02:56 PDT 2025

Total time taken to generate the page: 3.52102 seconds