JavaScript Math 对象的参考手册

本文详细介绍了JavaScript中的Math对象,包括它的属性如PI、E等,以及常用的方法如abs、sin、sqrt等。这些属性和方法可以帮助开发者执行各种数学计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Math 对象

Math 对象用于执行数学任务。

使用 Math 的属性和方法的语法:

var pi_value=Math.PI;
var sqrt_value=Math.sqrt(15);

注释:Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(),像 Math.sin() 这样的函数只是函数,不是某个对象的方法。您无需创建它,通过把 Math 作为对象使用就可以调用其所有属性和方法。

Math 对象属性

FF: Firefox, IE: Internet Explorer

属性 描述 FF IE
E 返回算术常量 e,即自然对数的底数(约等于2.718)。 1 3
LN2 返回 2 的自然对数(约等于0.693)。 1 3
LN10 返回 10 的自然对数(约等于2.302)。 1 3
LOG2E 返回以 2 为底的 e 的对数(约等于 1.414)。 1 3
LOG10E 返回以 10 为底的 e 的对数(约等于0.434)。 1 3
PI 返回圆周率(约等于3.14159)。 1 3
SQRT1_2 返回返回 2 的平方根的倒数(约等于 0.707)。 1 3
SQRT2 返回 2 的平方根(约等于 1.414)。 1 3

Math 对象方法

FF: Firefox, IE: Internet Explorer

方法 描述 FF IE
abs(x) 返回数的绝对值。 1 3
acos(x) 返回数的反余弦值。 1 3
asin(x) 返回数的反正弦值。 1 3
atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。 1 3
atan2(y,x) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。 1 3
ceil(x) 对数进行上舍入。 1 3
cos(x) 返回数的余弦。 1 3
exp(x) 返回 e 的指数。 1 3
floor(x) 对数进行下舍入。 1 3
log(x) 返回数的自然对数(底为e)。 1 3
max(x,y) 返回 x 和 y 中的最高值。 1 3
min(x,y) 返回 x 和 y 中的最低值。 1 3
pow(x,y) 返回 x 的 y 次幂。 1 3
random() 返回 0 ~ 1 之间的随机数。 1 3
round(x) 把数四舍五入为最接近的整数。 1 3
sin(x) 返回数的正弦。 1 3
sqrt(x) 返回数的平方根。 1 3
tan(x) 返回角的正切。 1 3
toSource() 返回该对象的源代码。 1 -
valueOf() 返回 Math 对象的原始值。 1 4
<?php $show_title="$MSG_LOGIN - $OJ_NAME"; ?> <?php include("template/$OJ_TEMPLATE/header.php");?> <div class="ui error message" id="error" hidden></div> <div class="ui middle aligned center aligned grid" style="height: 500px;" > <div class="row"> <div class="column" style="max-width: 450px"> <h2 class="ui image header"> <div class="content" style="margin-bottom: 10px; "> <?php echo $MSG_LOGIN ?> </div> </h2> <form class="ui large form" id="login" action="login.php" method="post" role="form" class="form-horizontal" onSubmit="return jsMd5();" > <div class="ui existing segment"> <div class="field"> <div class="ui left icon input"> <i class="user icon"></i> <input name="user_id" placeholder="<?php echo $MSG_USER_ID ?>" type="text" id="username"> </div> </div> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="password" placeholder="<?php echo $MSG_PASSWORD ?>" type="password" id="password"> </div> </div> <?php if($OJ_VCODE){?> <div class="field"> <div class="ui left icon input"> <i class="lock icon"></i> <input name="vcode" placeholder="<?php echo $MSG_VCODE ?>" type="text" autocomplete=off > <img id="vcode-img" onclick="this.src='vcode.php?'+Math.random()" height="30px"> </div> </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> 1,1 Top </div> <?php }?> <button name="submit" type="submit" class="ui fluid large submit button" ><?php echo $MSG_LOGIN ?></button> </div> <div class="ui error message"></div> </form> <div class="ui message"> <?php if ($OJ_REGISTER){ ?> <a href="registerpage.php"><?php echo $MSG_REGISTER ?></a>            <?php } ?> </div> </div> </div> </div> <script src="<?php echo $OJ_CDN_URL?>include/md5-min.js"></script> <script> function jsMd5(){ if($("input[name=password]").val()=="") return false; $("input[name=password]").val(hex_md5($("input[name=password]").val())); return true; } </script> <?php if ($OJ_VCODE) { ?> <script> $(document).ready(function () { $("#vcode-img").attr("src", "vcode.php?" + Math.random()); }) </script> <?php } ?> <?php include("template/$OJ_TEMPLATE/footer.php");?>
最新发布
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值