サイト内検索

Math メソッド一覧

スポンサー

ホーム > Math > sqrt

sqrt

平方根を返します.

シンタックス

Math.sqrt(x)
  • x - 数値

解説

sqrtメソッドはxの平方根を返します.
xが負の値である場合,sqrtメソッドはNaNを返します.

サンプルコード

以下にsqrtメソッドを使用したサンプルコードを示します.

<html>
  <head>
    <title>sqrtメソッドのサンプルコード</title>
  </head>
  <body>
    <script type="text/javascript" language="javascript">
      document.write(Math.sqrt(0, 0) + "<br />");
      document.write(Math.sqrt(0, 1) + "<br />");
      document.write(Math.sqrt(2, 2) + "<br />");
      document.write(Math.sqrt(-2, 2) + "<br />");
      document.write(Math.sqrt(-2, 3) + "<br />");
    </script>
  </body>
</html>

実行例

サンプルコードの実行結果は以下のようになります.

1
0
4
4
-8

関連項目

スポンサード リンク

inserted by FC2 system