convert to scientific notation

James Hurley jhurley0305 at sbcglobal.net
Tue Apr 21 02:18:18 EDT 2009


>
> Message: 3
> Date: Mon, 20 Apr 2009 16:53:05 -0700
> From: Randall Lee Reetz <randall at randallreetz.com>
> Subject: convert to scientific notation
> To: How to use Revolution <use-revolution at lists.runrev.com>
> Message-ID: <F40AB9D0-D69A-4D6D-A106-FAFAD24C7036 at randallreetz.com>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
> I can't remember how to use power function "^" to find the nth root
> of a number.  To find the 2ndth root of a number we can use the "sqrt
> ()" function.  But to find the nth root????
>
> For instance, lets say I want to convert a number to scientific
> notation (the 10th root of that number)... I used to know how to use
> the power function to do this.  Anyone remember how to do it?
>
> I tried to get the 10th root (scientific notation) of 100  (which
> should = 2) by:     100^(1/10) ... but that isn't it.
>
> Any ideas?  I feel brain dead.
>
> Randall
>

Randall,

Here is the function I have always used--see Turtle Graphics

function sci tNum,sigFigures
   if tNum < 0 then
     put "-" into sign
   else put empty into sign
   put abs(tNum) into tNum
   if sigFigures is empty then put 3 into sigFigures    --Default  
significant figures.
   put 0 into count
   if tNum >= 1 then
     repeat until tNum < 10
       divide tNum by 10
       add 1 to count
     end repeat
     put round((10^(sigFigures-1))*tNum)/10^(sigFigures-1) into tNum
     return sign & (char 1 to sigFigures + 1 of tNum) &"*10^" & count
   end if
   if tNum < 1 then
     repeat until tNum >= 1
       multiply tNum by 10
       add 1 to count
     end repeat
   end if
   return sign & (char 1 to sigFigures + 1 of tNum) & "*10^-" & count
end sci

For example:

put sci(23346.445443,4)

gives 2.335*10^4

Brute force, but functional.

Jim Hurley





More information about the use-livecode mailing list