Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

Elementary mathematical functions and operations


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

To round a number, use the round() or iround() functions: the first returns a floating point number, and the last returns an integer. 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 following URL). 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 value 3 and b has value 4. In particular, this makes an easy swap possible:

    a, b = b, a   # now...