- CoffeeScript 教程
- CoffeeScript - 主页
- CoffeeScript - 概述
- CoffeeScript - 环境
- CoffeeScript - 命令行实用程序
- CoffeeScript - 语法
- CoffeeScript - 数据类型
- CoffeeScript - 变量
- CoffeeScript - 运算符和别名
- CoffeeScript - 条件表达式
- CoffeeScript - 循环
- CoffeeScript - 推导式
- CoffeeScript - 函数
- CoffeeScript 面向对象
- CoffeeScript - 字符串
- CoffeeScript - 数组
- CoffeeScript - 对象
- CoffeeScript - 范围
- CoffeeScript - 散布运算符
- CoffeeScript - 日期
- CoffeeScript - 数学
- CoffeeScript - 异常处理
- CoffeeScript - 正则表达式
- CoffeeScript - 类和继承
- CoffeeScript 高级
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript 有用资源
- CoffeeScript - 快速指南
- CoffeeScript - 有用资源
- CoffeeScript - 讨论
CoffeeScript 数学 - acos()
说明
acos() 方法接受一个数字并返回它的反余弦(弧度)。它会返回介于 0 和 pi 弧度之间的数字,对应的 x 为 -1 到 1。如果 number 的值超出这个范围,则返回 NaN。
语法
以下是 JavaScript 的 acos() 方法语法。我们可以在 CoffeeScript 代码中使用相同的方法。
Math.acos( x )
示例
下面的示例演示了在 CoffeeScript 中使用 acos() 方法。将此代码保存在名为 math_acos.coffee 的文件中。
value = Math.acos -1
console.log "The arc cosine value of -1 is : " + value
value = Math.acos null
console.log "The arc cosine value of null is : " + value
value = Math.acos 20
console.log "The arc cosine value of 20 is : " + value
打开命令提示符并编译 .coffee 文件,如下所示。
c:\> coffee -c math_acos.coffee
编译后,它会给你以下 JavaScript 代码。
// Generated by CoffeeScript 1.10.0
(function() {
var value;
value = Math.acos(-1);
console.log("The arc cosine value of -1 is : " + value);
value = Math.acos(null);
console.log("The arc cosine value of null is : " + value);
value = Math.acos(20);
console.log("The arc cosine value of 20 is : " + value);
}).call(this);
现在,再次打开命令提示符,并运行 CoffeeScript 文件,如下所示。
c:\> coffee math_acos.coffee
执行后,CoffeeScript 文件会产生以下输出。
The arc cosine value of -1 is : 3.141592653589793 The arc console value of null is : 1.5707963267948966 The arc cosine value of 20 is : NaN
coffeescript_math.htm
广告