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

Home » Public Forums » archive » Re: Obtaining exponent from a scientific format number
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Obtaining exponent from a scientific format number [message #30279] Thu, 18 April 2002 01:41 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
Juan I. Cicuendez wrote:

> Hi all,
>
> I have a problem and I am looking for a faster solution:
>
> I have a scientific formatted number (e.g. 6.8977653e-18) and I have
> to split the exponent and number into two parts like this:
> long:68977653
> exp:-25
> where the first factor has to be a long number and the second the
> exponent.
> The exponential factors can algo change.
>
> The solution I came up is to turn the number into strings and then
> byte(mystring), obtaining the position of '.' and 'e' and then back to
> numbers. This seems to be quite slow and since I have a large number
> of data I don't think is very efficient.
>
> Thank you very much in advance, I would appreciate any hints.
>
> Juan


How about a mathematical solution?

IDL> number=6.8977653d-18

IDL> digits=8
IDL> exponent=floor(alog10(number))-(digits-1)
IDL> mantissa=round(number/10.0d0^exponent)
IDL> print,exponent
-25
IDL> print,mantissa
68977653
IDL>

It won't be entirely accurate due to the use of logs and exponentiation,
but it might be close enough (I've used double everywhere to increase
accuracy).


--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Draw a point in 3D graphic object ?
Next Topic: Finding all angles within a range of directions; an algorithm question

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

Current Time: Sat Oct 11 11:07:06 PDT 2025

Total time taken to generate the page: 0.00291 seconds