Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.idl-pvwave

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2012, 01:33 PM
Helder
Guest
 
Posts: n/a
Default Most significant digit and formatting floating point output

Dear all,
well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).
Here are two versions of the same question:
1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure thisout with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.

2) Long version: I'm analyzing some images and I get results with errors. These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units' and the source data is:
Result = 0.123456789
Error = 0.003456789
The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat = '(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRIM (FirstNonZeroElement,2)+')'
and use "MyFormat" as formatting for the string conversion of both.
(in the above example FirstNonZeroElement should be 3 and MyFormat would be'(f05.3)'.

Thanks in advance for any help.

Cheers,
Helder
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 08-07-2012, 01:44 PM
David Fanning
Guest
 
Posts: n/a
Default Re: Most significant digit and formatting floating point output

Helder writes:

> well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).
> Here are two versions of the same question:
> 1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure this out with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.
>
> 2) Long version: I'm analyzing some images and I get results with errors. These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units' and the source data is:
> Result = 0.123456789
> Error = 0.003456789
> The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat = '(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRIM (FirstNonZeroElement,2)+')'
> and use "MyFormat" as formatting for the string conversion of both.
> (in the above example FirstNonZeroElement should be 3 and MyFormat would be '(f05.3)'.


You might be interested in the Number_Formatter program
in the Coyote Library:

http://www.idlcoyote.com/programs/number_formatter.pro

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Reply With Quote
  #3 (permalink)  
Old 08-07-2012, 02:09 PM
Helder
Guest
 
Posts: n/a
Default Re: Most significant digit and formatting floating point output

On Tuesday, August 7, 2012 3:44:05 PM UTC+2, David Fanning wrote:
> Helder writes:
>
>
>
> > well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).

>
> > Here are two versions of the same question:

>
> > 1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure this out with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.

>
> >

>
> > 2) Long version: I'm analyzing some images and I get results with errors. These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units' and the source data is:

>
> > Result = 0.123456789

>
> > Error = 0.003456789

>
> > The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat ='(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRI M(FirstNonZeroElement,2)+')'

>
> > and use "MyFormat" as formatting for the string conversion of both.

>
> > (in the above example FirstNonZeroElement should be 3 and MyFormat would be '(f05.3)'.

>
>
>
> You might be interested in the Number_Formatter program
>
> in the Coyote Library:
>
>
>
> http://www.idlcoyote.com/programs/number_formatter.pro
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")


Thanks David,
If I understand number_formatter correctly, it accepts a number of decimalsas an input, but it does not determine which one is the first significant digit.

I'm starting to think that I'll have to code this as in your program and look for the first digit that is not a zero or a dot.

Thanks,
Helder
Reply With Quote
  #4 (permalink)  
Old 08-07-2012, 03:37 PM
Craig Markwardt
Guest
 
Posts: n/a
Default Re: Most significant digit and formatting floating point output

On Tuesday, August 7, 2012 9:33:13 AM UTC-4, Helder wrote:
> Dear all,
>
> well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).
>
> Here are two versions of the same question:
>
> 1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure this out with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.
>
>
>
> 2) Long version: I'm analyzing some images and I get results with errors.These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units'and the source data is:
>
> Result = 0.123456789
>
> Error = 0.003456789
>
> The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat = '(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRIM (FirstNonZeroElement,2)+')'
>
> and use "MyFormat" as formatting for the string conversion of both.
>
> (in the above example FirstNonZeroElement should be 3 and MyFormat would be '(f05.3)'.


ALOG10(ABS(X)) should give you this information. But to be general, you need to handle ABS(X) LT 1 and ABS(X) GT 1 separately. And also, the X LT 0 case demands one extra digit for the '-' symbol.

Some extra rounding logic may be needed.

Craig
Reply With Quote
  #5 (permalink)  
Old 08-08-2012, 08:20 PM
Helder
Guest
 
Posts: n/a
Default Re: Most significant digit and formatting floating point output

On Tuesday, August 7, 2012 5:37:31 PM UTC+2, Craig Markwardt wrote:
> On Tuesday, August 7, 2012 9:33:13 AM UTC-4, Helder wrote:
>
> > Dear all,

>
> >

>
> > well, I'm tangled up with something quite stupid, but I don't want to reinvent the wheel (for the 10th time today...).

>
> >

>
> > Here are two versions of the same question:

>
> >

>
> > 1) Short version: given a number such as 0.003456789 how do I get the most significant digit position? I need this number to produce formatted output that would convert the number to simply 0.003. In general I can figure this out with some IFs and stuff like that, but I'm hoping there is a more "elegant" way for this.

>
> >

>
> >

>
> >

>
> > 2) Long version: I'm analyzing some images and I get results with errors. These numbers are floating point and I would like to format the output so that it looks something like this: 'My results are (0.123 +/- 0.003) units' and the source data is:

>
> >

>
> > Result = 0.123456789

>
> >

>
> > Error = 0.003456789

>
> >

>
> > The point is that I need to find the first non-zero element in Error. Then I would use this number in the FORMAT parameter like this: MyFormat ='(f0'+STRTRIM(FirstNonZeroElement+2,2)+'.'+STRTRI M(FirstNonZeroElement,2)+')'

>
> >

>
> > and use "MyFormat" as formatting for the string conversion of both.

>
> >

>
> > (in the above example FirstNonZeroElement should be 3 and MyFormat would be '(f05.3)'.

>
>
>
> ALOG10(ABS(X)) should give you this information. But to be general, you need to handle ABS(X) LT 1 and ABS(X) GT 1 separately. And also, the X LT 0 case demands one extra digit for the '-' symbol.
>
>
>
> Some extra rounding logic may be needed.
>
>
>
> Craig


Hi Craig,
thanks, that is what I was looking for.
Cheers,
Helder
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 12:08 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.