Sophie

Sophie

distrib > Fedora > 20 > x86_64 > by-pkgid > d9f573299e87e886807be879704f0b6e > files > 132

julia-doc-0.3.4-1.fc20.noarch.rpm




<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Mathematical Operations and Elementary Functions &mdash; Julia Language 0.3.4 documentation</title>
  

  
  

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  

  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  
    <link rel="top" title="Julia Language 0.3.4 documentation" href="../index.html"/>
        <link rel="next" title="Complex and Rational Numbers" href="complex-and-rational-numbers.html"/>
        <link rel="prev" title="Integers and Floating-Point Numbers" href="integers-and-floating-point-numbers.html"/> 

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        <a href="http://julialang.org/"><img src="../_static/julia-logo.svg" class="logo"></a>
        <!--
        <a href="../index.html" class="fa fa-home"> Julia Language</a>
        -->
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
        
            <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="getting-started.html#resources">Resources</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables.html#allowed-variable-names">Allowed Variable Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables.html#stylistic-conventions">Stylistic Conventions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#integers">Integers</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#floating-point-numbers">Floating-Point Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#arbitrary-precision-arithmetic">Arbitrary Precision Arithmetic</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#numeric-literal-coefficients">Numeric Literal Coefficients</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#literal-zero-and-one">Literal zero and one</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Mathematical Operations and Elementary Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#arithmetic-operators">Arithmetic Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="#bitwise-operators">Bitwise Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="#updating-operators">Updating operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="#numeric-comparisons">Numeric Comparisons</a></li>
<li class="toctree-l2"><a class="reference internal" href="#elementary-functions">Elementary Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="complex-and-rational-numbers.html">Complex and Rational Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#complex-numbers">Complex Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#rational-numbers">Rational Numbers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="strings.html">Strings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="strings.html#characters">Characters</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#string-basics">String Basics</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#unicode-and-utf-8">Unicode and UTF-8</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#common-operations">Common Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#non-standard-string-literals">Non-Standard String Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#regular-expressions">Regular Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#id3">Byte Array Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="strings.html#version-number-literals">Version Number Literals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="functions.html#argument-passing-behavior">Argument Passing Behavior</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#the-return-keyword">The <tt class="docutils literal"><span class="pre">return</span></tt> Keyword</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#id1">Operators Are Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#operators-with-special-names">Operators With Special Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#anonymous-functions">Anonymous Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#multiple-return-values">Multiple Return Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#varargs-functions">Varargs Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#optional-arguments">Optional Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#keyword-arguments">Keyword Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#evaluation-scope-of-default-values">Evaluation Scope of Default Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#block-syntax-for-function-arguments">Block Syntax for Function Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#further-reading">Further Reading</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="control-flow.html">Control Flow</a><ul>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#compound-expressions">Compound Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#conditional-evaluation">Conditional Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#short-circuit-evaluation">Short-Circuit Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#repeated-evaluation-loops">Repeated Evaluation: Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#exception-handling">Exception Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#tasks-aka-coroutines">Tasks (aka Coroutines)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables-and-scoping.html">Scope of Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#for-loops-and-comprehensions">For Loops and Comprehensions</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#constants">Constants</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="types.html">Types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-declarations">Type Declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#abstract-types">Abstract Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#bits-types">Bits Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#composite-types">Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#immutable-composite-types">Immutable Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#declared-types">Declared Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#tuple-types">Tuple Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-unions">Type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#man-parametric-types">Parametric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-aliases">Type Aliases</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#operations-on-types">Operations on Types</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="methods.html">Methods</a><ul>
<li class="toctree-l2"><a class="reference internal" href="methods.html#defining-methods">Defining Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#method-ambiguities">Method Ambiguities</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#parametric-methods">Parametric Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#note-on-optional-and-keyword-arguments">Note on Optional and keyword Arguments</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="constructors.html">Constructors</a><ul>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#outer-constructor-methods">Outer Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#inner-constructor-methods">Inner Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#incomplete-initialization">Incomplete Initialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#parametric-constructors">Parametric Constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#case-study-rational">Case Study: Rational</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="conversion-and-promotion.html">Conversion and Promotion</a><ul>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#conversion">Conversion</a></li>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#promotion">Promotion</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Modules</a><ul>
<li class="toctree-l2"><a class="reference internal" href="modules.html#summary-of-module-usage">Summary of module usage</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="metaprogramming.html">Metaprogramming</a><ul>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#expressions-and-eval">Expressions and Eval</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#reflection">Reflection</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="arrays.html">Multi-dimensional Arrays</a><ul>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#sparse-matrices">Sparse Matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="linear-algebra.html">Linear algebra</a><ul>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#matrix-factorizations">Matrix factorizations</a></li>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#special-matrices">Special matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="networking-and-streams.html">Networking and Streams</a><ul>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#basic-stream-i-o">Basic Stream I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#working-with-files">Working with Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#a-simple-tcp-example">A simple TCP example</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#resolving-ip-addresses">Resolving IP Addresses</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="parallel-computing.html">Parallel Computing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#data-movement">Data Movement</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#parallel-map-and-loops">Parallel Map and Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#synchronization-with-remote-references">Synchronization With Remote References</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#scheduling">Scheduling</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#constructing-distributed-arrays">Constructing Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-array-operations">Distributed Array Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#shared-arrays-experimental">Shared Arrays (Experimental)</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#clustermanagers">ClusterManagers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="running-external-programs.html">Running External Programs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#quoting">Quoting</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#pipelines">Pipelines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calling-c-and-fortran-code.html">Calling C and Fortran Code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#mapping-c-types-to-julia">Mapping C Types to Julia</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-data-through-a-pointer">Accessing Data through a Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-pointers-for-modifying-inputs">Passing Pointers for Modifying Inputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#garbage-collection-safety">Garbage Collection Safety</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#non-constant-function-specifications">Non-constant Function Specifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#indirect-calls">Indirect Calls</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#calling-convention">Calling Convention</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-global-variables">Accessing Global Variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-julia-callback-functions-to-c">Passing Julia Callback Functions to C</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#c">C++</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#handling-platform-variations">Handling Platform Variations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="interacting-with-julia.html">Interacting With Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#the-different-prompt-modes">The different prompt modes</a></li>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#key-bindings">Key bindings</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#high-level-embedding">High-Level Embedding</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#converting-types">Converting Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#calling-julia-functions">Calling Julia Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#memory-management">Memory Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#working-with-arrays">Working with Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#exceptions">Exceptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html">Packages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#package-status">Package Status</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#adding-and-removing-packages">Adding and Removing Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#installing-unregistered-packages">Installing Unregistered Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#updating-packages">Updating Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#checkout-pin-and-free">Checkout, Pin and Free</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html#package-development">Package Development</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#initial-setup">Initial Setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#generating-a-new-package">Generating a New Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#making-your-package-available">Making Your Package Available</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#publishing-your-package">Publishing Your Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#tagging-package-versions">Tagging Package Versions</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#fixing-package-requirements">Fixing Package Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#man-package-requirements">Requirements Specification</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="performance-tips.html">Performance Tips</a><ul>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-global-variables">Avoid global variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#measure-performance-with-time-and-pay-attention-to-memory-allocation">Measure performance with <tt class="docutils literal"><span class="pre">&#64;time</span></tt> and pay attention to memory allocation</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tools">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-containers-with-abstract-type-parameters">Avoid containers with abstract type parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#type-declarations">Type declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#break-functions-into-multiple-definitions">Break functions into multiple definitions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#write-type-stable-functions">Write &#8220;type-stable&#8221; functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-changing-the-type-of-a-variable">Avoid changing the type of a variable</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#separate-kernel-functions">Separate kernel functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#access-arrays-in-memory-order-along-columns">Access arrays in memory order, along columns</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#pre-allocating-outputs">Pre-allocating outputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-string-interpolation-for-i-o">Avoid string interpolation for I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#fix-deprecation-warnings">Fix deprecation warnings</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tweaks">Tweaks</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#performance-annotations">Performance Annotations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="style-guide.html">Style Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#write-functions-not-just-scripts">Write functions, not just scripts</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-writing-overly-specific-types">Avoid writing overly-specific types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#handle-excess-argument-diversity-in-the-caller">Handle excess argument diversity in the caller</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#append-to-names-of-functions-that-modify-their-arguments">Append <cite>!</cite> to names of functions that modify their arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-strange-type-unions">Avoid strange type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#try-to-avoid-nullable-fields">Try to avoid nullable fields</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-elaborate-container-types">Avoid elaborate container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-underscores-in-names">Avoid underscores in names</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-try-catch">Don&#8217;t overuse try-catch</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-parenthesize-conditions">Don&#8217;t parenthesize conditions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse">Don&#8217;t overuse ...</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-use-unnecessary-static-parameters">Don&#8217;t use unnecessary static parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-confusion-about-whether-something-is-an-instance-or-a-type">Avoid confusion about whether something is an instance or a type</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-macros">Don&#8217;t overuse macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-expose-unsafe-operations-at-the-interface-level">Don&#8217;t expose unsafe operations at the interface level</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overload-methods-of-base-container-types">Don&#8217;t overload methods of base container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#be-careful-with-type-equality">Be careful with type equality</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#do-not-write-x-f-x">Do not write <tt class="docutils literal"><span class="pre">x-&gt;f(x)</span></tt></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="faq.html#sessions-and-the-repl">Sessions and the REPL</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#types-type-declarations-and-constructors">Types, type declarations, and constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#nothingness-and-missing-values">Nothingness and missing values</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#julia-releases">Julia Releases</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#developing-julia">Developing Julia</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="noteworthy-differences.html">Noteworthy Differences from other Languages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-matlab">Noteworthy differences from MATLAB</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-r">Noteworthy differences from R</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-python">Noteworthy differences from Python</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/base.html">The Standard Library</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#introduction">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#getting-around">Getting Around</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#all-objects">All Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#types">Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#generic-functions">Generic Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#syntax">Syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iteration">Iteration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#general-collections">General Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iterable-collections">Iterable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#indexable-collections">Indexable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#associative-collections">Associative Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#set-like-collections">Set-Like Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#dequeues">Dequeues</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#strings">Strings</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#i-o">I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#network-i-o">Network I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#multimedia-i-o">Multimedia I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#memory-mapped-i-o">Memory-mapped I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#standard-numeric-types">Standard Numeric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-operators">Mathematical Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-functions">Mathematical Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#data-formats">Data Formats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numbers">Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#bigfloats">BigFloats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#random-numbers">Random Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#combinatorics">Combinatorics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#statistics">Statistics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#signal-processing">Signal Processing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numerical-integration">Numerical Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#parallel-computing">Parallel Computing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#shared-arrays-experimental-unix-only-feature">Shared Arrays (Experimental, UNIX-only feature)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#system">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#c-interface">C Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#errors">Errors</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#tasks">Tasks</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#events">Events</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#reflection">Reflection</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#internals">Internals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sparse.html">Sparse Matrices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html">Linear Algebra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html#module-Base.LinAlg.BLAS">BLAS Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/constants.html">Constants</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/file.html">Filesystem</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/punctuation.html">Punctuation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sort.html">Sorting and Related Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-functions">Sorting Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#order-related-functions">Order-Related Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-algorithms">Sorting Algorithms</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/pkg.html">Package Manager Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/collections.html">Collections and Data Structures</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#priorityqueue">PriorityQueue</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#heap-functions">Heap Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/graphics.html">Graphics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/graphics.html#geometry">Geometry</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html">Unit and Functional Testing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#overview">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#handlers">Handlers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#functions">Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html#testing-base-julia">Testing Base Julia</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/profile.html">Profiling</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#basic-usage">Basic usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#accumulation-and-clearing">Accumulation and clearing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#options-for-controlling-the-display-of-profile-results">Options for controlling the display of profile results</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#configuration">Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#function-reference">Function reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/julia.html">Documentation of Julia&#8217;s Internals</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/cartesian.html">Base.Cartesian</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/sysimg.html">System Image Building</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/C.html">Developing/debugging Julia&#8217;s C code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li>
</ul>
</li>
</ul>

        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Julia Language</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
    <li>Mathematical Operations and Elementary Functions</li>
      <li class="wy-breadcrumbs-aside">
        
          <a href="../_sources/manual/mathematical-operations.txt" rel="nofollow"> View page source</a>
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document">
            
  <div class="section" id="mathematical-operations-and-elementary-functions">
<span id="man-mathematical-operations"></span><h1>Mathematical Operations and Elementary Functions<a class="headerlink" href="#mathematical-operations-and-elementary-functions" title="Permalink to this headline">¶</a></h1>
<p>Julia provides a complete collection of basic arithmetic and bitwise
operators across all of its numeric primitive types, as well as
providing portable, efficient implementations of a comprehensive
collection of standard mathematical functions.</p>
<div class="section" id="arithmetic-operators">
<h2>Arithmetic Operators<a class="headerlink" href="#arithmetic-operators" title="Permalink to this headline">¶</a></h2>
<p>The following <a class="reference external" href="http://en.wikipedia.org/wiki/Arithmetic#Arithmetic_operations">arithmetic operators</a>
are supported on all primitive numeric types:</p>
<table border="1" class="docutils">
<colgroup>
<col width="16%" />
<col width="23%" />
<col width="61%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Expression</th>
<th class="head">Name</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">+x</span></tt></td>
<td>unary plus</td>
<td>the identity operation</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">-x</span></tt></td>
<td>unary minus</td>
<td>maps values to their additive inverses</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">y</span></tt></td>
<td>binary plus</td>
<td>performs addition</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">y</span></tt></td>
<td>binary minus</td>
<td>performs subtraction</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">y</span></tt></td>
<td>times</td>
<td>performs multiplication</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span></tt></td>
<td>divide</td>
<td>performs division</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">\</span> <span class="pre">y</span></tt></td>
<td>inverse divide</td>
<td>equivalent to <tt class="docutils literal"><span class="pre">y</span> <span class="pre">/</span> <span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">^</span> <span class="pre">y</span></tt></td>
<td>power</td>
<td>raises <tt class="docutils literal"><span class="pre">x</span></tt> to the <tt class="docutils literal"><span class="pre">y</span></tt>th power</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">%</span> <span class="pre">y</span></tt></td>
<td>remainder</td>
<td>equivalent to <tt class="docutils literal"><span class="pre">rem(x,y)</span></tt></td>
</tr>
</tbody>
</table>
<p>as well as the negation on <tt class="docutils literal"><span class="pre">Bool</span></tt> types:</p>
<table border="1" class="docutils">
<colgroup>
<col width="15%" />
<col width="21%" />
<col width="65%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Expression</th>
<th class="head">Name</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">!x</span></tt></td>
<td>negation</td>
<td>changes <tt class="docutils literal"><span class="pre">true</span></tt> to <tt class="docutils literal"><span class="pre">false</span></tt> and vice versa</td>
</tr>
</tbody>
</table>
<p>Julia&#8217;s promotion system makes arithmetic operations on mixtures of argument
types &#8220;just work&#8221; naturally and automatically. See <a class="reference internal" href="conversion-and-promotion.html#man-conversion-and-promotion"><em>Conversion and Promotion</em></a>
for details of the promotion system.</p>
<p>Here are some simple examples using arithmetic operators:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">3</span>
<span class="mi">6</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">-</span> <span class="mi">2</span>
<span class="o">-</span><span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">3</span><span class="o">*</span><span class="mi">2</span><span class="o">/</span><span class="mi">12</span>
<span class="mf">0.5</span>
</pre></div>
</div>
<p>(By convention, we tend to space less tightly binding operators less
tightly, but there are no syntactic constraints.)</p>
</div>
<div class="section" id="bitwise-operators">
<h2>Bitwise Operators<a class="headerlink" href="#bitwise-operators" title="Permalink to this headline">¶</a></h2>
<p>The following <a class="reference external" href="http://en.wikipedia.org/wiki/Bitwise_operation#Bitwise_operators">bitwise
operators</a>
are supported on all primitive integer types:</p>
<table border="1" class="docutils">
<colgroup>
<col width="13%" />
<col width="87%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Expression</th>
<th class="head">Name</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">~x</span></tt></td>
<td>bitwise not</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">&amp;</span> <span class="pre">y</span></tt></td>
<td>bitwise and</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">|</span> <span class="pre">y</span></tt></td>
<td>bitwise or</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">$</span> <span class="pre">y</span></tt></td>
<td>bitwise xor (exclusive or)</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">&gt;&gt;&gt;</span> <span class="pre">y</span></tt></td>
<td><a class="reference external" href="http://en.wikipedia.org/wiki/Logical_shift">logical shift</a> right</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">&gt;&gt;</span> <span class="pre">y</span></tt></td>
<td><a class="reference external" href="http://en.wikipedia.org/wiki/Arithmetic_shift">arithmetic shift</a> right</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">x</span> <span class="pre">&lt;&lt;</span> <span class="pre">y</span></tt></td>
<td>logical/arithmetic shift left</td>
</tr>
</tbody>
</table>
<p>Here are some examples with bitwise operators:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="o">~</span><span class="mi">123</span>
<span class="o">-</span><span class="mi">124</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">123</span> <span class="o">&amp;</span> <span class="mi">234</span>
<span class="mi">106</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">123</span> <span class="o">|</span> <span class="mi">234</span>
<span class="mi">251</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">123</span> <span class="o">$</span> <span class="mi">234</span>
<span class="mi">145</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">~</span><span class="n">uint32</span><span class="p">(</span><span class="mi">123</span><span class="p">)</span>
<span class="mh">0xffffff84</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">~</span><span class="n">uint8</span><span class="p">(</span><span class="mi">123</span><span class="p">)</span>
<span class="mh">0x84</span>
</pre></div>
</div>
</div>
<div class="section" id="updating-operators">
<h2>Updating operators<a class="headerlink" href="#updating-operators" title="Permalink to this headline">¶</a></h2>
<p>Every binary arithmetic and bitwise operator also has an updating
version that assigns the result of the operation back into its left
operand. The updating version of the binary operator is formed by placing a
<tt class="docutils literal"><span class="pre">=</span></tt> immediately after the operator. For example, writing <tt class="docutils literal"><span class="pre">x</span> <span class="pre">+=</span> <span class="pre">3</span></tt> is
equivalent to writing <tt class="docutils literal"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">x</span> <span class="pre">+</span> <span class="pre">3</span></tt>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">+=</span> <span class="mi">3</span>
<span class="mi">4</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span>
<span class="mi">4</span>
</pre></div>
</div>
<p>The updating versions of all the binary arithmetic and bitwise operators
are:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="o">+=</span>  <span class="o">-=</span>  <span class="o">*=</span>  <span class="o">/=</span>  \<span class="o">=</span>  <span class="o">%=</span>  <span class="o">^=</span>  <span class="o">&amp;=</span>  <span class="o">|=</span>  <span class="o">$=</span>  <span class="o">&gt;&gt;&gt;=</span>  <span class="o">&gt;&gt;=</span>  <span class="o">&lt;&lt;=</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>An updating operator rebinds the variable on the left-hand side.
As a result, the type of the variable may change.</p>
<div class="last highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="mh">0x01</span><span class="p">;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="kt">Uint8</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">x</span> <span class="o">*=</span> <span class="mi">2</span> <span class="c">#Same as x = x * 2</span>
<span class="mi">2</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">isa</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kt">Int</span><span class="p">)</span>
<span class="n">true</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="numeric-comparisons">
<span id="man-numeric-comparisons"></span><h2>Numeric Comparisons<a class="headerlink" href="#numeric-comparisons" title="Permalink to this headline">¶</a></h2>
<p>Standard comparison operations are defined for all the primitive numeric
types:</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="75%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Operator</th>
<th class="head">Name</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">==</span></tt></td>
<td>equality</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">!=</span></tt></td>
<td>inequality</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">&lt;</span></tt></td>
<td>less than</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">&lt;=</span></tt></td>
<td>less than or equal to</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">&gt;</span></tt></td>
<td>greater than</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">&gt;=</span></tt></td>
<td>greater than or equal to</td>
</tr>
</tbody>
</table>
<p>Here are some simple examples:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">==</span> <span class="mi">1</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">==</span> <span class="mi">2</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">!=</span> <span class="mi">2</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">==</span> <span class="mf">1.0</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">&lt;</span> <span class="mi">2</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mf">1.0</span> <span class="o">&gt;</span> <span class="mi">3</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">&gt;=</span> <span class="mf">1.0</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&lt;=</span> <span class="mi">1</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&lt;=</span> <span class="o">-</span><span class="mi">1</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&lt;=</span> <span class="o">-</span><span class="mi">2</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="mi">3</span> <span class="o">&lt;</span> <span class="o">-</span><span class="mf">0.5</span>
<span class="n">false</span>
</pre></div>
</div>
<p>Integers are compared in the standard manner — by comparison of bits.
Floating-point numbers are compared according to the <a class="reference external" href="http://en.wikipedia.org/wiki/IEEE_754-2008">IEEE 754
standard</a>:</p>
<ul class="simple">
<li>Finite numbers are ordered in the usual manner.</li>
<li>Positive zero is equal but not greater than negative zero.</li>
<li><tt class="docutils literal"><span class="pre">Inf</span></tt> is equal to itself and greater than everything else except <tt class="docutils literal"><span class="pre">NaN</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">-Inf</span></tt> is equal to itself and less then everything else except <tt class="docutils literal"><span class="pre">NaN</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">NaN</span></tt> is not equal to, not less than, and not greater than anything,
including itself.</li>
</ul>
<p>The last point is potentially surprising and thus worth noting:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">NaN</span> <span class="o">==</span> <span class="n">NaN</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">NaN</span> <span class="o">!=</span> <span class="n">NaN</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">NaN</span> <span class="o">&lt;</span> <span class="n">NaN</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">NaN</span> <span class="o">&gt;</span> <span class="n">NaN</span>
<span class="n">false</span>
</pre></div>
</div>
<p>and can cause especial headaches with <a class="reference internal" href="arrays.html#man-arrays"><em>Arrays</em></a>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="p">[</span><span class="mi">1</span> <span class="n">NaN</span><span class="p">]</span> <span class="o">==</span> <span class="p">[</span><span class="mi">1</span> <span class="n">NaN</span><span class="p">]</span>
<span class="n">false</span>
</pre></div>
</div>
<p>Julia provides additional functions to test numbers for special values,
which can be useful in situations like hash key comparisons:</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%" />
<col width="67%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Tests if</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">isequal(x,</span> <span class="pre">y)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> are identical</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">isfinite(x)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">x</span></tt> is a finite number</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">isinf(x)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">x</span></tt> is infinite</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">isnan(x)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">x</span></tt> is not a number</td>
</tr>
</tbody>
</table>
<p><tt class="docutils literal"><span class="pre">isequal</span></tt> considers <tt class="docutils literal"><span class="pre">NaN</span></tt>s equal to each other:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="nb">isequal</span><span class="p">(</span><span class="n">NaN</span><span class="p">,</span><span class="n">NaN</span><span class="p">)</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">isequal</span><span class="p">([</span><span class="mi">1</span> <span class="n">NaN</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span> <span class="n">NaN</span><span class="p">])</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">isequal</span><span class="p">(</span><span class="n">NaN</span><span class="p">,</span><span class="n">NaN32</span><span class="p">)</span>
<span class="n">true</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">isequal</span></tt> can also be used to distinguish signed zeros:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="o">-</span><span class="mf">0.0</span> <span class="o">==</span> <span class="mf">0.0</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">isequal</span><span class="p">(</span><span class="o">-</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
<span class="n">false</span>
</pre></div>
</div>
<p>Mixed-type comparisons between signed integers, unsigned integers, and
floats can be tricky. A great deal of care has been taken to ensure
that Julia does them correctly.</p>
<p>For other types, <cite>isequal</cite> defaults to calling <cite>==</cite>, so if you want to
define equality for your own types then you only need to add a <cite>==</cite>
method.  If you define your own equality function, you should probably
define a corresponding <cite>hash</cite> function to ensure that <cite>isequal(x,y)</cite>
implies <cite>hash(x) == hash(y)</cite>.</p>
<div class="section" id="chaining-comparisons">
<h3>Chaining comparisons<a class="headerlink" href="#chaining-comparisons" title="Permalink to this headline">¶</a></h3>
<p>Unlike most languages, with the <a class="reference external" href="http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Comparison_operators">notable exception of
Python</a>,
comparisons can be arbitrarily chained:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="mi">1</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="o">&lt;=</span> <span class="mi">2</span> <span class="o">&lt;</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">3</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="o">&gt;=</span> <span class="mi">1</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">&lt;</span> <span class="mi">3</span> <span class="o">!=</span> <span class="mi">5</span>
<span class="n">true</span>
</pre></div>
</div>
<p>Chaining comparisons is often quite convenient in numerical code.
Chained comparisons use the <tt class="docutils literal"><span class="pre">&amp;&amp;</span></tt> operator for scalar comparisons,
and the <tt class="docutils literal"><span class="pre">&amp;</span></tt> operator for elementwise comparisons, which allows them to
work on arrays. For example, <tt class="docutils literal"><span class="pre">0</span> <span class="pre">.&lt;</span> <span class="pre">A</span> <span class="pre">.&lt;</span> <span class="pre">1</span></tt> gives a boolean array whose
entries are true where the corresponding elements of <tt class="docutils literal"><span class="pre">A</span></tt> are between 0
and 1.</p>
<p>Note the evaluation behavior of chained comparisons:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">v</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">println</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="n">x</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">v</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">v</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">v</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="mi">2</span>
<span class="mi">1</span>
<span class="mi">3</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">v</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">v</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">v</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="mi">2</span>
<span class="mi">1</span>
<span class="n">false</span>
</pre></div>
</div>
<p>The middle expression is only evaluated once, rather than twice as it
would be if the expression were written as
<tt class="docutils literal"><span class="pre">v(1)</span> <span class="pre">&lt;</span> <span class="pre">v(2)</span> <span class="pre">&amp;&amp;</span> <span class="pre">v(2)</span> <span class="pre">&lt;=</span> <span class="pre">v(3)</span></tt>. However, the order of evaluations in a
chained comparison is undefined. It is strongly recommended not to use
expressions with side effects (such as printing) in chained comparisons.
If side effects are required, the short-circuit <tt class="docutils literal"><span class="pre">&amp;&amp;</span></tt> operator should
be used explicitly (see <a class="reference internal" href="control-flow.html#man-short-circuit-evaluation"><em>Short-Circuit Evaluation</em></a>).</p>
</div>
<div class="section" id="operator-precedence">
<h3>Operator Precedence<a class="headerlink" href="#operator-precedence" title="Permalink to this headline">¶</a></h3>
<p>Julia applies the following order of operations, from highest precedence
to lowest:</p>
<table border="1" class="docutils">
<colgroup>
<col width="15%" />
<col width="85%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Category</th>
<th class="head">Operators</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Syntax</td>
<td><tt class="docutils literal"><span class="pre">.</span></tt> followed by <tt class="docutils literal"><span class="pre">::</span></tt></td>
</tr>
<tr class="row-odd"><td>Exponentiation</td>
<td><tt class="docutils literal"><span class="pre">^</span></tt> and its elementwise equivalent <tt class="docutils literal"><span class="pre">.^</span></tt></td>
</tr>
<tr class="row-even"><td>Fractions</td>
<td><tt class="docutils literal"><span class="pre">//</span></tt> and <tt class="docutils literal"><span class="pre">.//</span></tt></td>
</tr>
<tr class="row-odd"><td>Multiplication</td>
<td><tt class="docutils literal"><span class="pre">*</span> <span class="pre">/</span> <span class="pre">%</span> <span class="pre">&amp;</span> <span class="pre">\</span></tt> and  <tt class="docutils literal"><span class="pre">.*</span> <span class="pre">./</span> <span class="pre">.%</span> <span class="pre">.\</span></tt></td>
</tr>
<tr class="row-even"><td>Bitshifts</td>
<td><tt class="docutils literal"><span class="pre">&lt;&lt;</span> <span class="pre">&gt;&gt;</span> <span class="pre">&gt;&gt;&gt;</span></tt> and <tt class="docutils literal"><span class="pre">.&lt;&lt;</span> <span class="pre">.&gt;&gt;</span> <span class="pre">.&gt;&gt;&gt;</span></tt></td>
</tr>
<tr class="row-odd"><td>Addition</td>
<td><tt class="docutils literal"><span class="pre">+</span> <span class="pre">-</span> <span class="pre">|</span> <span class="pre">$</span></tt> and <tt class="docutils literal"><span class="pre">.+</span> <span class="pre">.-</span></tt></td>
</tr>
<tr class="row-even"><td>Syntax</td>
<td><tt class="docutils literal"><span class="pre">:</span> <span class="pre">..</span></tt> followed by <tt class="docutils literal"><span class="pre">|&gt;</span></tt></td>
</tr>
<tr class="row-odd"><td>Comparisons</td>
<td><tt class="docutils literal"><span class="pre">&gt;</span> <span class="pre">&lt;</span> <span class="pre">&gt;=</span> <span class="pre">&lt;=</span> <span class="pre">==</span> <span class="pre">===</span> <span class="pre">!=</span> <span class="pre">!==</span> <span class="pre">&lt;:</span></tt> and <tt class="docutils literal"><span class="pre">.&gt;</span> <span class="pre">.&lt;</span> <span class="pre">.&gt;=</span> <span class="pre">.&lt;=</span> <span class="pre">.==</span> <span class="pre">.!=</span></tt></td>
</tr>
<tr class="row-even"><td>Control flow</td>
<td><tt class="docutils literal"><span class="pre">&amp;&amp;</span></tt> followed by <tt class="docutils literal"><span class="pre">||</span></tt> followed by <tt class="docutils literal"><span class="pre">?</span></tt></td>
</tr>
<tr class="row-odd"><td>Assignments</td>
<td><tt class="docutils literal"><span class="pre">=</span> <span class="pre">+=</span> <span class="pre">-=</span> <span class="pre">*=</span> <span class="pre">/=</span> <span class="pre">//=</span> <span class="pre">\=</span> <span class="pre">^=</span> <span class="pre">%=</span> <span class="pre">|=</span> <span class="pre">&amp;=</span> <span class="pre">$=</span> <span class="pre">&lt;&lt;=</span> <span class="pre">&gt;&gt;=</span> <span class="pre">&gt;&gt;&gt;=</span></tt> and <tt class="docutils literal"><span class="pre">.+=</span> <span class="pre">.-=</span> <span class="pre">.*=</span> <span class="pre">./=</span> <span class="pre">.//=</span> <span class="pre">.\=</span> <span class="pre">.^=</span> <span class="pre">.%=</span></tt></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="elementary-functions">
<span id="man-elementary-functions"></span><h2>Elementary Functions<a class="headerlink" href="#elementary-functions" title="Permalink to this headline">¶</a></h2>
<p>Julia provides a comprehensive collection of mathematical functions and
operators. These mathematical operations are defined over as broad a
class of numerical values as permit sensible definitions, including
integers, floating-point numbers, rationals, and complexes, wherever
such definitions make sense.</p>
<div class="section" id="rounding-functions">
<h3>Rounding functions<a class="headerlink" href="#rounding-functions" title="Permalink to this headline">¶</a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="20%" />
<col width="53%" />
<col width="27%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Description</th>
<th class="head">Return type</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">round(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> to the nearest integer</td>
<td><tt class="docutils literal"><span class="pre">FloatingPoint</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">iround(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> to the nearest integer</td>
<td><tt class="docutils literal"><span class="pre">Integer</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">floor(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards <tt class="docutils literal"><span class="pre">-Inf</span></tt></td>
<td><tt class="docutils literal"><span class="pre">FloatingPoint</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">ifloor(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards <tt class="docutils literal"><span class="pre">-Inf</span></tt></td>
<td><tt class="docutils literal"><span class="pre">Integer</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">ceil(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards <tt class="docutils literal"><span class="pre">+Inf</span></tt></td>
<td><tt class="docutils literal"><span class="pre">FloatingPoint</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">iceil(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards <tt class="docutils literal"><span class="pre">+Inf</span></tt></td>
<td><tt class="docutils literal"><span class="pre">Integer</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">trunc(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards zero</td>
<td><tt class="docutils literal"><span class="pre">FloatingPoint</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">itrunc(x)</span></tt></td>
<td>round <tt class="docutils literal"><span class="pre">x</span></tt> towards zero</td>
<td><tt class="docutils literal"><span class="pre">Integer</span></tt></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="division-functions">
<h3>Division functions<a class="headerlink" href="#division-functions" title="Permalink to this headline">¶</a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="83%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">div(x,y)</span></tt></td>
<td>truncated division; quotient rounded towards zero</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">fld(x,y)</span></tt></td>
<td>floored division; quotient rounded towards <tt class="docutils literal"><span class="pre">-Inf</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">rem(x,y)</span></tt></td>
<td>remainder; satisfies <tt class="docutils literal"><span class="pre">x</span> <span class="pre">==</span> <span class="pre">div(x,y)*y</span> <span class="pre">+</span> <span class="pre">rem(x,y)</span></tt>; sign matches <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">divrem(x,y)</span></tt></td>
<td>returns <tt class="docutils literal"><span class="pre">(div(x,y),rem(x,y))</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">mod(x,y)</span></tt></td>
<td>modulus; satisfies <tt class="docutils literal"><span class="pre">x</span> <span class="pre">==</span> <span class="pre">fld(x,y)*y</span> <span class="pre">+</span> <span class="pre">mod(x,y)</span></tt>; sign matches <tt class="docutils literal"><span class="pre">y</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">mod2pi(x)</span></tt></td>
<td>modulus with respect to 2pi;  <tt class="docutils literal"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">mod2pi(x)</span>&nbsp; <span class="pre">&lt;</span> <span class="pre">2pi</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">gcd(x,y...)</span></tt></td>
<td>greatest common divisor of <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt>,...; sign matches <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">lcm(x,y...)</span></tt></td>
<td>least common multiple of <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt>,...; sign matches <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="sign-and-absolute-value-functions">
<h3>Sign and absolute value functions<a class="headerlink" href="#sign-and-absolute-value-functions" title="Permalink to this headline">¶</a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="22%" />
<col width="78%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">abs(x)</span></tt></td>
<td>a positive value with the magnitude of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">abs2(x)</span></tt></td>
<td>the squared magnitude of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">sign(x)</span></tt></td>
<td>indicates the sign of <tt class="docutils literal"><span class="pre">x</span></tt>, returning -1, 0, or +1</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">signbit(x)</span></tt></td>
<td>indicates whether the sign bit is on (true) or off (false)</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">copysign(x,y)</span></tt></td>
<td>a value with the magnitude of <tt class="docutils literal"><span class="pre">x</span></tt> and the sign of <tt class="docutils literal"><span class="pre">y</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">flipsign(x,y)</span></tt></td>
<td>a value with the magnitude of <tt class="docutils literal"><span class="pre">x</span></tt> and the sign of <tt class="docutils literal"><span class="pre">x*y</span></tt></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="powers-logs-and-roots">
<h3>Powers, logs and roots<a class="headerlink" href="#powers-logs-and-roots" title="Permalink to this headline">¶</a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="19%" />
<col width="81%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">sqrt(x)</span></tt></td>
<td>the square root of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">cbrt(x)</span></tt></td>
<td>the cube root of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">hypot(x,y)</span></tt></td>
<td>hypotenuse of right-angled triangle with other sides of length <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">exp(x)</span></tt></td>
<td>the natural exponential function at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">expm1(x)</span></tt></td>
<td>accurate <tt class="docutils literal"><span class="pre">exp(x)-1</span></tt> for <tt class="docutils literal"><span class="pre">x</span></tt> near zero</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">ldexp(x,n)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">x*2^n</span></tt> computed efficiently for integer values of <tt class="docutils literal"><span class="pre">n</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">log(x)</span></tt></td>
<td>the natural logarithm of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">log(b,x)</span></tt></td>
<td>the base <tt class="docutils literal"><span class="pre">b</span></tt> logarithm of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">log2(x)</span></tt></td>
<td>the base 2 logarithm of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">log10(x)</span></tt></td>
<td>the base 10 logarithm of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">log1p(x)</span></tt></td>
<td>accurate <tt class="docutils literal"><span class="pre">log(1+x)</span></tt> for <tt class="docutils literal"><span class="pre">x</span></tt> near zero</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">exponent(x)</span></tt></td>
<td>returns the binary exponent of <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">significand(x)</span></tt></td>
<td>returns the binary significand (a.k.a. mantissa) of a floating-point number <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
</tbody>
</table>
<p>For an overview of why functions like <tt class="docutils literal"><span class="pre">hypot</span></tt>, <tt class="docutils literal"><span class="pre">expm1</span></tt>, and <tt class="docutils literal"><span class="pre">log1p</span></tt>
are necessary and useful, see John D. Cook&#8217;s excellent pair
of blog posts on the subject: <a class="reference external" href="http://www.johndcook.com/blog/2010/06/07/math-library-functions-that-seem-unnecessary/">expm1, log1p,
erfc</a>,
and
<a class="reference external" href="http://www.johndcook.com/blog/2010/06/02/whats-so-hard-about-finding-a-hypotenuse/">hypot</a>.</p>
</div>
<div class="section" id="trigonometric-and-hyperbolic-functions">
<h3>Trigonometric and hyperbolic functions<a class="headerlink" href="#trigonometric-and-hyperbolic-functions" title="Permalink to this headline">¶</a></h3>
<p>All the standard trigonometric and hyperbolic functions are also defined:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">sin</span>    <span class="n">cos</span>    <span class="n">tan</span>    <span class="n">cot</span>    <span class="n">sec</span>    <span class="n">csc</span>
<span class="n">sinh</span>   <span class="n">cosh</span>   <span class="n">tanh</span>   <span class="n">coth</span>   <span class="n">sech</span>   <span class="n">csch</span>
<span class="n">asin</span>   <span class="n">acos</span>   <span class="n">atan</span>   <span class="n">acot</span>   <span class="n">asec</span>   <span class="n">acsc</span>
<span class="n">asinh</span>  <span class="n">acosh</span>  <span class="n">atanh</span>  <span class="n">acoth</span>  <span class="n">asech</span>  <span class="n">acsch</span>
<span class="n">sinc</span>   <span class="n">cosc</span>   <span class="n">atan2</span>
</pre></div>
</div>
<p>These are all single-argument functions, with the exception of
<a class="reference external" href="http://en.wikipedia.org/wiki/Atan2">atan2</a>, which gives the angle
in <a class="reference external" href="http://en.wikipedia.org/wiki/Radian">radians</a> between the <em>x</em>-axis
and the point specified by its arguments, interpreted as <em>x</em> and <em>y</em>
coordinates.</p>
<p>Additionally, <tt class="docutils literal"><span class="pre">sinpi(x)</span></tt> and <tt class="docutils literal"><span class="pre">cospi(x)</span></tt> are provided for more accurate computations
of <tt class="docutils literal"><span class="pre">sin(pi*x)</span></tt> and <tt class="docutils literal"><span class="pre">cos(pi*x)</span></tt> respectively.</p>
<p>In order to compute trigonometric functions with degrees
instead of radians, suffix the function with <tt class="docutils literal"><span class="pre">d</span></tt>. For example, <tt class="docutils literal"><span class="pre">sind(x)</span></tt>
computes the sine of <tt class="docutils literal"><span class="pre">x</span></tt> where <tt class="docutils literal"><span class="pre">x</span></tt> is specified in degrees.
The complete list of trigonometric functions with degree variants is:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">sind</span>   <span class="n">cosd</span>   <span class="n">tand</span>   <span class="n">cotd</span>   <span class="n">secd</span>   <span class="n">cscd</span>
<span class="n">asind</span>  <span class="n">acosd</span>  <span class="n">atand</span>  <span class="n">acotd</span>  <span class="n">asecd</span>  <span class="n">acscd</span>
</pre></div>
</div>
</div>
<div class="section" id="special-functions">
<h3>Special functions<a class="headerlink" href="#special-functions" title="Permalink to this headline">¶</a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="18%" />
<col width="82%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Function</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">erf(x)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Error_function">error function</a> at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">erfc(x)</span></tt></td>
<td>the complementary error function, i.e. the accurate version of <tt class="docutils literal"><span class="pre">1-erf(x)</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">erfinv(x)</span></tt></td>
<td>the inverse function to <tt class="docutils literal"><span class="pre">erf</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">erfcinv(x)</span></tt></td>
<td>the inverse function to <tt class="docutils literal"><span class="pre">erfc</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">erfi(x)</span></tt></td>
<td>the imaginary error function defined as <tt class="docutils literal"><span class="pre">-im</span> <span class="pre">*</span> <span class="pre">erf(x</span> <span class="pre">*</span> <span class="pre">im)</span></tt>, where <tt class="docutils literal"><span class="pre">im</span></tt> is the imaginary unit</td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">erfcx(x)</span></tt></td>
<td>the scaled complementary error function, i.e. accurate <tt class="docutils literal"><span class="pre">exp(x^2)</span> <span class="pre">*</span> <span class="pre">erfc(x)</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">dawson(x)</span></tt></td>
<td>the scaled imaginary error function, a.k.a. Dawson function, i.e. accurate <tt class="docutils literal"><span class="pre">exp(-x^2)</span> <span class="pre">*</span> <span class="pre">erfi(x)</span> <span class="pre">*</span> <span class="pre">sqrt(pi)</span> <span class="pre">/</span> <span class="pre">2</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">gamma(x)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Gamma_function">gamma function</a> at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">lgamma(x)</span></tt></td>
<td>accurate <tt class="docutils literal"><span class="pre">log(gamma(x))</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">lfact(x)</span></tt></td>
<td>accurate <tt class="docutils literal"><span class="pre">log(factorial(x))</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt>; same as <tt class="docutils literal"><span class="pre">lgamma(x+1)</span></tt> for <tt class="docutils literal"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">1</span></tt>, zero otherwise</td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">digamma(x)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Digamma_function">digamma function</a> (i.e. the derivative of <tt class="docutils literal"><span class="pre">lgamma</span></tt>) at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">beta(x,y)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Beta_function">beta function</a> at <tt class="docutils literal"><span class="pre">x,y</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">lbeta(x,y)</span></tt></td>
<td>accurate <tt class="docutils literal"><span class="pre">log(beta(x,y))</span></tt> for large <tt class="docutils literal"><span class="pre">x</span></tt> or <tt class="docutils literal"><span class="pre">y</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">eta(x)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Dirichlet_eta_function">Dirichlet eta function</a> at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">zeta(x)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Riemann_zeta_function">Riemann zeta function</a> at <tt class="docutils literal"><span class="pre">x</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">airy(z)</span></tt>, <tt class="docutils literal"><span class="pre">airyai(z)</span></tt>, <tt class="docutils literal"><span class="pre">airy(0,z)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Airy_function">Airy Ai function</a> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">airyprime(z)</span></tt>, <tt class="docutils literal"><span class="pre">airyaiprime(z)</span></tt>, <tt class="docutils literal"><span class="pre">airy(1,z)</span></tt></td>
<td>the derivative of the Airy Ai function at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">airybi(z)</span></tt>, <tt class="docutils literal"><span class="pre">airy(2,z)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Airy_function">Airy Bi function</a> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">airybiprime(z)</span></tt>, <tt class="docutils literal"><span class="pre">airy(3,z)</span></tt></td>
<td>the derivative of the Airy Bi function at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">airyx(z)</span></tt>, <tt class="docutils literal"><span class="pre">airyx(k,z)</span></tt></td>
<td>the scaled Airy AI function and <tt class="docutils literal"><span class="pre">k</span></tt> th derivatives at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">besselj(nu,z)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Bessel_function">Bessel function</a> of the first kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">besselj0(z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">besselj(0,z)</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">besselj1(z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">besselj(1,z)</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">besseljx(nu,z)</span></tt></td>
<td>the scaled Bessel function of the first kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">bessely(nu,z)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Bessel_function">Bessel function</a> of the second kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">bessely0(z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">bessely(0,z)</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">bessely1(z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">bessely(1,z)</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">besselyx(nu,z)</span></tt></td>
<td>the scaled Bessel function of the second kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">besselh(nu,k,z)</span></tt></td>
<td>the <a class="reference external" href="http://en.wikipedia.org/wiki/Bessel_function">Bessel function</a> of the third kind (a.k.a. Hankel function) of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt>; <tt class="docutils literal"><span class="pre">k</span></tt> must be either <tt class="docutils literal"><span class="pre">1</span></tt> or <tt class="docutils literal"><span class="pre">2</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">hankelh1(nu,z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">besselh(nu,</span> <span class="pre">1,</span> <span class="pre">z)</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">hankelh1x(nu,z)</span></tt></td>
<td>scaled <tt class="docutils literal"><span class="pre">besselh(nu,</span> <span class="pre">1,</span> <span class="pre">z)</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">hankelh2(nu,z)</span></tt></td>
<td><tt class="docutils literal"><span class="pre">besselh(nu,</span> <span class="pre">2,</span> <span class="pre">z)</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">hankelh2x(nu,z)</span></tt></td>
<td>scaled <tt class="docutils literal"><span class="pre">besselh(nu,</span> <span class="pre">2,</span> <span class="pre">z)</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">besseli(nu,z)</span></tt></td>
<td>the modified <a class="reference external" href="http://en.wikipedia.org/wiki/Bessel_function">Bessel function</a> of the first kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">besselix(nu,z)</span></tt></td>
<td>the scaled modified Bessel function of the first kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-odd"><td><tt class="docutils literal"><span class="pre">besselk(nu,z)</span></tt></td>
<td>the modified <a class="reference external" href="http://en.wikipedia.org/wiki/Bessel_function">Bessel function</a> of the second kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
<tr class="row-even"><td><tt class="docutils literal"><span class="pre">besselkx(nu,z)</span></tt></td>
<td>the scaled modified Bessel function of the second kind of order <tt class="docutils literal"><span class="pre">nu</span></tt> at <tt class="docutils literal"><span class="pre">z</span></tt></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>


          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="complex-and-rational-numbers.html" class="btn btn-neutral float-right" title="Complex and Rational Numbers"/>Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="integers-and-floating-point-numbers.html" class="btn btn-neutral" title="Integers and Floating-Point Numbers"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
    </p>
  </div>

  <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
</footer>
        </div>
      </div>

    </section>

  </div>
  

  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.3.4',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>