2008年12月14日

Math:常數

常數 | 函數

Math 是系統內建的物件實體,包括數學運算的常數與函數。Math 不是物件製造器,不能用來產生物件實體。Math 的常數都是全精度的實數,且是唯讀常數。可以配合 with(Math) { ... } 使用。

E LN2 LN10 LOG2E LOG10E
PI SQRT1_2 SQRT2
Math 物件實體的常數
E

尤拉常數(Euler's constant),自然對數的底數。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.E );
    </script>

  • 執行結果:

    2.718281828459045

LN2

2 的自然對數,log(2)。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.LN2 );
    </script>

  • 執行結果:

    0.6931471805599453

LN10

10 的自然對數,log(10)。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.LN10 );
    </script>

  • 執行結果:

    2.302585092994046

LOG2E

以 2 為底數的對數,求 E 的值;log2(E)。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.LOG2E );
    </script>

  • 執行結果:

    1.4426950408889634

LOG10E

以 10 為底數的對數,求 E 的值;log10(E)。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.LOG10E );
    </script>

  • 執行結果:

    0.4342944819032518

PI

圓周率。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.PI );
    </script>

  • 執行結果:

    3.141592653589793

SQRT1_2

1/2 的平方根。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.SQRT1_2 );
    </script>

  • 執行結果:

    0.7071067811865476

SQRT2

2 的平方根。

  • 程式用法:

    <script type='text/javascript'>
    document.write( Math.SQRT2 );
    </script>

  • 執行結果:

    1.4142135623730951


©2008-2009 by ant2legs, All Rights Reserved. ant2legs 擁有其製作的文章,圖片與程式的著作權,所有權利保留。