官术网_书友最值得收藏!

Elementary mathematical functions and operations

You can view the binary representation of any number (integer or float) with the bitstring function, for example, bitstring(3) returns "0000000000000000000000000000000000000000000000000000000000000011".

To round a number, use the round() function which returns a floating point number. All standard mathematical functions are provided, such as sqrt(), cbrt(), exp(), log(), sin(), cos(), tan(), erf() (the error function), and many more (refer to the URL mentioned at the end of this section). To generate a random number, use rand().

Use parentheses ( ) around expressions to enforce precedence. Chained assignments, such as a = b = c = d = 1, are allowed. The assignments are evaluated right-to-left. Assignments for different variables can be combined, as shown in the following example:

 a = 1; b = 2; c = 3; d = 4 
 a, b = c, d 

Now, a has a value of 3 and b has a value of 4. In particular, this makes an easy swap possible:

  a, b = b, a   # now a is 4 and b is 3 

Like in many other languages, the Boolean operators working on the true and false values for and, or, and not have &&, ||, and ! as symbols, respectively. Julia applies a short-circuit optimization here. That means the following:

  • In a && b, b is not evaluated when a is false (since && is already false)
  • In a || b, b is not evaluated when a is true (since || is already true)

The operators & and | are also used for non-short-circuit Boolean evaluations.

Julia also supports bitwise operations on integers. Note that n++ or n-- with n as an integer does not exist in Julia, as it does in C++ or Java. Use n += 1 or n -= 1 instead.

For more detailed information on operations, such as the bitwise operators, special precedence, and so on, refer to http://docs.julialang.org/en/latest/manual/mathematical-operations/.

主站蜘蛛池模板: 海原县| 顺义区| 信阳市| 井冈山市| 怀宁县| 肇庆市| 清新县| 静乐县| 滁州市| 嘉鱼县| 卢湾区| 若尔盖县| 建德市| 天气| 赫章县| 卫辉市| 临颍县| 湖南省| 江油市| 承德市| 聂拉木县| 玉树县| 色达县| 泰宁县| 伊宁县| 湟源县| 上杭县| 温州市| 临夏县| 安宁市| 福建省| 施甸县| 堆龙德庆县| 铁力市| 梧州市| 麻栗坡县| 通化市| 南岸区| 宁津县| 龙陵县| 温宿县|