A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: base 10 logarithms in Actionscript

  1. #1
    Junior Member
    Join Date
    Nov 2000
    Posts
    4
    I apologize for the duplicate thread, I already posted this in General Help before I saw this forum. Here goes:

    Hi everyone. My math is a little rusty these days. I notice that Flash can compute natural logarithms, but I need to compute a base 10 log. I imagine this could be accomplished using the functions and constants in Flash, but I'm sort of lost. Can anyone give me a hand?

    Or, does anyone else know other good tricks to determine the order of magnitude of a number?

    -Jon

  2. #2
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    I can't personally help, but try searching the Flashcoders archives, it's quite likly to have somthing:

    http://chattyfig.figleaf.com/search.php

  3. #3
    madskool.wordpress.com brutfood's Avatar
    Join Date
    Apr 2002
    Posts
    469

    Just divide

    Math.log(x)/Math.log(10)

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    190
    Yeah.

    Code:
               log e a     ln a
    log n a = --------- = -------
               log e n     ln n
    log e x = ln x = Math.log(x)

    Good luck,
    Martin
    Last edited by Somar; 10-14-2002 at 11:08 PM.

  5. #5
    Senior Member
    Join Date
    Mar 2000
    Posts
    177
    As a Math function:

    Code:
    Math.logBase = function (num, base) {
    	if (base == undefined) base = Math.E;
    	return Math.log (num) / Math.log (base);
    };
    
    // test
    trace (Math.logBase (1000, 10)); // 3
    trace (Math.logBase (.001, 10)); // -3
    trace (Math.logBase (256, 2)); // 8
    New Book: Robert Penner's Programming Flash MX
    Dynamic tweening, color, math, vectors and physics with OOP ActionScript
    http://www.robertpenner.com/profmx
    http://www.amazon.com/exec/obidos/AS...bertpennerc-20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center