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

Home » Public Forums » archive » Re: IDL strplit : split a decimal number
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: IDL strplit : split a decimal number [message #40005] Wed, 07 July 2004 09:08
mwvogel is currently offline  mwvogel
Messages: 9
Registered: February 2003
Junior Member
"Paolo Grigis" <pgrigis@astro.phys.ethz.ch> schreef in bericht
news:40ec199f$1@pfaff2.ethz.ch...
>
> It is slightly confusing, however, that IDL
>
> IDL> print,!dpi,format='(D50.40)'
> 3.1415926535897931159979634685441851615906
>
> makes up some nonsense digits after reaching the machine precision
> limit.
>
> I guess I would have preferred a "simpler" output like
> 3.14159265358979300000000000000000000... when one can easily
> spot that the double precision limit is reached at the 15th
> digit.
>

Now, this is what happens on my machine { x86 (AMD Athlon) Win32 Windows 5.4
Sep 25 2000 32 64} :
IDL> print,!dpi,format='(D50.40)'
3.1415926535897931000000000000000000000000

Alternatively, I think RSI has made the E format specifier to limit the
number to machine precision.
IDL> print,!dpi,format='(E)'
3.1415926535897931E+000
Re: IDL strplit : split a decimal number [message #40007 is a reply to message #40005] Wed, 07 July 2004 08:41 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
mwvogel wrote:
> Alternatively, you could use the format syntax
>
> IDL> PRINT, '['+STRSPLIT( STRING(DOUBLE(!pi), FORMAT='(D)'), '.',
> /EXTRACT)+']'
> [ 3] [1415927410125732]

But, last time I checked, pi was equal to 3.14159265358979323846...
try !dpi instead.

It is slightly confusing, however, that IDL

IDL> print,!dpi,format='(D50.40)'
3.1415926535897931159979634685441851615906

makes up some nonsense digits after reaching the machine precision
limit.

I guess I would have preferred a "simpler" output like
3.14159265358979300000000000000000000... when one can easily
spot that the double precision limit is reached at the 15th
digit.

Cheers,
Paolo
Re: IDL strplit : split a decimal number [message #40011 is a reply to message #40007] Wed, 07 July 2004 07:57 Go to previous message
mwvogel is currently offline  mwvogel
Messages: 9
Registered: February 2003
Junior Member
Alternatively, you could use the format syntax

IDL> PRINT, '['+STRSPLIT( STRING(DOUBLE(!pi), FORMAT='(D)'), '.',
/EXTRACT)+']'
[ 3] [1415927410125732]


"bru" <bruno.galand@boost-technologies.com> schreef in bericht
news:afdbccba.0407070153.3d45d1a4@posting.google.com...
> Hi,
>
> I'm a new IDL user and I have problems using the function STRSPLIT.
> Actually, I need to split a float number to seperate the FLOOR part
> from the decimal one.
> For example, let's take A = 147.123456789d
> I need to make an 2D integer array called B, containing the two parts
> of A seperated by the dot ... B(0) = 147 and B(1) = 123456789 ... with
> all this accuracy.
> But writing such thing as:
> B = strsplit(a, '.', /extr)
> is not accurate enough, since it only returns:
> B(0) = 147 and B(1) = 12346
> I thought it was only the 'print' function which returns an
> approximation of B(1), but if I write B(1)-12346, it returns 0 ... and
> if I try B(1)-123456789, it returns -123444443
>
> Can any one help me with this?
> Maybe I shouldn't use the STRSPLIT function to do this?
> Maybe I don't use this function correctly ...
> Thank you for all remarks.
> Bruno
Re: IDL strplit : split a decimal number [message #40014 is a reply to message #40011] Wed, 07 July 2004 06:32 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ben Panter writes:

> Blimey. And to think that a year ago I was worried about the sky falling
> in with doubles and floats.

Amazing what you can find on the Internet, isn't it! :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: IDL strplit : split a decimal number [message #40015 is a reply to message #40014] Wed, 07 July 2004 03:37 Go to previous message
Ben Panter is currently offline  Ben Panter
Messages: 102
Registered: July 2003
Senior Member
> For example, let's take A = 147.123456789d
> I need to make an 2D integer array called B, containing the two parts
> of A seperated by the dot ... B(0) = 147 and B(1) = 123456789 ... with

<snip>

> Maybe I shouldn't use the STRSPLIT function to do this?

How about not using strsplit?

IDL> a=123.45434362d

IDL> print, floor(a)
123

IDL> print, a-floor(a)
0.45434362

IDL> print, (a-floor(a))*1e8
45434362.

so b[0]=long(floor(a)) and
b[1]=long((a-floor(a))*1e8)

Note - I've used longs rather than ints as the double precision will be
larger than the point where ints go round again (~32k).

Ben

Blimey. And to think that a year ago I was worried about the sky falling
in with doubles and floats.

--
Ben Panter, Edinburgh
My name (no spaces)@bigfoot which is a com.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Rebinning large array
Next Topic: Re: IDL strplit : split a decimal number -errata

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

Current Time: Wed Oct 08 17:03:29 PDT 2025

Total time taken to generate the page: 0.00767 seconds