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 #30308 is a reply to message #30307] Wed, 17 April 2002 09:50 Go to previous message
Michael Baca is currently offline  Michael Baca
Messages: 5
Registered: October 1999
Junior Member
Well, part of this will depend on the format of the input number. The easy
way to get the exponent of the number is:

value=6.8977653d-18 ; the d will assign the value to a double
exp_num = floor(alog10(value)) ; works for both positive and negative
exponents

Then you just need to decide you starting position. In your message, you
moved the decimal place 7 positions to the right so the quick method would
be:

exp_num = exp_num - 7 ; moves the decimal 7 places to the right
base_val = floor(value/10.0d^exp_num)

Not fancy, but should do the job. The good news is that this will also work
on an array. So if you have an array of value, you can use the exact same
code and takes minimal effort. Much more efficient than looping over values
and counting positions in a string.

The biggest issue is handling the initial value. You may have problems
keeping track of the 7+ decimal places if not defined properly. My inital
attempts used 6.8977653e-18 and would consistently lose the 3 in the base
number unless I defined the number as above (use d not e). Besides,
recalling my days as a physics TA, do you really know the number that well.
:)

Mike

"Juan I. Cicuendez" <jicicuendez@gmv.es> wrote in message
news:4b04c513.0204170601.64440c58@posting.google.com...
> 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
[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: Sun Oct 12 16:56:10 PDT 2025

Total time taken to generate the page: 1.17794 seconds