Re: IDL strplit : split a decimal number [message #40005] |
Wed, 07 July 2004 09:08 |
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  |
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  |
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 #40015 is a reply to message #40014] |
Wed, 07 July 2004 03:37  |
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.
|
|
|