- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 333字
- 2021-06-24 14:21:42
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/.
- Python快樂編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- JavaScript+DHTML語法與范例詳解詞典
- 零基礎(chǔ)學(xué)C++程序設(shè)計
- Python自動化運維快速入門(第2版)
- SQL Server 2012數(shù)據(jù)庫管理與開發(fā)項目教程
- Python機器學(xué)習(xí)算法與實戰(zhàn)
- Oracle Exadata專家手冊
- 數(shù)據(jù)結(jié)構(gòu)習(xí)題解析與實驗指導(dǎo)
- 快速入門與進階:Creo 4·0全實例精講
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- Spring 5 Design Patterns
- Xamarin Blueprints
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- Microsoft HoloLens By Example
- HTML5+CSS3+jQuery Mobile+Bootstrap開發(fā)APP從入門到精通(視頻教學(xué)版)