Re: Type of array to store large numbers [message #80265] |
Fri, 25 May 2012 07:02 |
Carsten Lechte
Messages: 124 Registered: August 2006
|
Senior Member |
|
|
On 25/05/12 15:07, Sir Loin Steak wrote:
> Sorry, what I meant was I want to write the data to a file for another
> program to read, but the data were always output in the form 401.480.
If you want to save a number in full precision (e.g. when saving the
state of some numerical code), simply increasing the number of
significant digits is wasteful and does not work for numbers that are
not representable in the decimal system.
You can look at binary formats, like HDF5 (look for routines starting
with H5_ in the idl help).
If you want to stay within the more universally readable ascii realm,
ANSI C defines a formatting code "%a" that writes an exact
representation of the floating point number, using hex for the
mantissa and decimal for the exponent. Unfortunately, IDL 6.4's
printf-style format codes do not implement this.
If you just want a little more precision, use the format code as you
mentioned.
chl
|
|
|
Re: Type of array to store large numbers [message #80266 is a reply to message #80265] |
Fri, 25 May 2012 06:36  |
Russell Ryan
Messages: 122 Registered: May 2012
|
Senior Member |
|
|
On May 25, 9:07 am, Sir Loin Steak <lj...@fsmail.net> wrote:
> On May 25, 1:58 pm, Fab <fabien.mauss...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>> On 05/25/2012 02:50 PM, Sir Loin Steak wrote:
>
>>> Hi all
>
>>> I have a lot of numbers that have high precision (such as 401.4798584)
>>> and I am trying to find what sort of array to use to store these
>>> values. Can anyone help? I've tried floats, doubles etc, and none keep
>>> the precision to more than 5 d.p. Am I missing something obvious, or
>>> is what I'm after impossible?!!
>
>> What do you mean with "keep" the precision?
>
>> IDL> f = 401.4798584
>> IDL> d = 401.4798584d
>> IDL> print, f
>> 401.480
>> IDL> print, d
>> 401.47986
>> IDL> print, f, FORMAT='(F12.8)'
>> 401.47985840
>> IDL> print, d, FORMAT='(F12.8)'
>> 401.47985840
>
>> http://www.idlcoyote.com/math_tips/sky_is_falling.html
>
>> Cheers
>
> Sorry, what I meant was I want to write the data to a file for another
> program to read, but the data were always output in the form 401.480.
> I never thought about specifying with a format statement! I'll give it
> a go now.
>
> Thanks for the help.
I think you missed the point of the previous post. When you declare
something as a double, IDL keeps that precision but doesn't print it
out when you say print. You need to use a formatted print statement
to "see" all those extra digits.
The bottom line is, they're there. You just aren't seeing them. And
do read that article by Fanning.
|
|
|
Re: Type of array to store large numbers [message #80267 is a reply to message #80266] |
Fri, 25 May 2012 06:07  |
Sir Loin Steak
Messages: 42 Registered: January 2012
|
Member |
|
|
On May 25, 1:58 pm, Fab <fabien.mauss...@gmail.com> wrote:
> On 05/25/2012 02:50 PM, Sir Loin Steak wrote:
>
>> Hi all
>
>> I have a lot of numbers that have high precision (such as 401.4798584)
>> and I am trying to find what sort of array to use to store these
>> values. Can anyone help? I've tried floats, doubles etc, and none keep
>> the precision to more than 5 d.p. Am I missing something obvious, or
>> is what I'm after impossible?!!
>
> What do you mean with "keep" the precision?
>
> IDL> f = 401.4798584
> IDL> d = 401.4798584d
> IDL> print, f
> 401.480
> IDL> print, d
> 401.47986
> IDL> print, f, FORMAT='(F12.8)'
> 401.47985840
> IDL> print, d, FORMAT='(F12.8)'
> 401.47985840
>
> http://www.idlcoyote.com/math_tips/sky_is_falling.html
>
> Cheers
Sorry, what I meant was I want to write the data to a file for another
program to read, but the data were always output in the form 401.480.
I never thought about specifying with a format statement! I'll give it
a go now.
Thanks for the help.
|
|
|
Re: Type of array to store large numbers [message #80268 is a reply to message #80267] |
Fri, 25 May 2012 05:58  |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 05/25/2012 02:50 PM, Sir Loin Steak wrote:
> Hi all
>
> I have a lot of numbers that have high precision (such as 401.4798584)
> and I am trying to find what sort of array to use to store these
> values. Can anyone help? I've tried floats, doubles etc, and none keep
> the precision to more than 5 d.p. Am I missing something obvious, or
> is what I'm after impossible?!!
What do you mean with "keep" the precision?
IDL> f = 401.4798584
IDL> d = 401.4798584d
IDL> print, f
401.480
IDL> print, d
401.47986
IDL> print, f, FORMAT='(F12.8)'
401.47985840
IDL> print, d, FORMAT='(F12.8)'
401.47985840
http://www.idlcoyote.com/math_tips/sky_is_falling.html
Cheers
|
|
|